From f3dfd3d8d8c86f41caaec29fb12383543f100e70 Mon Sep 17 00:00:00 2001 From: Davor Gajic Date: Thu, 7 Dec 2023 15:10:59 +0100 Subject: [PATCH] do not create git auth secret if it exists --- create/application.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/create/application.go b/create/application.go index db1ad08..a86b679 100644 --- a/create/application.go +++ b/create/application.go @@ -20,6 +20,7 @@ import ( "github.com/ninech/nctl/internal/format" "github.com/ninech/nctl/logs" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/watch" "k8s.io/utils/pointer" runtimeclient "sigs.k8s.io/controller-runtime/pkg/client" @@ -102,10 +103,18 @@ func (app *applicationCmd) Run(ctx context.Context, client *api.Client) error { if err := auth.Valid(); err != nil { return fmt.Errorf("the credentials are given but they are empty: %w", err) } - // for git auth we create a separate secret and then reference it in the app. + secret := auth.Secret(newApp) - if err := client.Create(ctx, secret); err != nil { - return fmt.Errorf("unable to create git auth secret: %w", err) + if err := client.Get(ctx, types.NamespacedName{Name: secret.Name, Namespace: secret.Namespace}, secret); err != nil { + // for git auth we create a separate secret and then reference it in the app. + if err := client.Create(ctx, secret); err != nil { + return fmt.Errorf("unable to create git auth secret: %w", err) + } + } else { + fmt.Println("updating git auth credentials") + if err := client.Update(ctx, secret); err != nil { + return fmt.Errorf("unable to update git auth secret: %w", err) + } } newApp.Spec.ForProvider.Git.Auth = &apps.GitAuth{