Skip to content

Commit

Permalink
Fix the last remaining linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
annismckenzie committed Jan 23, 2021
1 parent 92c2446 commit 16bca77
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
6 changes: 4 additions & 2 deletions controllers/config/k3osconfig_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,10 @@ func (r *K3OSConfigReconciler) enqueueObjectsOnChanges(object client.Object) []r
r.logger.Error(err, "failed to PartialObjectMetadataList all K3OSConfig resources in this namespace")
}

requests := make([]reconcile.Request, len(k3osconfigs.Items))
for i, item := range k3osconfigs.Items {
numItems := len(k3osconfigs.Items)
requests := make([]reconcile.Request, numItems)
for i := 0; i < numItems; i++ {
item := &k3osconfigs.Items[i]
requests[i] = reconcile.Request{NamespacedName: types.NamespacedName{Name: item.GetName(), Namespace: item.GetNamespace()}}
}
r.logger.V(1).Info("enqueuing requests for all K3OSConfig resources in this namespace", "namespace", r.namespace, "requests", requests)
Expand Down
22 changes: 14 additions & 8 deletions pkg/util/taints/taints.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ const (
UNTAINTED = "untainted"
)

// consts for taint value parts.
const (
taintKeyOnly = 1 // '<key>'
taintWithEffect = 2 // '<key>:<effect>' or '<key>=<value>:<effect>'
taintKeyValue = 2
)

// parseTaint parses a taint from a string, whose form must be either
// '<key>=<value>:<effect>', '<key>:<effect>', or '<key>'.
func parseTaint(st string) (corev1.Taint, error) {
Expand All @@ -46,20 +53,20 @@ func parseTaint(st string) (corev1.Taint, error) {

parts := strings.Split(st, ":")
switch len(parts) {
case 1:
case taintKeyOnly:
key = parts[0]
case 2:
case taintWithEffect:
effect = corev1.TaintEffect(parts[1])
if err := validateTaintEffect(effect); err != nil {
return taint, err
}

partsKV := strings.Split(parts[0], "=")
if len(partsKV) > 2 {
if len(partsKV) > taintKeyValue {
return taint, fmt.Errorf("invalid taint spec: %v", st)
}
key = partsKV[0]
if len(partsKV) == 2 {
if len(partsKV) == taintKeyValue {
value = partsKV[1]
if errs := validation.IsValidLabelValue(value); len(errs) > 0 {
return taint, fmt.Errorf("invalid taint spec: %v, %s", st, strings.Join(errs, "; "))
Expand Down Expand Up @@ -90,8 +97,7 @@ func validateTaintEffect(effect corev1.TaintEffect) error {

// ParseTaints takes a spec which is an array and creates slices for new taints to be added, taints to be deleted.
// It also validates the spec. For example, the form `<key>` may be used to remove a taint, but not to add one.
func ParseTaints(spec []string) ([]corev1.Taint, []corev1.Taint, error) {
var taints, taintsToRemove []corev1.Taint
func ParseTaints(spec []string) (taintsToAdd, taintsToRemove []corev1.Taint, err error) {
uniqueTaints := map[corev1.TaintEffect]sets.String{}

for _, taintSpec := range spec {
Expand Down Expand Up @@ -120,10 +126,10 @@ func ParseTaints(spec []string) ([]corev1.Taint, []corev1.Taint, error) {
}
uniqueTaints[newTaint.Effect].Insert(newTaint.Key)

taints = append(taints, newTaint)
taintsToAdd = append(taintsToAdd, newTaint)
}
}
return taints, taintsToRemove, nil
return taintsToAdd, taintsToRemove, nil
}

// ReorganizeTaints returns the updated set of taints, taking into account old taints that were not updated,
Expand Down

0 comments on commit 16bca77

Please sign in to comment.