Skip to content
This repository has been archived by the owner on Jul 25, 2022. It is now read-only.

Commit

Permalink
set namespace to default while dropping an namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
neo-liang-sap committed Mar 16, 2020
1 parent c86ab58 commit 4892f69
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pkg/cmd/drop.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package cmd
import (
"errors"
"fmt"
"strings"

"github.com/spf13/cobra"
)
Expand All @@ -40,6 +41,20 @@ func NewDropCmd(targetReader TargetReader, targetWriter TargetWriter, ioStreams

fmt.Fprintf(ioStreams.Out, "Dropped %s %s\n", target.Stack()[stackLength-1].Kind, target.Stack()[stackLength-1].Name)

if target.Stack()[stackLength-1].Kind == "namespace" {
cfg := getKubeConfigOfCurrentTarget()
out, err := ExecCmdReturnOutput("bash", "-c", "export KUBECONFIG="+cfg+"; kubectl config current-context")
if err != nil {
fmt.Println(err)
}
currentConext := strings.TrimSuffix(string(out), "\n")
_, err = ExecCmdReturnOutput("bash", "-c", "export KUBECONFIG="+cfg+"; kubectl config set-context "+currentConext+" --namespace=default")
if err != nil {
fmt.Println(err)
}

}

target.SetStack(target.Stack()[:stackLength-1])
if err := targetWriter.WriteTarget(pathTarget, target); err != nil {
return err
Expand Down

0 comments on commit 4892f69

Please sign in to comment.