Skip to content

Commit

Permalink
add argocd admin username (#230)
Browse files Browse the repository at this point in the history
Signed-off-by: Manabu McCloskey <[email protected]>
  • Loading branch information
nabuskey authored Apr 26, 2024
1 parent 6dfe2d8 commit 64660b3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
25 changes: 20 additions & 5 deletions pkg/cmd/get/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ import (
)

const (
secretTemplatePath = "templates/secrets.tmpl"
secretTemplatePath = "templates/secrets.tmpl"
argoCDAdminUsername = "admin"
argoCDInitialAdminSecretName = "argocd-initial-admin-secret"
giteaAdminSecretName = "gitea-credential"
)

//go:embed templates
Expand All @@ -39,8 +42,8 @@ var SecretsCmd = &cobra.Command{

// well known secrets that are part of the core packages
var corePkgSecrets = map[string][]string{
"argocd": []string{"argocd-initial-admin-secret"},
"gitea": []string{"gitea-credential"},
"argocd": []string{argoCDInitialAdminSecretName},
"gitea": []string{giteaAdminSecretName},
}

type TemplateData struct {
Expand Down Expand Up @@ -80,7 +83,7 @@ func printAllPackageSecrets(ctx context.Context, outWriter io.Writer, kubeClient

for k, v := range corePkgSecrets {
for i := range v {
secret, sErr := getSecretByName(ctx, kubeClient, k, v[i])
secret, sErr := getCorePackageSecret(ctx, kubeClient, k, v[i])
if sErr != nil {
if errors.IsNotFound(sErr) {
continue
Expand Down Expand Up @@ -116,7 +119,7 @@ func printPackageSecrets(ctx context.Context, outWriter io.Writer, kubeClient cl
secretNames, ok := corePkgSecrets[p]
if ok {
for j := range secretNames {
secret, sErr := getSecretByName(ctx, kubeClient, p, secretNames[j])
secret, sErr := getCorePackageSecret(ctx, kubeClient, p, secretNames[j])
if sErr != nil {
if errors.IsNotFound(sErr) {
continue
Expand Down Expand Up @@ -197,3 +200,15 @@ func getSecretByName(ctx context.Context, kubeClient client.Client, ns, name str
s := v1.Secret{}
return s, kubeClient.Get(ctx, client.ObjectKey{Name: name, Namespace: ns}, &s)
}

func getCorePackageSecret(ctx context.Context, kubeClient client.Client, ns, name string) (v1.Secret, error) {
s, err := getSecretByName(ctx, kubeClient, ns, name)
if err != nil {
return v1.Secret{}, err
}

if name == argoCDInitialAdminSecretName && s.Data != nil {
s.Data["username"] = []byte(argoCDAdminUsername)
}
return s, nil
}
14 changes: 7 additions & 7 deletions pkg/cmd/get/secrets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,23 @@ func TestPrintPackageSecrets(t *testing.T) {
packages: []string{"argocd", "gitea", "abc"},
listLabelSelector: []labels.Selector{selector("abc")},
getKeys: []client.ObjectKey{
{Name: "argocd-initial-admin-secret", Namespace: "argocd"},
{Name: "gitea-credential", Namespace: "gitea"},
{Name: argoCDInitialAdminSecretName, Namespace: "argocd"},
{Name: giteaAdminSecretName, Namespace: "gitea"},
},
},
{
err: nil,
packages: []string{"argocd", "gitea"},
getKeys: []client.ObjectKey{
{Name: "argocd-initial-admin-secret", Namespace: "argocd"},
{Name: "gitea-credential", Namespace: "gitea"},
{Name: argoCDInitialAdminSecretName, Namespace: "argocd"},
{Name: giteaAdminSecretName, Namespace: "gitea"},
},
},
{
err: nil,
packages: []string{"argocd"},
getKeys: []client.ObjectKey{
{Name: "argocd-initial-admin-secret", Namespace: "argocd"},
{Name: argoCDInitialAdminSecretName, Namespace: "argocd"},
},
},
}
Expand Down Expand Up @@ -109,8 +109,8 @@ func TestPrintAllPackageSecrets(t *testing.T) {
err: nil,
listLabelSelector: []labels.Selector{labels.NewSelector().Add(*r)},
getKeys: []client.ObjectKey{
{Name: "argocd-initial-admin-secret", Namespace: "argocd"},
{Name: "gitea-credential", Namespace: "gitea"},
{Name: argoCDInitialAdminSecretName, Namespace: "argocd"},
{Name: giteaAdminSecretName, Namespace: "gitea"},
},
},
}
Expand Down

0 comments on commit 64660b3

Please sign in to comment.