diff --git a/fission/main.go b/fission/main.go index 4b22b98c..2f53539d 100644 --- a/fission/main.go +++ b/fission/main.go @@ -25,10 +25,6 @@ import ( func getFissionNamespace() string { fissionNamespace := os.Getenv("FISSION_NAMESPACE") - if len(fissionNamespace) == 0 { - // TODO make this smarter, perhaps based on helm releases - fissionNamespace = "fission" - } return fissionNamespace } @@ -37,6 +33,10 @@ func getKubeConfigPath() string { if len(kubeConfig) == 0 { home := os.Getenv("HOME") kubeConfig = filepath.Join(home, ".kube", "config") + + if _, err := os.Stat(kubeConfig); os.IsNotExist(err) { + fatal("Couldn't find kubeconfig file. Set the KUBECONFIG environment variable to your kubeconfig's path.") + } } return kubeConfig } diff --git a/fission/portforward.go b/fission/portforward.go index 94ff1aac..402fbf26 100644 --- a/fission/portforward.go +++ b/fission/portforward.go @@ -5,10 +5,10 @@ import ( "net" "os" "strconv" + "strings" "time" meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - // "k8s.io/client-go/rest" "k8s.io/client-go/kubernetes" "k8s.io/client-go/tools/clientcmd" "k8s.io/client-go/tools/portforward" @@ -52,13 +52,29 @@ func runPortForward(kubeConfig string, labelSelector string, localPort string, f fatal(fmt.Sprintf("Failed to connect to Kubernetes: %s", err)) } - // get the pod; if there is more than one, always port-forward to the first. + // if fission namespace is unset, try to find a fission pod in any namespace + if len(fissionNamespace) == 0 { + fissionNamespace = meta_v1.NamespaceAll + } + + // get the pod; if there is more than one, ask the user to disambiguate podList, err := clientset.CoreV1().Pods(fissionNamespace). List(meta_v1.ListOptions{LabelSelector: labelSelector}) if err != nil || len(podList.Items) == 0 { fatal("Error getting controller pod for port-forwarding") } + // make a useful error message if there is more than one install + if len(podList.Items) > 1 { + namespaces := make([]string, 0) + for _, p := range podList.Items { + namespaces = append(namespaces, p.Namespace) + } + fatal(fmt.Sprintf("Found %v fission installs, set FISSION_NAMESPACE to one of: %v", + len(podList.Items), strings.Join(namespaces, " "))) + } + + // pick the first pod podName := podList.Items[0].Name podNameSpace := podList.Items[0].Namespace