From 3c9228d1aa68710a8ba3c02ff55e45a6f1b91ff5 Mon Sep 17 00:00:00 2001 From: Maksim Fedotov Date: Tue, 17 May 2022 14:54:52 +0300 Subject: [PATCH] fix: protectedHandler OnDelete get tenant using client --- e2e/tenant_protected_webhook_test.go | 2 +- pkg/webhook/tenant/protected.go | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/e2e/tenant_protected_webhook_test.go b/e2e/tenant_protected_webhook_test.go index 3ad33247..e80039b8 100644 --- a/e2e/tenant_protected_webhook_test.go +++ b/e2e/tenant_protected_webhook_test.go @@ -18,7 +18,7 @@ import ( var _ = Describe("Deleting a tenant with protected annotation", func() { tnt := &capsulev1beta1.Tenant{ ObjectMeta: metav1.ObjectMeta{ - Name: "protected_tenant", + Name: "protected-tenant", Annotations: map[string]string{ capsulev1beta1.ProtectedTenantAnnotation: "", }, diff --git a/pkg/webhook/tenant/protected.go b/pkg/webhook/tenant/protected.go index a39dd7e7..e5381bfa 100644 --- a/pkg/webhook/tenant/protected.go +++ b/pkg/webhook/tenant/protected.go @@ -7,6 +7,7 @@ import ( "context" "fmt" + "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/tools/record" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/webhook/admission" @@ -28,10 +29,11 @@ func (h *protectedHandler) OnCreate(client.Client, *admission.Decoder, record.Ev } } -func (h *protectedHandler) OnDelete(_ client.Client, decoder *admission.Decoder, _ record.EventRecorder) capsulewebhook.Func { +func (h *protectedHandler) OnDelete(clt client.Client, decoder *admission.Decoder, _ record.EventRecorder) capsulewebhook.Func { return func(ctx context.Context, req admission.Request) *admission.Response { tenant := &capsulev1beta1.Tenant{} - if err := decoder.Decode(req, tenant); err != nil { + + if err := clt.Get(ctx, types.NamespacedName{Name: req.AdmissionRequest.Name}, tenant); err != nil { return utils.ErroredResponse(err) }