From 81c40ddb4c6be1d1dbf290bb2bfc7de573886551 Mon Sep 17 00:00:00 2001 From: Haytham Abuelfutuh Date: Tue, 11 May 2021 11:48:51 -0700 Subject: [PATCH] init-secrets: Use the right IsAlreadyExists (#261) Signed-off-by: Haytham Abuelfutuh --- flytepropeller/cmd/controller/cmd/init_certs.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/flytepropeller/cmd/controller/cmd/init_certs.go b/flytepropeller/cmd/controller/cmd/init_certs.go index ba65d7c64e..d59b192096 100644 --- a/flytepropeller/cmd/controller/cmd/init_certs.go +++ b/flytepropeller/cmd/controller/cmd/init_certs.go @@ -5,8 +5,6 @@ import ( "context" cryptorand "crypto/rand" - "github.com/flyteorg/flyteidl/clients/go/events/errors" - "github.com/flyteorg/flytestdlib/logger" kubeErrors "k8s.io/apimachinery/pkg/api/errors" @@ -119,8 +117,12 @@ func createWebhookSecret(ctx context.Context, namespace string, cfg *webhook.Con } _, err := secretsClient.Create(ctx, secret, v12.CreateOptions{}) + if err == nil { + logger.Infof(ctx, "Created secret [%v]", cfg.SecretName) + return nil + } - if errors.IsAlreadyExists(err) { + if kubeErrors.IsAlreadyExists(err) { logger.Infof(ctx, "A secret already exists with the same name. Validating.") s, err := secretsClient.Get(ctx, cfg.SecretName, v12.GetOptions{}) if err != nil { @@ -142,8 +144,10 @@ func createWebhookSecret(ctx context.Context, namespace string, cfg *webhook.Con if requiresUpdate { logger.Infof(ctx, "The existing secret is missing one or more keys.") - secret.Annotations["flyteLastUpdate"] = "system-updated" - secret.Annotations["flyteUpdatedAt"] = time.Now().String() + secret.Annotations = map[string]string{ + "flyteLastUpdate": "system-updated", + "flyteUpdatedAt": time.Now().String(), + } _, err = secretsClient.Update(ctx, secret, v12.UpdateOptions{}) if err != nil && kubeErrors.IsConflict(err) { @@ -157,8 +161,6 @@ func createWebhookSecret(ctx context.Context, namespace string, cfg *webhook.Con return nil } - logger.Infof(ctx, "Created secret [%v]", cfg.SecretName) - return err }