Skip to content

Commit c5982d0

Browse files
authored
Merge pull request kubernetes#86347 from yuzhiquan/patch-kubectl
cleanup(kubectl taint): fix Errorf and comment error, and remove unne…
2 parents 6cbb37c + 87e8137 commit c5982d0

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

staging/src/k8s.io/kubectl/pkg/cmd/taint/taint.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func (o *TaintOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []st
183183
func (o TaintOptions) validateFlags() error {
184184
// Cannot have a non-empty selector and all flag set. They are mutually exclusive.
185185
if o.all && o.selector != "" {
186-
return fmt.Errorf("setting 'all' parameter with a non empty selector is prohibited.")
186+
return fmt.Errorf("setting 'all' parameter with a non empty selector is prohibited")
187187
}
188188
// If both selector and all are not set.
189189
if !o.all && o.selector == "" {
@@ -294,7 +294,7 @@ func (o TaintOptions) updateTaints(obj runtime.Object) (string, error) {
294294
}
295295
if !o.overwrite {
296296
if exists := checkIfTaintsAlreadyExists(node.Spec.Taints, o.taintsToAdd); len(exists) != 0 {
297-
return "", fmt.Errorf("Node %s already has %v taint(s) with same effect(s) and --overwrite is false", node.Name, exists)
297+
return "", fmt.Errorf("node %s already has %v taint(s) with same effect(s) and --overwrite is false", node.Name, exists)
298298
}
299299
}
300300
operation, newTaints, err := reorganizeTaints(node, o.overwrite, o.taintsToAdd, o.taintsToRemove)

staging/src/k8s.io/kubectl/pkg/cmd/taint/utils.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func validateTaintEffect(effect corev1.TaintEffect) error {
125125
return nil
126126
}
127127

128-
// ReorganizeTaints returns the updated set of taints, taking into account old taints that were not updated,
128+
// reorganizeTaints returns the updated set of taints, taking into account old taints that were not updated,
129129
// old taints that were updated, old taints that were deleted, and new taints.
130130
func reorganizeTaints(node *corev1.Node, overwrite bool, taintsToAdd []corev1.Taint, taintsToRemove []corev1.Taint) (string, []corev1.Taint, error) {
131131
newTaints := append([]corev1.Taint{}, taintsToAdd...)
@@ -177,7 +177,7 @@ func addTaints(oldTaints []corev1.Taint, newTaints *[]corev1.Taint) bool {
177177
return len(oldTaints) != len(*newTaints)
178178
}
179179

180-
// CheckIfTaintsAlreadyExists checks if the node already has taints that we want to add and returns a string with taint keys.
180+
// checkIfTaintsAlreadyExists checks if the node already has taints that we want to add and returns a string with taint keys.
181181
func checkIfTaintsAlreadyExists(oldTaints []corev1.Taint, taints []corev1.Taint) string {
182182
var existingTaintList = make([]string, 0)
183183
for _, taint := range taints {
@@ -190,30 +190,26 @@ func checkIfTaintsAlreadyExists(oldTaints []corev1.Taint, taints []corev1.Taint)
190190
return strings.Join(existingTaintList, ",")
191191
}
192192

193-
// DeleteTaintsByKey removes all the taints that have the same key to given taintKey
193+
// deleteTaintsByKey removes all the taints that have the same key to given taintKey
194194
func deleteTaintsByKey(taints []corev1.Taint, taintKey string) ([]corev1.Taint, bool) {
195195
newTaints := []corev1.Taint{}
196-
deleted := false
197196
for i := range taints {
198197
if taintKey == taints[i].Key {
199-
deleted = true
200198
continue
201199
}
202200
newTaints = append(newTaints, taints[i])
203201
}
204-
return newTaints, deleted
202+
return newTaints, len(taints) != len(newTaints)
205203
}
206204

207-
// DeleteTaint removes all the taints that have the same key and effect to given taintToDelete.
205+
// deleteTaint removes all the taints that have the same key and effect to given taintToDelete.
208206
func deleteTaint(taints []corev1.Taint, taintToDelete *corev1.Taint) ([]corev1.Taint, bool) {
209207
newTaints := []corev1.Taint{}
210-
deleted := false
211208
for i := range taints {
212209
if taintToDelete.MatchTaint(&taints[i]) {
213-
deleted = true
214210
continue
215211
}
216212
newTaints = append(newTaints, taints[i])
217213
}
218-
return newTaints, deleted
214+
return newTaints, len(taints) != len(newTaints)
219215
}

0 commit comments

Comments
 (0)