Skip to content

Commit

Permalink
init-secrets: Use the right IsAlreadyExists (flyteorg#261)
Browse files Browse the repository at this point in the history
Signed-off-by: Haytham Abuelfutuh <[email protected]>
  • Loading branch information
EngHabu authored May 11, 2021
1 parent 36e0531 commit 81c40dd
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions flytepropeller/cmd/controller/cmd/init_certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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 {
Expand All @@ -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) {
Expand All @@ -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
}

Expand Down

0 comments on commit 81c40dd

Please sign in to comment.