From 482630731a083a3eac03b4a3da4c2db428be442f Mon Sep 17 00:00:00 2001 From: Daishan Date: Fri, 15 Nov 2019 10:24:41 -0700 Subject: [PATCH] Fix git-ssh secrets create in CLI Add annotation and url prompt. Tekton requires special annotations to add ssh-key --- cli/cmd/secrets/create.go | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/cli/cmd/secrets/create.go b/cli/cmd/secrets/create.go index 4c3656487..ed7aec921 100644 --- a/cli/cmd/secrets/create.go +++ b/cli/cmd/secrets/create.go @@ -44,8 +44,7 @@ func (s *Create) Run(ctx *clicontext.CLIContext) error { } else { secret = constructors.NewSecret(ns, constants.DefaultGithubCrendential, v1.Secret{}) } - setDefaults(secret) - secret.Type = v1.SecretTypeOpaque + setDefaults(secret, v1.SecretTypeOpaque) accessToken, err = questions.PromptPassword("Github AccessToken[******]: ", accessToken) if err != nil { @@ -113,7 +112,7 @@ func (s *Create) Run(ctx *clicontext.CLIContext) error { } else { secret = constructors.NewSecret(ns, constants.DefaultGitCrendential, v1.Secret{}) } - setDefaults(secret) + setDefaults(secret, v1.SecretTypeBasicAuth) url, err = questions.Prompt(fmt.Sprintf("git url[%s]: ", url), url) if err != nil { @@ -137,16 +136,27 @@ func (s *Create) Run(ctx *clicontext.CLIContext) error { if s.GitSSHKeyAuth { var err error - var sshPrivateKeyPath, ns string + var url, sshPrivateKeyPath, ns string ns, err = questions.Prompt("Select namespace[default]: ", "default") if err != nil { return err } - secret := constructors.NewSecret(ns, constants.DefaultGitCrendentialSSH, v1.Secret{}) - setDefaults(secret) - secret.Type = v1.SecretTypeSSHAuth + secret, err := ctx.Core.Secrets(ns).Get(constants.DefaultGitCrendentialSSH, metav1.GetOptions{}) + if err == nil { + url = secret.Annotations["tekton.dev/git-0"] + } else { + secret = constructors.NewSecret(ns, constants.DefaultGitCrendentialSSH, v1.Secret{}) + secret.Type = v1.SecretTypeSSHAuth + } + setDefaults(secret, v1.SecretTypeSSHAuth) + + url, err = questions.Prompt(fmt.Sprintf("git url[%s]: ", url), url) + if err != nil { + return err + } + secret.Annotations["tekton.dev/git-0"] = url sshPrivateKeyPath, err = questions.Prompt(fmt.Sprintf("ssh_key_path[%s]: ", sshPrivateKeyPath), sshPrivateKeyPath) if err != nil { @@ -211,8 +221,8 @@ func createOrUpdate(secret *v1.Secret, ctx *clicontext.CLIContext) error { return nil } -func setDefaults(secret *v1.Secret) { - secret.Type = v1.SecretTypeBasicAuth +func setDefaults(secret *v1.Secret, secretType v1.SecretType) { + secret.Type = secretType if secret.Annotations == nil { secret.Annotations = make(map[string]string) }