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

[GEP-25] Enable Shoot cloudProfile reference as complement to cloudProfileName #636

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ rules:
- core.gardener.cloud
resources:
- cloudprofiles
- namespacedcloudprofiles
verbs:
- get
- list
Expand Down
3 changes: 2 additions & 1 deletion docs/operations/operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ metadata:
name: my-shoot
namespace: my-namespace
spec:
cloudProfileName: ironcore
cloudProfile:
name: ironcore
secretBindingName: my-credentials
region: my-region
networking:
Expand Down
17 changes: 13 additions & 4 deletions pkg/admission/validator/shoot.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
extensionswebhook "github.com/gardener/gardener/extensions/pkg/webhook"
"github.com/gardener/gardener/pkg/apis/core"
gardencorev1beta1 "github.com/gardener/gardener/pkg/apis/core/v1beta1"
"github.com/gardener/gardener/pkg/utils/gardener"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/apimachinery/pkg/util/validation/field"
Expand Down Expand Up @@ -68,7 +69,7 @@ type validationContext struct {
shoot *core.Shoot
infrastructureConfig *apisironcore.InfrastructureConfig
controlPlaneConfig *apisironcore.ControlPlaneConfig
cloudProfile *gardencorev1beta1.CloudProfile
cloudProfileSpec *gardencorev1beta1.CloudProfileSpec
}

func (s *shoot) validateContext(valContext *validationContext) field.ErrorList {
Expand Down Expand Up @@ -142,10 +143,18 @@ func newValidationContext(ctx context.Context, decoder runtime.Decoder, c client
return nil, fmt.Errorf("error decoding controlPlaneConfig: %v", err)
}

cloudProfile := &gardencorev1beta1.CloudProfile{}
if err := c.Get(ctx, client.ObjectKey{Name: shoot.Spec.CloudProfile.Name}, cloudProfile); err != nil {
shootV1Beta1 := &gardencorev1beta1.Shoot{}
err = gardencorev1beta1.Convert_core_Shoot_To_v1beta1_Shoot(shoot, shootV1Beta1, nil)
if err != nil {
return nil, err
}
cloudProfile, err := gardener.GetCloudProfile(ctx, c, shootV1Beta1)
if err != nil {
return nil, err
}
if cloudProfile == nil {
return nil, fmt.Errorf("cloudprofile could not be found")
}

if cloudProfile.Spec.ProviderConfig == nil {
return nil, fmt.Errorf("providerConfig is not given for cloud profile %q", cloudProfile.Name)
Expand All @@ -155,6 +164,6 @@ func newValidationContext(ctx context.Context, decoder runtime.Decoder, c client
shoot: shoot,
infrastructureConfig: infrastructureConfig,
controlPlaneConfig: controlPlaneConfig,
cloudProfile: cloudProfile,
cloudProfileSpec: &cloudProfile.Spec,
}, nil
}
8 changes: 6 additions & 2 deletions pkg/apis/ironcore/helper/scheme.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
k8sclient "sigs.k8s.io/controller-runtime/pkg/client"

api "github.com/ironcore-dev/gardener-extension-provider-ironcore/pkg/apis/ironcore"
"github.com/ironcore-dev/gardener-extension-provider-ironcore/pkg/apis/ironcore/install"
Expand Down Expand Up @@ -65,9 +65,13 @@ func InfrastructureStatusFromRaw(raw *runtime.RawExtension) (*api.Infrastructure
func CloudProfileConfigFromCluster(cluster *controller.Cluster) (*api.CloudProfileConfig, error) {
var cloudProfileConfig *api.CloudProfileConfig
if cluster != nil && cluster.CloudProfile != nil && cluster.CloudProfile.Spec.ProviderConfig != nil && cluster.CloudProfile.Spec.ProviderConfig.Raw != nil {
cloudProfileSpecifier := fmt.Sprintf("CloudProfile %q", k8sclient.ObjectKeyFromObject(cluster.CloudProfile))
if cluster.Shoot != nil && cluster.Shoot.Spec.CloudProfile != nil {
cloudProfileSpecifier = fmt.Sprintf("%s '%s/%s'", cluster.Shoot.Spec.CloudProfile.Kind, cluster.Shoot.Namespace, cluster.Shoot.Spec.CloudProfile.Name)
}
cloudProfileConfig = &api.CloudProfileConfig{}
if _, _, err := decoder.Decode(cluster.CloudProfile.Spec.ProviderConfig.Raw, nil, cloudProfileConfig); err != nil {
return nil, fmt.Errorf("could not decode providerConfig of cloudProfile for '%s': %w", client.ObjectKeyFromObject(cluster.CloudProfile), err)
return nil, fmt.Errorf("could not decode providerConfig of %s: %w", cloudProfileSpecifier, err)
}
}
return cloudProfileConfig, nil
Expand Down