@@ -17,7 +17,6 @@ import (
1717 gardencorev1beta1helper "github.com/gardener/gardener/pkg/apis/core/v1beta1/helper"
1818 "github.com/gardener/gardener/pkg/utils"
1919 "github.com/gardener/gardener/pkg/utils/gardener"
20- gutil "github.com/gardener/gardener/pkg/utils/gardener"
2120 "k8s.io/apimachinery/pkg/util/sets"
2221 "k8s.io/apimachinery/pkg/util/validation/field"
2322 "k8s.io/utils/ptr"
@@ -176,33 +175,33 @@ func ValidateProviderMachineImage(providerImage api.MachineImages, capabilityDef
176175 // Validate each version
177176 for j , version := range providerImage .Versions {
178177 jdxPath := validationPath .Child ("versions" ).Index (j )
179- allErrs = append (allErrs , validateMachineImageVersion (providerImage , capabilityDefinitions , version , jdxPath )... )
178+ allErrs = append (allErrs , validateMachineImageVersion (capabilityDefinitions , version , jdxPath )... )
180179 }
181180
182181 return allErrs
183182}
184183
185- // validateMachineImageVersion validates a specific machine image version
186- func validateMachineImageVersion (providerImage api. MachineImages , capabilityDefinitions []gardencorev1beta1.CapabilityDefinition , version api.MachineImageVersion , jdxPath * field.Path ) field.ErrorList {
184+ // validates a specific machine image version
185+ func validateMachineImageVersion (capabilityDefinitions []gardencorev1beta1.CapabilityDefinition , version api.MachineImageVersion , jdxPath * field.Path ) field.ErrorList {
187186 allErrs := field.ErrorList {}
188187
189188 if len (version .Version ) == 0 {
190189 allErrs = append (allErrs , field .Required (jdxPath .Child ("version" ), "must provide a version" ))
191190 }
192191
193192 if len (capabilityDefinitions ) > 0 {
194- allErrs = append (allErrs , validateCapabilityFlavors (providerImage , version , capabilityDefinitions , jdxPath )... )
193+ allErrs = append (allErrs , validateCapabilityFlavors (version , capabilityDefinitions , jdxPath )... )
195194 } else {
196- allErrs = append (allErrs , validateRegions (version .Regions , providerImage . Name , version . Version , capabilityDefinitions , jdxPath )... )
195+ allErrs = append (allErrs , validateRegions (version .Regions , capabilityDefinitions , jdxPath )... )
197196 if len (version .CapabilityFlavors ) > 0 {
198197 allErrs = append (allErrs , field .Forbidden (jdxPath .Child ("capabilityFlavors" ), "must not be set as CloudProfile does not define capabilities. Use regions instead." ))
199198 }
200199 }
201200 return allErrs
202201}
203202
204- // validateCapabilityFlavors validates the capability flavors of a machine image version.
205- func validateCapabilityFlavors (providerImage api. MachineImages , version api.MachineImageVersion , capabilityDefinitions []gardencorev1beta1.CapabilityDefinition , jdxPath * field.Path ) field.ErrorList {
203+ // validates the capability flavors of a machine image version.
204+ func validateCapabilityFlavors (version api.MachineImageVersion , capabilityDefinitions []gardencorev1beta1.CapabilityDefinition , jdxPath * field.Path ) field.ErrorList {
206205 allErrs := field.ErrorList {}
207206
208207 // When using capabilities, regions must not be set
@@ -213,14 +212,14 @@ func validateCapabilityFlavors(providerImage api.MachineImages, version api.Mach
213212 // Validate each flavor's capabilities and regions
214213 for k , capabilitySet := range version .CapabilityFlavors {
215214 kdxPath := jdxPath .Child ("capabilityFlavors" ).Index (k )
216- allErrs = append (allErrs , gutil .ValidateCapabilities (capabilitySet .Capabilities , capabilityDefinitions , kdxPath .Child ("capabilities" ))... )
217- allErrs = append (allErrs , validateRegions (capabilitySet .Regions , providerImage . Name , version . Version , capabilityDefinitions , kdxPath )... )
215+ allErrs = append (allErrs , gardener .ValidateCapabilities (capabilitySet .Capabilities , capabilityDefinitions , kdxPath .Child ("capabilities" ))... )
216+ allErrs = append (allErrs , validateRegions (capabilitySet .Regions , capabilityDefinitions , kdxPath )... )
218217 }
219218 return allErrs
220219}
221220
222- // validateRegions validates the regions of a machine image version or capability flavor.
223- func validateRegions (regions []api.RegionIDMapping , name , version string , capabilityDefinitions []gardencorev1beta1.CapabilityDefinition , jdxPath * field.Path ) field.ErrorList {
221+ // validates the regions of a machine image version or capability flavor.
222+ func validateRegions (regions []api.RegionIDMapping , capabilityDefinitions []gardencorev1beta1.CapabilityDefinition , jdxPath * field.Path ) field.ErrorList {
224223 allErrs := field.ErrorList {}
225224
226225 for k , region := range regions {
@@ -249,42 +248,6 @@ func validateRegions(regions []api.RegionIDMapping, name, version string, capabi
249248 return allErrs
250249}
251250
252- // ValidateProviderMachineImageLegacy validates a CloudProfileConfig MachineImages entry.
253- func ValidateProviderMachineImageLegacy (validationPath * field.Path , machineImage api.MachineImages ) field.ErrorList {
254- allErrs := field.ErrorList {}
255-
256- if len (machineImage .Name ) == 0 {
257- allErrs = append (allErrs , field .Required (validationPath .Child ("name" ), "must provide a name" ))
258- }
259-
260- if len (machineImage .Versions ) == 0 {
261- allErrs = append (allErrs , field .Required (validationPath .Child ("versions" ), fmt .Sprintf ("must provide at least one version for machine image %q" , machineImage .Name )))
262- }
263- for j , version := range machineImage .Versions {
264- jdxPath := validationPath .Child ("versions" ).Index (j )
265-
266- if len (version .Version ) == 0 {
267- allErrs = append (allErrs , field .Required (jdxPath .Child ("version" ), "must provide a version" ))
268- }
269-
270- for k , region := range version .Regions {
271- kdxPath := jdxPath .Child ("regions" ).Index (k )
272-
273- if len (region .Name ) == 0 {
274- allErrs = append (allErrs , field .Required (kdxPath .Child ("name" ), "must provide a name" ))
275- }
276- if len (region .ID ) == 0 {
277- allErrs = append (allErrs , field .Required (kdxPath .Child ("id" ), "must provide an image ID" ))
278- }
279- if ! slices .Contains (v1beta1constants .ValidArchitectures , ptr .Deref (region .Architecture , v1beta1constants .ArchitectureAMD64 )) {
280- allErrs = append (allErrs , field .NotSupported (kdxPath .Child ("architecture" ), * region .Architecture , v1beta1constants .ValidArchitectures ))
281- }
282- }
283- }
284-
285- return allErrs
286- }
287-
288251// NewProviderImagesContext creates a new ImagesContext for provider images.
289252func NewProviderImagesContext (providerImages []api.MachineImages ) * gardener.ImagesContext [api.MachineImages , api.MachineImageVersion ] {
290253 return gardener .NewImagesContext (
0 commit comments