@@ -97,71 +97,144 @@ func setMachineSetBootImage(machineset *machinev1beta1.MachineSet, generateBootI
9797}
9898
9999func TestGetArchFromMachineSet (t * testing.T ) {
100+ // Helper to create a single-arch cluster version
101+ singleArchCV := & osconfigv1.ClusterVersion {
102+ Status : osconfigv1.ClusterVersionStatus {
103+ Desired : osconfigv1.Release {
104+ Architecture : "" , // Empty means single-arch
105+ },
106+ },
107+ }
108+ // Helper to create a multi-arch cluster version
109+ multiArchCV := & osconfigv1.ClusterVersion {
110+ Status : osconfigv1.ClusterVersionStatus {
111+ Desired : osconfigv1.Release {
112+ Architecture : osconfigv1 .ClusterVersionArchitectureMulti ,
113+ },
114+ },
115+ }
116+
100117 cases := []struct {
101- name string
102- annotations map [string ]string
103- expectedArch string
104- expectError bool
118+ name string
119+ annotations map [string ]string
120+ clusterVersion * osconfigv1.ClusterVersion
121+ expectedArch string
122+ expectError bool
105123 }{
106124 {
107- name : "Single architecture label" ,
125+ name : "Single architecture label in single-arch cluster " ,
108126 annotations : map [string ]string {
109127 MachineSetArchAnnotationKey : "kubernetes.io/arch=amd64" ,
110128 },
111- expectedArch : "x86_64" ,
112- expectError : false ,
129+ clusterVersion : singleArchCV ,
130+ expectedArch : "x86_64" ,
131+ expectError : false ,
132+ },
133+ {
134+ name : "Single architecture label in multi-arch cluster" ,
135+ annotations : map [string ]string {
136+ MachineSetArchAnnotationKey : "kubernetes.io/arch=amd64" ,
137+ },
138+ clusterVersion : multiArchCV ,
139+ expectedArch : "x86_64" ,
140+ expectError : false ,
113141 },
114142 {
115143 name : "Multiple labels with architecture first" ,
116144 annotations : map [string ]string {
117145 MachineSetArchAnnotationKey : "kubernetes.io/arch=amd64,topology.ebs.csi.aws.com/zone=eu-central-1a" ,
118146 },
119- expectedArch : "x86_64" ,
120- expectError : false ,
147+ clusterVersion : singleArchCV ,
148+ expectedArch : "x86_64" ,
149+ expectError : false ,
121150 },
122151 {
123152 name : "Multiple labels with architecture last" ,
124153 annotations : map [string ]string {
125154 MachineSetArchAnnotationKey : "topology.ebs.csi.aws.com/zone=eu-central-1a,kubernetes.io/arch=arm64" ,
126155 },
127- expectedArch : "aarch64" ,
128- expectError : false ,
156+ clusterVersion : singleArchCV ,
157+ expectedArch : "aarch64" ,
158+ expectError : false ,
129159 },
130160 {
131161 name : "Multiple labels with architecture in middle" ,
132162 annotations : map [string ]string {
133163 MachineSetArchAnnotationKey : "topology.ebs.csi.aws.com/zone=eu-central-1a,kubernetes.io/arch=s390x,node.kubernetes.io/instance-type=m5.large" ,
134164 },
135- expectedArch : "s390x" ,
136- expectError : false ,
165+ clusterVersion : singleArchCV ,
166+ expectedArch : "s390x" ,
167+ expectError : false ,
137168 },
138169 {
139170 name : "Multiple labels with spaces" ,
140171 annotations : map [string ]string {
141172 MachineSetArchAnnotationKey : " topology.ebs.csi.aws.com/zone=eu-central-1a , kubernetes.io/arch=ppc64le , node.kubernetes.io/instance-type=m5.large " ,
142173 },
143- expectedArch : "ppc64le" ,
144- expectError : false ,
174+ clusterVersion : singleArchCV ,
175+ expectedArch : "ppc64le" ,
176+ expectError : false ,
145177 },
146178 {
147179 name : "Invalid architecture" ,
148180 annotations : map [string ]string {
149181 MachineSetArchAnnotationKey : "kubernetes.io/arch=invalid-arch" ,
150182 },
151- expectError : true ,
183+ clusterVersion : singleArchCV ,
184+ expectError : true ,
152185 },
153186 {
154- name : "No architecture label" ,
187+ name : "No architecture label in annotation " ,
155188 annotations : map [string ]string {
156189 MachineSetArchAnnotationKey : "topology.ebs.csi.aws.com/zone=eu-central-1a,node.kubernetes.io/instance-type=m5.large" ,
157190 },
191+ clusterVersion : singleArchCV ,
192+ expectError : true ,
193+ },
194+ {
195+ name : "No annotation in single-arch cluster defaults to control plane arch" ,
196+ annotations : map [string ]string {},
197+ clusterVersion : singleArchCV ,
198+ expectError : false , // Should default to control plane arch
199+ },
200+ {
201+ name : "No annotation in multi-arch cluster returns error" ,
202+ annotations : map [string ]string {},
203+ clusterVersion : & osconfigv1.ClusterVersion {
204+ Status : osconfigv1.ClusterVersionStatus {
205+ Desired : osconfigv1.Release {
206+ Architecture : osconfigv1 .ClusterVersionArchitectureMulti ,
207+ },
208+ },
209+ },
158210 expectError : true ,
159211 },
160212 {
161- name : "No annotation" ,
162- annotations : map [string ]string {},
163- expectedArch : "" , // Will default to control plane arch, but we can't test that easily
164- expectError : false ,
213+ name : "ARM64 architecture in multi-arch cluster" ,
214+ annotations : map [string ]string {
215+ MachineSetArchAnnotationKey : "kubernetes.io/arch=arm64" ,
216+ },
217+ clusterVersion : multiArchCV ,
218+ expectedArch : "aarch64" ,
219+ expectError : false ,
220+ },
221+ {
222+ name : "PPC64LE architecture in single-arch cluster" ,
223+ annotations : map [string ]string {
224+ MachineSetArchAnnotationKey : "kubernetes.io/arch=ppc64le" ,
225+ },
226+ clusterVersion : singleArchCV ,
227+ expectedArch : "ppc64le" ,
228+ expectError : false ,
229+ },
230+ {
231+ name : "S390X architecture in multi-arch cluster" ,
232+ annotations : map [string ]string {
233+ MachineSetArchAnnotationKey : "kubernetes.io/arch=s390x" ,
234+ },
235+ clusterVersion : multiArchCV ,
236+ expectedArch : "s390x" ,
237+ expectError : false ,
165238 },
166239 }
167240
@@ -174,7 +247,7 @@ func TestGetArchFromMachineSet(t *testing.T) {
174247 },
175248 }
176249
177- arch , err := getArchFromMachineSet (machineSet )
250+ arch , err := getArchFromMachineSet (machineSet , tc . clusterVersion )
178251
179252 if tc .expectError {
180253 assert .Error (t , err , "Expected error for test case: %s" , tc .name )
0 commit comments