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

add argocd admin username #230

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
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
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
Loading