Skip to content

Commit

Permalink
do not create git auth secret if it exists
Browse files Browse the repository at this point in the history
  • Loading branch information
Davor Gajic committed Dec 7, 2023
1 parent 5439ce6 commit f3dfd3d
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions create/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit f3dfd3d

Please sign in to comment.