Skip to content

Commit a08a1e3

Browse files
committed
Replaced hasAnyLabel with labels.Set...Has
1 parent de863d7 commit a08a1e3

7 files changed

Lines changed: 12 additions & 16 deletions

internal/controller/aggregates_controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"strings"
2525

2626
corev1 "k8s.io/api/core/v1"
27+
"k8s.io/apimachinery/pkg/labels"
2728
"k8s.io/apimachinery/pkg/runtime"
2829
ctrl "sigs.k8s.io/controller-runtime"
2930
k8sclient "sigs.k8s.io/controller-runtime/pkg/client"
@@ -56,7 +57,7 @@ func (r *AggregatesController) Reconcile(ctx context.Context, req ctrl.Request)
5657
return ctrl.Result{}, k8sclient.IgnoreNotFound(err)
5758
}
5859

59-
if !hasAnyLabel(node.Labels, labelServiceID) {
60+
if !(labels.Set)(node.Labels).Has(labelServiceID) {
6061
return ctrl.Result{}, nil
6162
}
6263

internal/controller/decomission_controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"net/http"
2424

2525
corev1 "k8s.io/api/core/v1"
26+
"k8s.io/apimachinery/pkg/labels"
2627
"k8s.io/apimachinery/pkg/runtime"
2728
ctrl "sigs.k8s.io/controller-runtime"
2829
k8sclient "sigs.k8s.io/controller-runtime/pkg/client"
@@ -63,7 +64,7 @@ func (r *NodeDecommissionReconciler) Reconcile(ctx context.Context, req ctrl.Req
6364
return ctrl.Result{}, k8sclient.IgnoreNotFound(err)
6465
}
6566

66-
found := hasAnyLabel(node.Labels, labelLifecycleMode)
67+
found := (labels.Set)(node.Labels).Has(labelLifecycleMode)
6768

6869
if !found {
6970
// Get out of the way

internal/controller/maintenance_controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
corev1 "k8s.io/api/core/v1"
2727
policyv1 "k8s.io/api/policy/v1"
2828
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
29+
"k8s.io/apimachinery/pkg/labels"
2930
"k8s.io/apimachinery/pkg/runtime"
3031
"k8s.io/apimachinery/pkg/util/intstr"
3132
"k8s.io/client-go/util/retry"
@@ -71,7 +72,7 @@ func (r *MaintenanceController) Reconcile(ctx context.Context, req ctrl.Request)
7172
return ctrl.Result{}, k8sclient.IgnoreNotFound(err)
7273
}
7374

74-
if !hasAnyLabel(node.Labels, labelLifecycleMode) {
75+
if !(labels.Set)(node.Labels).Has(labelLifecycleMode) {
7576
return ctrl.Result{}, nil
7677
}
7778

internal/controller/node_certificate_controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
cmmeta "github.com/cert-manager/cert-manager/pkg/apis/meta/v1"
2828
corev1 "k8s.io/api/core/v1"
2929
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
30+
"k8s.io/apimachinery/pkg/labels"
3031
"k8s.io/apimachinery/pkg/runtime"
3132
"k8s.io/client-go/util/retry"
3233
ctrl "sigs.k8s.io/controller-runtime"
@@ -162,7 +163,7 @@ func (r *NodeCertificateController) Reconcile(ctx context.Context, req ctrl.Requ
162163
return ctrl.Result{}, k8sclient.IgnoreNotFound(err)
163164
}
164165

165-
found := hasAnyLabel(node.Labels, labelHypervisor)
166+
found := (labels.Set)(node.Labels).Has(labelHypervisor)
166167

167168
if !found {
168169
return ctrl.Result{}, nil

internal/controller/onboarding_controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"time"
2626

2727
corev1 "k8s.io/api/core/v1"
28+
"k8s.io/apimachinery/pkg/labels"
2829
"k8s.io/apimachinery/pkg/runtime"
2930
"k8s.io/apimachinery/pkg/types"
3031
ctrl "sigs.k8s.io/controller-runtime"
@@ -95,7 +96,7 @@ func (r *OnboardingController) Reconcile(ctx context.Context, req ctrl.Request)
9596
return ctrl.Result{}, k8sclient.IgnoreNotFound(err)
9697
}
9798

98-
found := hasAnyLabel(node.Labels, labelHypervisor)
99+
found := (labels.Set)(node.Labels).Has(labelHypervisor)
99100

100101
if !found {
101102
return ctrl.Result{}, nil

internal/controller/traits_controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"strings"
2525

2626
corev1 "k8s.io/api/core/v1"
27+
"k8s.io/apimachinery/pkg/labels"
2728
"k8s.io/apimachinery/pkg/runtime"
2829
ctrl "sigs.k8s.io/controller-runtime"
2930
k8sclient "sigs.k8s.io/controller-runtime/pkg/client"
@@ -58,7 +59,7 @@ func (r *TraitsController) Reconcile(ctx context.Context, req ctrl.Request) (ctr
5859
return ctrl.Result{}, k8sclient.IgnoreNotFound(err)
5960
}
6061

61-
if !hasAnyLabel(node.Labels, labelHypervisor) {
62+
if !(labels.Set)(node.Labels).Has(labelHypervisor) {
6263
return ctrl.Result{}, nil
6364
}
6465

internal/controller/utils.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,6 @@ func setNodeLabels(ctx context.Context, writer client.Writer, node *corev1.Node,
3636
return true, writer.Patch(ctx, newNode, client.MergeFrom(node))
3737
}
3838

39-
func hasAnyLabel(labels map[string]string, list ...string) bool {
40-
for _, label := range list {
41-
if _, found := labels[label]; found {
42-
return true
43-
}
44-
}
45-
46-
return false
47-
}
48-
4939
// setNodeAnnotations sets annotations on the node.
5040
func setNodeAnnotations(ctx context.Context, writer client.Writer, node *corev1.Node, annotations map[string]string) error {
5141
newNode := node.DeepCopy()

0 commit comments

Comments
 (0)