Skip to content

Commit

Permalink
Update variable names to match usage
Browse files Browse the repository at this point in the history
  • Loading branch information
johscheuer committed Jul 22, 2022
1 parent 72ed3b0 commit 06239af
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 24 deletions.
12 changes: 6 additions & 6 deletions kubectl-fdb/cmd/buggify_crash_loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func updateCrashLoopList(kubeClient client.Client, clusterName string, pods []st
return err
}

processGroups, err := getProcessGroupIDsFromPodName(cluster, pods)
processGroupIDs, err := getProcessGroupIDsFromPodName(cluster, pods)
if err != nil {
return err
}
Expand All @@ -124,26 +124,26 @@ func updateCrashLoopList(kubeClient client.Client, clusterName string, pods []st
return kubeClient.Patch(ctx.TODO(), cluster, patch)
}

if len(processGroups) == 0 {
if len(processGroupIDs) == 0 {
return fmt.Errorf("please provide atleast one pod")
}

if wait {
if clear {
if !confirmAction(fmt.Sprintf("Removing %v to crash-loop from cluster %s/%s", processGroups, namespace, clusterName)) {
if !confirmAction(fmt.Sprintf("Removing %v to crash-loop from cluster %s/%s", processGroupIDs, namespace, clusterName)) {
return fmt.Errorf("user aborted the removal")
}
} else {
if !confirmAction(fmt.Sprintf("Adding %v to crash-loop from cluster %s/%s", processGroups, namespace, clusterName)) {
if !confirmAction(fmt.Sprintf("Adding %v to crash-loop from cluster %s/%s", processGroupIDs, namespace, clusterName)) {
return fmt.Errorf("user aborted the removal")
}
}
}

if clear {
cluster.RemoveProcessGroupsFromCrashLoopList(processGroups)
cluster.RemoveProcessGroupsFromCrashLoopList(processGroupIDs)
} else {
cluster.AddProcessGroupsToCrashLoopList(processGroups)
cluster.AddProcessGroupsToCrashLoopList(processGroupIDs)
}

return kubeClient.Patch(ctx.TODO(), cluster, patch)
Expand Down
12 changes: 6 additions & 6 deletions kubectl-fdb/cmd/buggify_no_schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func updateNoScheduleList(kubeClient client.Client, clusterName string, pods []s
return err
}

processGroups, err := getProcessGroupIDsFromPodName(cluster, pods)
processGroupIDs, err := getProcessGroupIDsFromPodName(cluster, pods)
if err != nil {
return err
}
Expand All @@ -125,26 +125,26 @@ func updateNoScheduleList(kubeClient client.Client, clusterName string, pods []s
return kubeClient.Patch(ctx.TODO(), cluster, patch)
}

if len(processGroups) == 0 {
if len(processGroupIDs) == 0 {
return fmt.Errorf("please provide atleast one pod")
}

if wait {
if clear {
if !confirmAction(fmt.Sprintf("Removing %v from no-schedule from cluster %s/%s", processGroups, namespace, clusterName)) {
if !confirmAction(fmt.Sprintf("Removing %v from no-schedule from cluster %s/%s", processGroupIDs, namespace, clusterName)) {
return fmt.Errorf("user aborted the removal")
}
} else {
if !confirmAction(fmt.Sprintf("Adding %v from no-schedule from cluster %s/%s", processGroups, namespace, clusterName)) {
if !confirmAction(fmt.Sprintf("Adding %v from no-schedule from cluster %s/%s", processGroupIDs, namespace, clusterName)) {
return fmt.Errorf("user aborted the removal")
}
}
}

if clear {
cluster.RemoveProcessGroupsFromNoScheduleList(processGroups)
cluster.RemoveProcessGroupsFromNoScheduleList(processGroupIDs)
} else {
cluster.AddProcessGroupsToNoScheduleList(processGroups)
cluster.AddProcessGroupsToNoScheduleList(processGroupIDs)
}

return kubeClient.Patch(ctx.TODO(), cluster, patch)
Expand Down
6 changes: 3 additions & 3 deletions kubectl-fdb/cmd/k8s_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func getAllPodsFromClusterWithCondition(kubeClient client.Client, clusterName st

// getProcessGroupIDsFromPodName returns the process group IDs based on the cluster configuration.
func getProcessGroupIDsFromPodName(cluster *fdbv1beta2.FoundationDBCluster, podNames []string) ([]string, error) {
processGroups := make([]string, 0, len(podNames))
processGroupIDs := make([]string, 0, len(podNames))

// TODO(johscheuer): We could validate if the provided process group is actually part of the cluster
for _, podName := range podNames {
Expand All @@ -215,8 +215,8 @@ func getProcessGroupIDsFromPodName(cluster *fdbv1beta2.FoundationDBCluster, podN
return nil, fmt.Errorf("cluster name %s is not set as prefix for Pod name %s, please ensure the specified Pod is part of the cluster", cluster.Name, podName)
}

processGroups = append(processGroups, internal.GetProcessGroupIDFromPodName(cluster, podName))
processGroupIDs = append(processGroupIDs, internal.GetProcessGroupIDFromPodName(cluster, podName))
}

return processGroups, nil
return processGroupIDs, nil
}
17 changes: 8 additions & 9 deletions kubectl-fdb/cmd/remove_process_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ kubectl fdb -n default remove process-group -c cluster --remove-all-failed
}

// replaceProcessGroups adds process groups to the removal list of the cluster
func replaceProcessGroups(kubeClient client.Client, clusterName string, processGroups []string, namespace string, withExclusion bool, wait bool, removeAllFailed bool, useProcessGroupID bool) error {
if len(processGroups) == 0 && !removeAllFailed {
func replaceProcessGroups(kubeClient client.Client, clusterName string, processGroupIDs []string, namespace string, withExclusion bool, wait bool, removeAllFailed bool, useProcessGroupID bool) error {
if len(processGroupIDs) == 0 && !removeAllFailed {
return nil
}

Expand All @@ -123,7 +123,7 @@ func replaceProcessGroups(kubeClient client.Client, clusterName string, processG

// In this case the user has Pod name specified
if !useProcessGroupID {
processGroups, err = getProcessGroupIDsFromPodName(cluster, processGroups)
processGroupIDs, err = getProcessGroupIDsFromPodName(cluster, processGroupIDs)
if err != nil {
return err
}
Expand All @@ -132,7 +132,7 @@ func replaceProcessGroups(kubeClient client.Client, clusterName string, processG
patch := client.MergeFrom(cluster.DeepCopy())

processGroupSet := map[string]fdbv1beta2.None{}
for _, processGroup := range processGroups {
for _, processGroup := range processGroupIDs {
processGroupSet[processGroup] = fdbv1beta2.None{}
}

Expand All @@ -145,22 +145,21 @@ func replaceProcessGroups(kubeClient client.Client, clusterName string, processG

needsReplacement, _ := processGroupStatus.NeedsReplacement(0)
if needsReplacement {
processGroups = append(processGroups, processGroupStatus.ProcessGroupID)
processGroupIDs = append(processGroupIDs, processGroupStatus.ProcessGroupID)
}
}
}

if wait {
confirmed := confirmAction(fmt.Sprintf("Remove %v from cluster %s/%s with exclude: %t", processGroups, namespace, clusterName, withExclusion))
if !confirmed {
if !confirmAction(fmt.Sprintf("Remove %v from cluster %s/%s with exclude: %t", processGroupIDs, namespace, clusterName, withExclusion)) {
return fmt.Errorf("user aborted the removal")
}
}

if withExclusion {
cluster.AddProcessGroupsToRemovalList(processGroups)
cluster.AddProcessGroupsToRemovalList(processGroupIDs)
} else {
cluster.AddProcessGroupsToRemovalWithoutExclusionList(processGroups)
cluster.AddProcessGroupsToRemovalWithoutExclusionList(processGroupIDs)
}

return kubeClient.Patch(ctx.TODO(), cluster, patch)
Expand Down

0 comments on commit 06239af

Please sign in to comment.