Skip to content

Commit

Permalink
Fix counting of nmstate enabled nodes (#796)
Browse files Browse the repository at this point in the history
Currently, the label app=kubernetes-nmstate is used to count number
of nmstate enabled nodes, but this label is also present on webhooks
and cert manager, which may run on control-plane.

Using label component=kubernetes-nmstate-handler ensures that only
nodes with handlers running on them are considered.

Signed-off-by: Radim Hrazdil <[email protected]>
  • Loading branch information
rhrazdil authored Aug 10, 2021
1 parent eec9b4d commit ab10a40
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions pkg/policyconditions/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ func nodesRunningNmstate(cli client.Client) ([]corev1.Node, error) {
}

pods := corev1.PodList{}
byApp := client.MatchingLabels{"app": "kubernetes-nmstate"}
err = cli.List(context.TODO(), &pods, byApp)
byComponent := client.MatchingLabels{"component": "kubernetes-nmstate-handler"}
err = cli.List(context.TODO(), &pods, byComponent)
if err != nil {
return []corev1.Node{}, errors.Wrap(err, "getting pods failed")
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/policyconditions/conditions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ func newNode(idx int) corev1.Node {
return node
}

func newPodAtNode(idx int, name string, namespace string, app string) corev1.Pod {
func newPodAtNode(idx int, name string, namespace string, component string) corev1.Pod {
pod := corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-%d", name, idx),
Namespace: namespace,
Labels: map[string]string{
"app": app,
"component": component,
},
},
Spec: corev1.PodSpec{
Expand All @@ -86,7 +86,7 @@ func newPodAtNode(idx int, name string, namespace string, app string) corev1.Pod
}

func newNmstatePodAtNode(idx int) corev1.Pod {
return newPodAtNode(idx, "nmstate-handler", "nmstate", "kubernetes-nmstate")
return newPodAtNode(idx, "nmstate-handler", "nmstate", "kubernetes-nmstate-handler")
}

func newNonNmstatePodAtNode(idx int) corev1.Pod {
Expand Down

0 comments on commit ab10a40

Please sign in to comment.