-
Notifications
You must be signed in to change notification settings - Fork 82
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
5c06494
commit 82e3247
Showing
5 changed files
with
251 additions
and
23 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
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" | ||
|
||
openstackvalidation "github.com/gardener/gardener-extension-provider-openstack/pkg/apis/openstack/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 OpenStack namespaced cloud profiles") | ||
} | ||
|
||
cpConfig, err := decodeCloudProfileConfig(cp.decoder, cloudProfile.Status.CloudProfileSpec.ProviderConfig) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return openstackvalidation.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
Oops, something went wrong.