From 458aacbe2dde05cb532f772ed8cde91955e4ace5 Mon Sep 17 00:00:00 2001 From: cloudwiz Date: Wed, 3 Nov 2021 16:05:31 +0000 Subject: [PATCH] Allow creating secrets for the not yet existing mesh Signed-off-by: cloudwiz --- .../runtime/k8s/webhooks/secret_validator.go | 4 +--- .../k8s/webhooks/secret_validator_test.go | 22 +++++-------------- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/pkg/plugins/runtime/k8s/webhooks/secret_validator.go b/pkg/plugins/runtime/k8s/webhooks/secret_validator.go index 43760b334bde..ccdef78a129b 100644 --- a/pkg/plugins/runtime/k8s/webhooks/secret_validator.go +++ b/pkg/plugins/runtime/k8s/webhooks/secret_validator.go @@ -107,9 +107,7 @@ func (v *SecretValidator) validateMeshSecret(ctx context.Context, verr *validato Name: meshOfSecret(secret), } if err := v.Client.Get(ctx, key, &mesh); err != nil { - if kube_apierrs.IsNotFound(err) { - verr.AddViolationAt(validators.RootedAt("metadata").Field("labels").Key(meshLabel), "mesh does not exist") - } else { + if !kube_apierrs.IsNotFound(err) { return errors.Wrap(err, "could not fetch mesh") } } diff --git a/pkg/plugins/runtime/k8s/webhooks/secret_validator_test.go b/pkg/plugins/runtime/k8s/webhooks/secret_validator_test.go index e82e8a2d4f7a..9d33027c5513 100644 --- a/pkg/plugins/runtime/k8s/webhooks/secret_validator_test.go +++ b/pkg/plugins/runtime/k8s/webhooks/secret_validator_test.go @@ -176,7 +176,7 @@ var _ = Describe("ServiceValidator", func() { uid: "" `, }), - Entry("should not allow Secret with mesh that does not exist", testCase{ + Entry("should allow Secret with mesh that does not exist", testCase{ request: ` apiVersion: admission.k8s.io/v1 kind: AdmissionReview @@ -202,21 +202,11 @@ var _ = Describe("ServiceValidator", func() { operation: CREATE `, expected: ` - allowed: false - status: - code: 422 - details: - causes: - - field: metadata.labels["kuma.io/mesh"] - message: mesh does not exist - reason: FieldValueInvalid - kind: Secret - name: sec-1 - message: 'metadata.labels["kuma.io/mesh"]: mesh does not exist' - metadata: {} - reason: Invalid - status: Failure - uid: "" + allowed: true + status: + code: 200 + metadata: {} + uid: "" `, }), Entry("should not allow switching mesh in Secret", testCase{