Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 1 addition & 23 deletions pkg/apis/stackit/validation/infrastructure.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.
Expand Down Expand Up @@ -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
}
44 changes: 2 additions & 42 deletions pkg/apis/stackit/validation/infrastructure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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())
})

})
})