From 1fb15a03d5382546a7c9e6d13a6fe02f3f5554fe Mon Sep 17 00:00:00 2001 From: christoph Date: Fri, 13 Sep 2024 08:48:33 +0200 Subject: [PATCH] feat(cli): namespace creation on install Signed-off-by: christoph --- cmd/glasskube/cmd/install.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/cmd/glasskube/cmd/install.go b/cmd/glasskube/cmd/install.go index b6bfd3923..277fb3ca5 100644 --- a/cmd/glasskube/cmd/install.go +++ b/cmd/glasskube/cmd/install.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + apierrors "k8s.io/apimachinery/pkg/api/errors" "os" "strings" @@ -221,15 +222,12 @@ var installCmd = &cobra.Command{ fmt.Fprintln(os.Stderr, " * Automatic updates will be", bold("not enabled")) } + createNamespace := false if installCmdOptions.NamespaceOptions.Namespace != "" { if ok, err := namespaces.IsNamespaceInstalled(ctx, cs, installCmdOptions.NamespaceOptions.Namespace); !ok { fmt.Printf(" * Namespace %v does not exist and will be created\n", installCmdOptions.NamespaceOptions.Namespace) - err := namespaces.InstallNamespace(ctx, cs, installCmdOptions.NamespaceOptions.Namespace) - if err != nil { - fmt.Fprintf(os.Stderr, "An error occurred in creating the Namespace:\n\n%v\n", err) - cliutils.ExitWithError() - } + createNamespace = true } else if err != nil { fmt.Fprintf(os.Stderr, "An error occurred in the Namespace check:\n\n%v\n", err) cliutils.ExitWithError() @@ -248,6 +246,13 @@ var installCmd = &cobra.Command{ cancel() } + if createNamespace { + err := namespaces.InstallNamespace(ctx, cs, installCmdOptions.NamespaceOptions.Namespace) + if err != nil && !apierrors.IsAlreadyExists(err) { + fmt.Fprintf(os.Stderr, "An error occurred in creating the Namespace:\n\n%v\n", err) + cliutils.ExitWithError() + } + } if installCmdOptions.NoWait { if err := installer.Install(ctx, pkg, opts); err != nil { fmt.Fprintf(os.Stderr, "An error occurred during installation:\n\n%v\n", err)