Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
sunny0826 committed Jan 19, 2020
1 parent bb05abf commit 41892fb
Show file tree
Hide file tree
Showing 6 changed files with 357 additions and 9 deletions.
10 changes: 6 additions & 4 deletions cmd/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,10 @@ func getAddConfig(kubeconfig string) (*clientcmdapi.Config, error) {
log.Fatal("Only support add 1 context.")
}

name := getName()
name := getName(kubeconfig)
err = nameCheck(name)
if err != nil {
Error.Println(err)
os.Exit(-1)
log.Fatal(err)
}
suffix := HashSuf(config)
username := fmt.Sprintf("user-%v", suffix)
Expand Down Expand Up @@ -151,7 +150,10 @@ func fileExists(path string) bool {
return true
}

func getName() string {
func getName(kubeconfig string) string {
if file == ""{
return kubeconfig
}
if name == "" {
n := strings.Split(file, "/")
result := strings.Split(n[len(n)-1], ".")
Expand Down
4 changes: 2 additions & 2 deletions cmd/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"k8s.io/client-go/tools/clientcmd"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
clientcmdlatest "k8s.io/client-go/tools/clientcmd/api/latest"
"log"
"os"
"sigs.k8s.io/yaml"
"strings"
Expand Down Expand Up @@ -60,8 +61,7 @@ func (mc MergeCommand) runMerge(command *cobra.Command, args []string) error {
for _, yaml := range files {
config, err := LoadClientConfig(yaml)
if err != nil {
fmt.Println(err)
os.Exit(-1)
log.Fatal(err)
}
name := nameHandle(yaml)
commandLineFile, _ := ioutil.TempFile("", "")
Expand Down
2 changes: 1 addition & 1 deletion cmd/rename.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (rc *RenameCommand) runRename(command *cobra.Command, args []string) error
rename := PromptUI("Rename", kubeName)
if rename != kubeName {
if _, ok := config.Contexts[rename]; ok {
log.Fatal("Name: %s already exists", rename)
log.Fatalf("Name: %s already exists", rename)
} else {
if obj, ok := config.Contexts[kubeName]; ok {
config.Contexts[rename] = obj
Expand Down
2 changes: 1 addition & 1 deletion cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func ModifyKubeConfig(config *clientcmdapi.Config) error {
pathOptions := clientcmd.NewDefaultPathOptions()

if err := clientcmd.ModifyConfig(pathOptions, *config, true); err != nil {
log.Println("Unexpected error: %v", err)
log.Printf("Unexpected error: %v", err)
return err
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/sunny0826/kubecm

go 1.12
go 1.13

require (
github.com/bndr/gotabulate v1.1.2
Expand Down
Loading

0 comments on commit 41892fb

Please sign in to comment.