Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix validation webhook #313

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
8 changes: 6 additions & 2 deletions pkg/admission/validator/shoot.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,15 @@ func (s *shoot) validateShoot(ctx context.Context, shoot *core.Shoot) error {
// InfrastructureConfig
infraConfigFldPath := fldPath.Child("infrastructureConfig")

// ControlPlaneConfig
controlPlaneConfigFldPath := fldPath.Child("controlPlaneConfig")

if shoot.Spec.Provider.InfrastructureConfig == nil {
return field.Required(infraConfigFldPath, "InfrastructureConfig must be set for metal shoots")
}
if shoot.Spec.Provider.ControlPlaneConfig == nil {
return field.Required(controlPlaneConfigFldPath, "ControlPlaneConfig must be set for metal shoots")
}

infraConfig, err := decodeInfrastructureConfig(s.decoder, shoot.Spec.Provider.InfrastructureConfig, infraConfigFldPath)
if err != nil {
Expand All @@ -100,8 +106,6 @@ func (s *shoot) validateShoot(ctx context.Context, shoot *core.Shoot) error {
return errList.ToAggregate()
}

controlPlaneConfigFldPath := fldPath.Child("controlPlaneConfig")

controlPlaneConfig, err := decodeControlPlaneConfig(s.decoder, shoot.Spec.Provider.ControlPlaneConfig, fldPath.Child("controlPlaneConfig"))
if err != nil {
return err
Expand Down
9 changes: 9 additions & 0 deletions pkg/apis/metal/validation/infrastructure.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ func ValidateInfrastructureConfigAgainstCloudProfile(infra *apismetal.Infrastruc
return allErrs
}

cloudConfigPath := fldPath.Child("cloudConfig")

if cloudProfileConfig.Kind == "" {
allErrs = append(allErrs, field.Required(cloudConfigPath.Child("kind"), "at least kind is required"))
}
if cloudProfileConfig.APIVersion == "" {
allErrs = append(allErrs, field.Required(cloudConfigPath.Child("apiVersion"), "at least apiVersion is required"))
}

mcp, p, err := helper.FindMetalControlPlane(cloudProfileConfig, infra.PartitionID)
if err != nil {
allErrs = append(allErrs, field.Invalid(fldPath.Child("partitionID"), infra.PartitionID, "cloud profile does not define the given shoot partition"))
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/metal/validation/infrastructure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package validation_test
import (
"github.com/gardener/gardener/pkg/apis/core"
gardencorev1beta1 "github.com/gardener/gardener/pkg/apis/core/v1beta1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/validation/field"

apismetal "github.com/metal-stack/gardener-extension-provider-metal/pkg/apis/metal"
Expand Down Expand Up @@ -254,5 +255,9 @@ func createCloudProfileConfig() *apismetal.CloudProfileConfig {
},
},
},
TypeMeta: v1.TypeMeta{
Kind: "cloudProfile",
APIVersion: "v1alpha1",
},
}
}