Skip to content

Commit

Permalink
(fix): create namespace using kubeconfig (#507)
Browse files Browse the repository at this point in the history
  • Loading branch information
abhijith-darshan authored Aug 30, 2024
1 parent c786624 commit 59d933d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
7 changes: 4 additions & 3 deletions pkg/internal/local/klient/kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,17 @@ func getKindClusters() ([]string, error) {
}

// CreateNamespace - creates a namespace with the given name
func CreateNamespace(namespaceName string) error {
func CreateNamespace(namespaceName, kubeconfig string) error {
if strings.TrimSpace(namespaceName) == "" {
return errors.New("namespace name cannot be empty")
}
return utils.ShellPipe{
Shells: []utils.Shell{
{
Cmd: "kubectl create namespace ${namespace} --dry-run=client -o yaml",
Cmd: "kubectl create namespace ${namespace} --kubeconfig=${kubeconfig} --dry-run=client -o yaml",
Vars: map[string]string{
"namespace": namespaceName,
"namespace": namespaceName,
"kubeconfig": kubeconfig,
},
},
{
Expand Down
17 changes: 11 additions & 6 deletions pkg/internal/local/setup/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@ func clusterSetup(env *ExecutionEnv) error {
if err != nil {
return err
}
if env.cluster.Namespace != nil {
err = klient.CreateNamespace(*env.cluster.Namespace)
if err != nil {
return err
}
err = env.cluster.saveConfig() // save kubeconfig after cluster creation
if err != nil {
return err
}
err = env.cluster.saveConfig()
err = env.cluster.createNamespace() // create namespace if specified using kubeconfig
if err != nil {
return err
}
Expand Down Expand Up @@ -64,3 +62,10 @@ func (c *Cluster) saveConfig() error {
c.kubeConfigPath = filepath.Join(dir, file)
return nil
}

func (c *Cluster) createNamespace() error {
if c.Namespace == nil {
return nil
}
return klient.CreateNamespace(*c.Namespace, c.kubeConfigPath)
}

0 comments on commit 59d933d

Please sign in to comment.