diff --git a/pkg/apis/stackit/validation/infrastructure.go b/pkg/apis/stackit/validation/infrastructure.go index eb37d372..a09175aa 100644 --- a/pkg/apis/stackit/validation/infrastructure.go +++ b/pkg/apis/stackit/validation/infrastructure.go @@ -5,8 +5,6 @@ package validation import ( - "slices" - cidrvalidation "github.com/gardener/gardener/pkg/utils/validation/cidr" "github.com/google/uuid" apivalidation "k8s.io/apimachinery/pkg/api/validation" @@ -19,10 +17,6 @@ import ( func ValidateInfrastructureConfig(infra *stackitv1alpha1.InfrastructureConfig, nodesCIDR *string, fldPath *field.Path) field.ErrorList { allErrs := field.ErrorList{} - if len(infra.FloatingPoolName) == 0 { - allErrs = append(allErrs, field.Required(fldPath.Child("floatingPoolName"), "must provide the name of a floating pool")) - } - networksPath := fldPath.Child("networks") // check InfrastructureConfig.networks.worker(s) is a valid cidr and not be set if a network id is provided. @@ -104,24 +98,8 @@ func ValidateInfrastructureConfigUpdate(oldConfig, newConfig *stackitv1alpha1.In } // ValidateInfrastructureConfigAgainstCloudProfile validates the given InfrastructureConfig against constraints in the given CloudProfile. -func ValidateInfrastructureConfigAgainstCloudProfile(oldInfra, infra *stackitv1alpha1.InfrastructureConfig, cloudProfileConfig *stackitv1alpha1.CloudProfileConfig, fldPath *field.Path) field.ErrorList { +func ValidateInfrastructureConfigAgainstCloudProfile(_, _ *stackitv1alpha1.InfrastructureConfig, _ *stackitv1alpha1.CloudProfileConfig, _ *field.Path) field.ErrorList { allErrs := field.ErrorList{} - if oldInfra == nil || oldInfra.FloatingPoolName != infra.FloatingPoolName { - //nolint:staticcheck // SA1019: needed for migration purposes - allErrs = append(allErrs, validateFloatingPoolNameConstraints(cloudProfileConfig.Constraints.FloatingPools, infra.FloatingPoolName, fldPath.Child("floatingPoolName"))) - } - return allErrs } - -func validateFloatingPoolNameConstraints(fps []stackitv1alpha1.FloatingPool, name string, fldPath *field.Path) *field.Error { - availablePoolNames := make([]string, 0, len(fps)) - for _, fp := range fps { - availablePoolNames = append(availablePoolNames, fp.Name) - } - if !slices.Contains(availablePoolNames, name) { - return field.NotSupported(fldPath, name, availablePoolNames) - } - return nil -} diff --git a/pkg/apis/stackit/validation/infrastructure_test.go b/pkg/apis/stackit/validation/infrastructure_test.go index 48be106f..40b7975a 100644 --- a/pkg/apis/stackit/validation/infrastructure_test.go +++ b/pkg/apis/stackit/validation/infrastructure_test.go @@ -38,15 +38,12 @@ var _ = Describe("InfrastructureConfig validation", func() { }) Describe("#ValidateInfrastructureConfig", func() { - It("should forbid invalid floating pool name configuration", func() { + It("should allow empty floating pool name configuration", func() { infrastructureConfig.FloatingPoolName = "" errorList := ValidateInfrastructureConfig(infrastructureConfig, &nodes, nilPath) - Expect(errorList).To(ConsistOfFields(Fields{ - "Type": Equal(field.ErrorTypeRequired), - "Field": Equal("floatingPoolName"), - })) + Expect(errorList).To(BeEmpty()) }) It("should forbid invalid router id configuration", func() { @@ -240,41 +237,4 @@ var _ = Describe("InfrastructureConfig validation", func() { })))) }) }) - - Describe("#ValidateInfrastructureConfigAgainstCloudProfile", func() { - var cloudProfileConfig *stackitv1alpha1.CloudProfileConfig - - BeforeEach(func() { - cloudProfileConfig = &stackitv1alpha1.CloudProfileConfig{ - Constraints: stackitv1alpha1.Constraints{ - FloatingPools: []stackitv1alpha1.FloatingPool{ - { - Name: floatingPoolName1, - }, - }, - }, - } - }) - - It("should validate that the floating pool name exists in the cloud profile", func() { - oldInfrastructureConfig := infrastructureConfig.DeepCopy() - infrastructureConfig.FloatingPoolName = "does-for-sure-not-exist-in-cloudprofile" - - errorList := ValidateInfrastructureConfigAgainstCloudProfile(oldInfrastructureConfig, infrastructureConfig, cloudProfileConfig, nilPath) - Expect(errorList).To(ConsistOfFields(Fields{ - "Type": Equal(field.ErrorTypeNotSupported), - "Field": Equal("floatingPoolName"), - "BadValue": Equal("does-for-sure-not-exist-in-cloudprofile"), - })) - }) - - It("should not validate anything if the floating pool name was not changed", func() { - infrastructureConfig.FloatingPoolName = "does-for-sure-not-exist-in-cloudprofile" - oldInfrastructureConfig := infrastructureConfig.DeepCopy() - - errorList := ValidateInfrastructureConfigAgainstCloudProfile(oldInfrastructureConfig, infrastructureConfig, cloudProfileConfig, nilPath) - Expect(errorList).To(BeEmpty()) - }) - - }) })