Skip to content

feat: Add create-namespace flag to vcluster platform add cluster command #2672

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
10 changes: 8 additions & 2 deletions cmd/vclusterctl/cmd/platform/add/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type ClusterCmd struct {
Log log.Logger
*flags.GlobalFlags
Namespace string
CreateNamespace bool
ServiceAccount string
DisplayName string
Context string
Expand Down Expand Up @@ -82,6 +83,7 @@ vcluster platform add cluster my-cluster
}

c.Flags().StringVar(&cmd.Namespace, "namespace", clihelper.DefaultPlatformNamespace, "The namespace to generate the service account in. The namespace will be created if it does not exist")
c.Flags().BoolVar(&cmd.CreateNamespace, "create-namespace", true, "If true the namespace will be created if it does not exist")
c.Flags().StringVar(&cmd.ServiceAccount, "service-account", "loft-admin", "The service account name to create")
c.Flags().StringVar(&cmd.DisplayName, "display-name", "", "The display name to show in the UI for this cluster")
c.Flags().BoolVar(&cmd.Wait, "wait", false, "If true, will wait until the cluster is initialized")
Expand Down Expand Up @@ -170,8 +172,8 @@ func (cmd *ClusterCmd) Run(ctx context.Context, args []string) error {
if os.Getenv("DEVELOPMENT") == "true" {
helmArgs = []string{
"upgrade", "--install", "loft", cmp.Or(os.Getenv("DEVELOPMENT_CHART_DIR"), "./chart"),
"--create-namespace",
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually this one needs to stay, because we are overwriting helmArgs here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I'm done, why os.Getenv("DEVELOPMENT") == "true" needs to be forced to pass --create-namespace?

Copy link
Contributor

Choose a reason for hiding this comment

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

It doesn't need to be forced, but how the code was before the helmArgs isn't used inside DEV conditional, meaning you could not have turned it on. You can make it optional in this block, but needs to use the flags.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, how about I add a --dev-create-namespace flag?

"--namespace", namespace,
"--create-namespace",
"--set", "agentOnly=true",
"--set", "image=" + cmp.Or(os.Getenv("DEVELOPMENT_IMAGE"), "ghcr.io/loft-sh/enterprise:release-test"),
"--set", "env.AGENT_IMAGE=" + cmp.Or(os.Getenv("AGENT_IMAGE"), os.Getenv("DEVELOPMENT_IMAGE"), "ghcr.io/loft-sh/enterprise:release-test"),
Expand All @@ -191,8 +193,12 @@ func (cmd *ClusterCmd) Run(ctx context.Context, args []string) error {
helmArgs = append(helmArgs, "--version", cmd.HelmChartVersion)
}

if cmd.CreateNamespace {
helmArgs = append(helmArgs, "--create-namespace")
}

// general arguments
helmArgs = append(helmArgs, "--install", "--create-namespace", "--namespace", cmd.Namespace, "--set", "agentOnly=true")
helmArgs = append(helmArgs, "--install", "--namespace", cmd.Namespace, "--set", "agentOnly=true")
}

for _, set := range cmd.HelmSet {
Expand Down