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

set KUBECONFIG before argocd login #126

Merged
merged 3 commits into from
Jul 12, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 6 additions & 3 deletions cmd/commands/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type (
AppSpecifier string
InstallationMode string
Namespace string
KubeConfig string
KubeContext string
Namespaced bool
DryRun bool
Expand Down Expand Up @@ -135,6 +136,7 @@ func NewRepoBootstrapCommand() *cobra.Command {
AppSpecifier: appSpecifier,
InstallationMode: installationMode,
Namespace: cmd.Flag("namespace").Value.String(),
KubeConfig: cmd.Flag("kubeconfig").Value.String(),
KubeContext: cmd.Flag("context").Value.String(),
Namespaced: namespaced,
DryRun: dryRun,
Expand Down Expand Up @@ -262,9 +264,10 @@ func RunRepoBootstrap(ctx context.Context, opts *RepoBootstrapOptions) error {

log.G(ctx).Infof("running argocd login to initialize argocd config")
err = argocdLogin(&argocd.LoginOptions{
Namespace: opts.Namespace,
Username: "admin",
Password: passwd,
Namespace: opts.Namespace,
Username: "admin",
Password: passwd,
KubeConfig: opts.KubeConfig,
})
if err != nil {
return err
Expand Down
19 changes: 14 additions & 5 deletions pkg/argocd/argocd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package argocd

import (
"context"
"os"

"github.com/argoproj-labs/argocd-autopilot/pkg/kube"
"github.com/argoproj-labs/argocd-autopilot/pkg/log"
Expand Down Expand Up @@ -31,9 +32,10 @@ type (
}

LoginOptions struct {
Namespace string
Username string
Password string
Namespace string
Username string
Password string
KubeConfig string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about kube context?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed most kube flags (except for timeout, kubeconfig and namespace).

}
)

Expand Down Expand Up @@ -103,13 +105,20 @@ func Login(opts *LoginOptions) error {
"--port-forward",
"--port-forward-namespace",
opts.Namespace,
"--password",
opts.Password,
"--username",
opts.Username,
"--password",
opts.Password,
"--name",
"autopilot",
}
if opts.KubeConfig != "" {
origKubeConfig := os.Getenv("KUBECONFIG")
defer func() { os.Setenv("KUBECONFIG", origKubeConfig) }()
if err := os.Setenv("KUBECONFIG", opts.KubeConfig); err != nil {
return err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return a wrapped error here: failed to set KUBECONFIG env var, cause I'm not sure the error returned here would be clear

}
}

root.SetArgs(args)
return root.Execute()
Expand Down