Skip to content

Commit

Permalink
Address PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
dimityrmirchev committed Sep 20, 2024
1 parent c0cd79e commit 4ede948
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 2 additions & 0 deletions cmd/gardener-extension-admission-alicloud/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
webhookcmd "github.com/gardener/gardener/extensions/pkg/webhook/cmd"
"github.com/gardener/gardener/pkg/apis/core/install"
v1beta1constants "github.com/gardener/gardener/pkg/apis/core/v1beta1/constants"
securityinstall "github.com/gardener/gardener/pkg/apis/security/install"
gardenerhealthz "github.com/gardener/gardener/pkg/healthz"
"github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -118,6 +119,7 @@ func NewAdmissionCommand(ctx context.Context) *cobra.Command {
}

install.Install(mgr.GetScheme())
securityinstall.Install(mgr.GetScheme())

if err := alicloudinstall.AddToScheme(mgr.GetScheme()); err != nil {
return fmt.Errorf("could not update manager scheme: %w", err)
Expand Down
8 changes: 3 additions & 5 deletions pkg/admission/validator/credentialsbinding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ var _ = Describe("CredentialsBinding validator", func() {
Expect(err).To(HaveOccurred())
})

It("should return nil when the corresponding Secret is valid", func() {
It("should succeed when the corresponding Secret is valid", func() {
apiReader.EXPECT().Get(ctx, client.ObjectKey{Namespace: namespace, Name: name}, gomock.AssignableToTypeOf(&corev1.Secret{})).
DoAndReturn(func(_ context.Context, _ client.ObjectKey, obj *corev1.Secret, _ ...client.GetOption) error {
secret := &corev1.Secret{Data: map[string][]byte{
Expand All @@ -116,15 +116,13 @@ var _ = Describe("CredentialsBinding validator", func() {
return nil
})

err := credentialsBindingValidator.Validate(ctx, credentialsBinding, nil)
Expect(err).NotTo(HaveOccurred())
Expect(credentialsBindingValidator.Validate(ctx, credentialsBinding, nil)).To(Succeed())
})

It("should return nil when the CredentialsBinding did not change", func() {
old := credentialsBinding.DeepCopy()

err := credentialsBindingValidator.Validate(ctx, credentialsBinding, old)
Expect(err).NotTo(HaveOccurred())
Expect(credentialsBindingValidator.Validate(ctx, credentialsBinding, old)).To(Succeed())
})
})
})
10 changes: 6 additions & 4 deletions pkg/admission/validator/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const (

var logger = log.Log.WithName("alicloud-validator-webhook")

// New creates a new webhook that validates Shoot and CloudProfile resources.
// New creates a new webhook that validates Shoot, CloudProfile, SecretBinding and CredentialsBinding resources.
func New(mgr manager.Manager) (*extensionswebhook.Webhook, error) {
logger.Info("Setting up webhook", "name", Name)

Expand All @@ -37,9 +37,11 @@ func New(mgr manager.Manager) (*extensionswebhook.Webhook, error) {
Path: "/webhooks/validate",
Predicates: []predicate.Predicate{extensionspredicate.GardenCoreProviderType(alicloud.Type)},
Validators: map[extensionswebhook.Validator][]extensionswebhook.Type{
NewShootValidator(mgr): {{Obj: &core.Shoot{}}},
NewCloudProfileValidator(mgr): {{Obj: &core.CloudProfile{}}},
NewSecretBindingValidator(mgr): {{Obj: &core.SecretBinding{}}},
NewShootValidator(mgr): {{Obj: &core.Shoot{}}},
NewCloudProfileValidator(mgr): {{Obj: &core.CloudProfile{}}},
NewSecretBindingValidator(mgr): {{Obj: &core.SecretBinding{}}},
// TODO(dimityrmirchev): Uncomment this line once this extension uses a g/g version that contains https://github.com/gardener/gardener/pull/10499
// Predicates: []predicate.Predicate{predicate.Or(extensionspredicate.GardenCoreProviderType(alicloud.Type), extensionspredicate.GardenSecurityProviderType(alicloud.Type))},
NewCredentialsBindingValidator(mgr): {{Obj: &security.CredentialsBinding{}}},
},
Target: extensionswebhook.TargetSeed,
Expand Down

0 comments on commit 4ede948

Please sign in to comment.