mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 12:43:23 +00:00
Merge pull request #86347 from yuzhiquan/patch-kubectl
cleanup(kubectl taint): fix Errorf and comment error, and remove unne…
This commit is contained in:
commit
c5982d03cf
@ -183,7 +183,7 @@ func (o *TaintOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []st
|
|||||||
func (o TaintOptions) validateFlags() error {
|
func (o TaintOptions) validateFlags() error {
|
||||||
// Cannot have a non-empty selector and all flag set. They are mutually exclusive.
|
// Cannot have a non-empty selector and all flag set. They are mutually exclusive.
|
||||||
if o.all && o.selector != "" {
|
if o.all && o.selector != "" {
|
||||||
return fmt.Errorf("setting 'all' parameter with a non empty selector is prohibited.")
|
return fmt.Errorf("setting 'all' parameter with a non empty selector is prohibited")
|
||||||
}
|
}
|
||||||
// If both selector and all are not set.
|
// If both selector and all are not set.
|
||||||
if !o.all && o.selector == "" {
|
if !o.all && o.selector == "" {
|
||||||
@ -294,7 +294,7 @@ func (o TaintOptions) updateTaints(obj runtime.Object) (string, error) {
|
|||||||
}
|
}
|
||||||
if !o.overwrite {
|
if !o.overwrite {
|
||||||
if exists := checkIfTaintsAlreadyExists(node.Spec.Taints, o.taintsToAdd); len(exists) != 0 {
|
if exists := checkIfTaintsAlreadyExists(node.Spec.Taints, o.taintsToAdd); len(exists) != 0 {
|
||||||
return "", fmt.Errorf("Node %s already has %v taint(s) with same effect(s) and --overwrite is false", node.Name, exists)
|
return "", fmt.Errorf("node %s already has %v taint(s) with same effect(s) and --overwrite is false", node.Name, exists)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
operation, newTaints, err := reorganizeTaints(node, o.overwrite, o.taintsToAdd, o.taintsToRemove)
|
operation, newTaints, err := reorganizeTaints(node, o.overwrite, o.taintsToAdd, o.taintsToRemove)
|
||||||
|
@ -125,7 +125,7 @@ func validateTaintEffect(effect corev1.TaintEffect) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReorganizeTaints returns the updated set of taints, taking into account old taints that were not updated,
|
// reorganizeTaints returns the updated set of taints, taking into account old taints that were not updated,
|
||||||
// old taints that were updated, old taints that were deleted, and new taints.
|
// old taints that were updated, old taints that were deleted, and new taints.
|
||||||
func reorganizeTaints(node *corev1.Node, overwrite bool, taintsToAdd []corev1.Taint, taintsToRemove []corev1.Taint) (string, []corev1.Taint, error) {
|
func reorganizeTaints(node *corev1.Node, overwrite bool, taintsToAdd []corev1.Taint, taintsToRemove []corev1.Taint) (string, []corev1.Taint, error) {
|
||||||
newTaints := append([]corev1.Taint{}, taintsToAdd...)
|
newTaints := append([]corev1.Taint{}, taintsToAdd...)
|
||||||
@ -177,7 +177,7 @@ func addTaints(oldTaints []corev1.Taint, newTaints *[]corev1.Taint) bool {
|
|||||||
return len(oldTaints) != len(*newTaints)
|
return len(oldTaints) != len(*newTaints)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CheckIfTaintsAlreadyExists checks if the node already has taints that we want to add and returns a string with taint keys.
|
// checkIfTaintsAlreadyExists checks if the node already has taints that we want to add and returns a string with taint keys.
|
||||||
func checkIfTaintsAlreadyExists(oldTaints []corev1.Taint, taints []corev1.Taint) string {
|
func checkIfTaintsAlreadyExists(oldTaints []corev1.Taint, taints []corev1.Taint) string {
|
||||||
var existingTaintList = make([]string, 0)
|
var existingTaintList = make([]string, 0)
|
||||||
for _, taint := range taints {
|
for _, taint := range taints {
|
||||||
@ -190,30 +190,26 @@ func checkIfTaintsAlreadyExists(oldTaints []corev1.Taint, taints []corev1.Taint)
|
|||||||
return strings.Join(existingTaintList, ",")
|
return strings.Join(existingTaintList, ",")
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteTaintsByKey removes all the taints that have the same key to given taintKey
|
// deleteTaintsByKey removes all the taints that have the same key to given taintKey
|
||||||
func deleteTaintsByKey(taints []corev1.Taint, taintKey string) ([]corev1.Taint, bool) {
|
func deleteTaintsByKey(taints []corev1.Taint, taintKey string) ([]corev1.Taint, bool) {
|
||||||
newTaints := []corev1.Taint{}
|
newTaints := []corev1.Taint{}
|
||||||
deleted := false
|
|
||||||
for i := range taints {
|
for i := range taints {
|
||||||
if taintKey == taints[i].Key {
|
if taintKey == taints[i].Key {
|
||||||
deleted = true
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
newTaints = append(newTaints, taints[i])
|
newTaints = append(newTaints, taints[i])
|
||||||
}
|
}
|
||||||
return newTaints, deleted
|
return newTaints, len(taints) != len(newTaints)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteTaint removes all the taints that have the same key and effect to given taintToDelete.
|
// deleteTaint removes all the taints that have the same key and effect to given taintToDelete.
|
||||||
func deleteTaint(taints []corev1.Taint, taintToDelete *corev1.Taint) ([]corev1.Taint, bool) {
|
func deleteTaint(taints []corev1.Taint, taintToDelete *corev1.Taint) ([]corev1.Taint, bool) {
|
||||||
newTaints := []corev1.Taint{}
|
newTaints := []corev1.Taint{}
|
||||||
deleted := false
|
|
||||||
for i := range taints {
|
for i := range taints {
|
||||||
if taintToDelete.MatchTaint(&taints[i]) {
|
if taintToDelete.MatchTaint(&taints[i]) {
|
||||||
deleted = true
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
newTaints = append(newTaints, taints[i])
|
newTaints = append(newTaints, taints[i])
|
||||||
}
|
}
|
||||||
return newTaints, deleted
|
return newTaints, len(taints) != len(newTaints)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user