Skip to content

Commit

Permalink
feat(cli): namespace creation on install
Browse files Browse the repository at this point in the history
Signed-off-by: christoph <[email protected]>
  • Loading branch information
christophenne committed Sep 13, 2024
1 parent b13c5e3 commit 1fb15a0
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions cmd/glasskube/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"os"
"strings"

Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand Down

0 comments on commit 1fb15a0

Please sign in to comment.