Skip to content

Commit

Permalink
fix: maybe use --all-namespace and -n
Browse files Browse the repository at this point in the history
  • Loading branch information
ndj888 committed Sep 12, 2021
1 parent 2140039 commit c2f927d
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions cmd/kubefwd/services/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,15 @@ var Cmd = &cobra.Command{
Run: runCmd,
}

// SetAllNamespace Form V1Core get all namespace
func SetAllNamespace(clientSet *kubernetes.Clientset, options metav1.ListOptions, namespaces *[]string) *[]string {
// setAllNamespace Form V1Core get all namespace
func setAllNamespace(clientSet *kubernetes.Clientset, options metav1.ListOptions, namespaces *[]string) {
nsList, err := clientSet.CoreV1().Namespaces().List(context.TODO(), options)
if err != nil {
log.Fatalf("Error get all namespaces by CoreV1: %s\n", err.Error())
}
for _, ns := range nsList.Items {
*namespaces = append(*namespaces, ns.Name)
}
return namespaces
}

// checkConnection tests if you can connect to the cluster in your config,
Expand Down Expand Up @@ -275,7 +274,10 @@ Try:

// if use --all-namespace ,from v1 api get all ns.
if isAllNs {
SetAllNamespace(clientSet, listOptions, &namespaces)
if len(namespaces) >= 1 {
log.Fatalf("Error --all-namespace not use -n.")
}
setAllNamespace(clientSet, listOptions, &namespaces)
}

// check connectivity
Expand Down

0 comments on commit c2f927d

Please sign in to comment.