Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Issue-331] Checks that service account is available before secret is created #333

Merged
merged 1 commit into from
Aug 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions pkg/commands/secret/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ kp secret create my-git-cred --git-url https://github.com --git-user my-git-user

ctx := cmd.Context()

// First check that service account is available before secret is created
serviceAccount, err := cs.K8sClient.CoreV1().ServiceAccounts(cs.Namespace).Get(ctx, serviceAccount, metav1.GetOptions{})
if err != nil {
return err
}

if !ch.IsDryRun() {
secret, err = cs.K8sClient.CoreV1().Secrets(cs.Namespace).Create(ctx, secret, metav1.CreateOptions{})
if err != nil {
Expand All @@ -93,11 +99,6 @@ kp secret create my-git-cred --git-url https://github.com --git-user my-git-user
return err
}

serviceAccount, err := cs.K8sClient.CoreV1().ServiceAccounts(cs.Namespace).Get(ctx, serviceAccount, metav1.GetOptions{})
if err != nil {
return err
}

updatedSA := serviceAccount.DeepCopy()

updatedSA.Secrets = append(updatedSA.Secrets, corev1.ObjectReference{Name: args[0]})
Expand Down