-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for cloudprofile field and validate namespacedcloudprofiles
- Loading branch information
1 parent
bf2b2b0
commit 21a1f9e
Showing
6 changed files
with
138 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package validator | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
extensionswebhook "github.com/gardener/gardener/extensions/pkg/webhook" | ||
"github.com/gardener/gardener/pkg/apis/core" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/runtime/serializer" | ||
"k8s.io/apimachinery/pkg/util/validation/field" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
"sigs.k8s.io/controller-runtime/pkg/manager" | ||
|
||
awsvalidation "github.com/gardener/gardener-extension-provider-aws/pkg/apis/aws/validation" | ||
) | ||
|
||
// NewNamespacedCloudProfileValidator returns a new instance of a cloud profile validator. | ||
func NewNamespacedCloudProfileValidator(mgr manager.Manager) extensionswebhook.Validator { | ||
return &namespacedCloudProfile{ | ||
decoder: serializer.NewCodecFactory(mgr.GetScheme(), serializer.EnableStrict).UniversalDecoder(), | ||
} | ||
} | ||
|
||
type namespacedCloudProfile struct { | ||
decoder runtime.Decoder | ||
} | ||
|
||
// Validate validates the given namespaced cloud profile objects. | ||
func (cp *namespacedCloudProfile) Validate(_ context.Context, new, _ client.Object) error { | ||
cloudProfile, ok := new.(*core.NamespacedCloudProfile) | ||
if !ok { | ||
return fmt.Errorf("wrong object type %T", new) | ||
} | ||
|
||
providerConfigPath := field.NewPath("status", "cloudProfileSpec").Child("providerConfig") | ||
if cloudProfile.Status.CloudProfileSpec.ProviderConfig == nil { | ||
return field.Required(providerConfigPath, "providerConfig must be calculated for AWS namespaced cloud profiles") | ||
} | ||
|
||
cpConfig, err := decodeCloudProfileConfig(cp.decoder, cloudProfile.Status.CloudProfileSpec.ProviderConfig) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return awsvalidation.ValidateCloudProfileConfig(cpConfig, providerConfigPath).ToAggregate() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters