Skip to content

Commit

Permalink
Return the correct node names in the node labels and taints check
Browse files Browse the repository at this point in the history
Previously a loop variable was being used for the node name in the diagnostic
returned from the node labels and taints check. If the offending node wasn't the
last one in the list, the wrong node name would be returned.

Add a test to reproduce the issue, and copy the loop variable to fix it.
  • Loading branch information
adamwg committed Feb 24, 2022
1 parent 7769a03 commit 91df975
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions checks/doks/node_labels_taints.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func (*nodeLabelsTaintsCheck) Description() string {
func (c *nodeLabelsTaintsCheck) Run(objects *kube.Objects) ([]checks.Diagnostic, error) {
var diagnostics []checks.Diagnostic
for _, node := range objects.Nodes.Items {
node := node
var customLabels, customTaints []string
for labelKey := range node.Labels {
if !isKubernetesLabel(labelKey) && !isDOKSLabel(labelKey) {
Expand Down
22 changes: 18 additions & 4 deletions checks/doks/node_labels_taints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func TestNodeLabels(t *testing.T) {
Kind: checks.Node,
Details: "Custom node labels: [example.com/another-label example.com/custom-label]",
Object: &metav1.ObjectMeta{
Name: "bad-node",
Labels: map[string]string{
"doks.digitalocean.com/foo": "bar",
"doks.digitalocean.com/baz": "xyzzy",
Expand All @@ -98,11 +99,24 @@ func TestNodeLabels(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
objects := &kube.Objects{
Nodes: &corev1.NodeList{
Items: []corev1.Node{{
ObjectMeta: metav1.ObjectMeta{
Labels: test.nodeLabels,
Items: []corev1.Node{
{
ObjectMeta: metav1.ObjectMeta{
Name: "good-node",
},
},
}},
{
ObjectMeta: metav1.ObjectMeta{
Name: "bad-node",
Labels: test.nodeLabels,
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "another-good-node",
},
},
},
},
}

Expand Down

0 comments on commit 91df975

Please sign in to comment.