Skip to content

Commit 55ea895

Browse files
[release-4.12] OCPBUGS-11376: Operator should not add empty strings node arch list i… (#746)
* OCPBUGS-11071: Operator should not add empty strings node arch list in console config * Warn when a node is missing the architecture label. Add unit tests for getNodeArchitectures. * Add test getNodeArchitectures test case for duplicate architecture labels --------- Co-authored-by: Jon Jackson <[email protected]>
1 parent a804d4d commit 55ea895

File tree

2 files changed

+153
-1
lines changed

2 files changed

+153
-1
lines changed

pkg/console/operator/sync_v400.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,11 @@ func getNodeArchitectures(nodes *corev1.NodeList) []string {
613613
nodeArchitecturesSet := sets.NewString()
614614
for _, node := range nodes.Items {
615615
nodeArch := node.Labels[api.NodeArchitectureLabel]
616-
nodeArchitecturesSet.Insert(nodeArch)
616+
if nodeArch == "" {
617+
klog.Warningf("Architecture label %q missing on node %q", api.NodeArchitectureLabel, node.GetName())
618+
} else {
619+
nodeArchitecturesSet.Insert(nodeArch)
620+
}
617621
}
618622
return nodeArchitecturesSet.List()
619623
}
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
package operator
2+
3+
import (
4+
"testing"
5+
6+
"github.com/go-test/deep"
7+
"github.com/openshift/console-operator/pkg/api"
8+
v1 "k8s.io/api/core/v1"
9+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
10+
)
11+
12+
func TestGetNodeArchitectures(t *testing.T) {
13+
tests := []struct {
14+
name string
15+
nodeList *v1.NodeList
16+
expected []string
17+
}{
18+
{
19+
name: "Test getNodeArchitectures",
20+
nodeList: &v1.NodeList{
21+
Items: []v1.Node{
22+
{
23+
ObjectMeta: metav1.ObjectMeta{
24+
Name: "node-1",
25+
Labels: map[string]string{
26+
api.NodeArchitectureLabel: "foo",
27+
},
28+
},
29+
},
30+
{
31+
ObjectMeta: metav1.ObjectMeta{
32+
Name: "node-1",
33+
Labels: map[string]string{
34+
api.NodeArchitectureLabel: "baz",
35+
},
36+
},
37+
},
38+
},
39+
},
40+
expected: []string{"baz", "foo"},
41+
},
42+
{
43+
name: "Test getNodeArchitectures empty node list",
44+
nodeList: &v1.NodeList{},
45+
expected: []string{},
46+
},
47+
{
48+
name: "Test getNodeArchitectures empty labels",
49+
nodeList: &v1.NodeList{
50+
Items: []v1.Node{
51+
{
52+
ObjectMeta: metav1.ObjectMeta{
53+
Name: "node-1",
54+
},
55+
},
56+
{
57+
ObjectMeta: metav1.ObjectMeta{
58+
Name: "node-2",
59+
Labels: map[string]string{
60+
api.NodeArchitectureLabel: "baz",
61+
},
62+
},
63+
},
64+
},
65+
},
66+
expected: []string{"baz"},
67+
},
68+
{
69+
name: "Test getNodeArchitectures missing arch label",
70+
nodeList: &v1.NodeList{
71+
Items: []v1.Node{
72+
{
73+
ObjectMeta: metav1.ObjectMeta{
74+
Name: "node-1",
75+
Labels: map[string]string{},
76+
},
77+
},
78+
{
79+
ObjectMeta: metav1.ObjectMeta{
80+
Name: "node-2",
81+
Labels: map[string]string{
82+
api.NodeArchitectureLabel: "baz",
83+
},
84+
},
85+
},
86+
},
87+
},
88+
expected: []string{"baz"},
89+
},
90+
{
91+
name: "Test getNodeArchitectures empty arch label",
92+
nodeList: &v1.NodeList{
93+
Items: []v1.Node{
94+
{
95+
ObjectMeta: metav1.ObjectMeta{
96+
Name: "node-1",
97+
Labels: map[string]string{
98+
api.NodeArchitectureLabel: "",
99+
},
100+
},
101+
},
102+
{
103+
ObjectMeta: metav1.ObjectMeta{
104+
Name: "node-2",
105+
Labels: map[string]string{
106+
api.NodeArchitectureLabel: "baz",
107+
},
108+
},
109+
},
110+
},
111+
},
112+
expected: []string{"baz"},
113+
},
114+
{
115+
name: "Test getNodeArchitectures duplicate arch label",
116+
nodeList: &v1.NodeList{
117+
Items: []v1.Node{
118+
{
119+
ObjectMeta: metav1.ObjectMeta{
120+
Name: "node-1",
121+
Labels: map[string]string{
122+
api.NodeArchitectureLabel: "baz",
123+
},
124+
},
125+
},
126+
{
127+
ObjectMeta: metav1.ObjectMeta{
128+
Name: "node-2",
129+
Labels: map[string]string{
130+
api.NodeArchitectureLabel: "baz",
131+
},
132+
},
133+
},
134+
},
135+
},
136+
expected: []string{"baz"},
137+
},
138+
}
139+
140+
for _, tt := range tests {
141+
t.Run(tt.name, func(t *testing.T) {
142+
actual := getNodeArchitectures(tt.nodeList)
143+
if diff := deep.Equal(tt.expected, actual); diff != nil {
144+
t.Error(diff)
145+
}
146+
})
147+
}
148+
}

0 commit comments

Comments
 (0)