diff --git a/package.json b/package.json index bf65a4e9..f66b67e0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "venona", - "version": "0.12.1", + "version": "0.13.0", "description": "Codefresh agent to run on Codefresh's runtime environment and execute pipeline", "main": "index.js", "scripts": { diff --git a/venonactl/cmd/install.go b/venonactl/cmd/install.go index 44f0fb03..44576c2c 100644 --- a/venonactl/cmd/install.go +++ b/venonactl/cmd/install.go @@ -41,6 +41,7 @@ var ( kubeNamespace string kubeContextName string + inCluster bool ) // installCmd represents the install command @@ -60,6 +61,9 @@ var installCmd = &cobra.Command{ if kubeNamespace == "" { kubeNamespace = "default" } + + s.KubernetesAPI.InCluster = inCluster + s.KubernetesAPI.ContextName = kubeContextName s.KubernetesAPI.Namespace = kubeNamespace @@ -113,6 +117,7 @@ func init() { installCmd.Flags().StringVar(&kubeNamespace, "kube-namespace", viper.GetString("kube-namespace"), "Name of the namespace on which venona should be installed [$KUBE_NAMESPACE]") installCmd.Flags().StringVar(&kubeContextName, "kube-context-name", viper.GetString("kube-context"), "Name of the kubernetes context on which venona should be installed (default is current-context) [$KUBE_CONTEXT]") installCmd.Flags().BoolVar(&setDefaultRuntime, "set-default", false, "Mark the install runtime-environment as default one after installation") + installCmd.Flags().BoolVar(&inCluster, "in-cluster", false, "Set flag if venona is been installed from inside a cluster") } func installRuntimeEnvironment() { diff --git a/venonactl/cmd/root.go b/venonactl/cmd/root.go index e6c3c3c1..2282f7b2 100644 --- a/venonactl/cmd/root.go +++ b/venonactl/cmd/root.go @@ -134,10 +134,12 @@ var rootCmd = &cobra.Command{ if kubeConfigPath == "" { currentUser, _ := user.Current() - kubeConfigPath = path.Join(currentUser.HomeDir, ".kube", "config") - logrus.WithFields(logrus.Fields{ - "Kube-Config-Path": kubeConfigPath, - }).Debug("Path to kubeconfig not set, using default") + if currentUser != nil { + kubeConfigPath = path.Join(currentUser.HomeDir, ".kube", "config") + logrus.WithFields(logrus.Fields{ + "Kube-Config-Path": kubeConfigPath, + }).Debug("Path to kubeconfig not set, using default") + } } s.AppName = store.ApplicationName diff --git a/venonactl/pkg/operators/helper.go b/venonactl/pkg/operators/helper.go index 502b6719..9ea7ee4a 100644 --- a/venonactl/pkg/operators/helper.go +++ b/venonactl/pkg/operators/helper.go @@ -122,11 +122,17 @@ func NewKubeRESTClientConfig(s *store.Values) (*rest.Config, error) { // NewKubeClientset - returns clientset func NewKubeClientset(s *store.Values) (*kubernetes.Clientset, error) { - kubeClientConfig, err := NewKubeRESTClientConfig(s) + var config *rest.Config + var err error + if s.KubernetesAPI.InCluster { + config, err = rest.InClusterConfig() + } else { + config, err = NewKubeRESTClientConfig(s) + } if err != nil { return nil, err } - return kubernetes.NewForConfig(kubeClientConfig) + return kubernetes.NewForConfig(config) } func getKubeObjectsFromTempalte(values map[string]interface{}) (map[string]runtime.Object, error) { diff --git a/venonactl/pkg/store/store.go b/venonactl/pkg/store/store.go index b6fc226e..ab1350c9 100644 --- a/venonactl/pkg/store/store.go +++ b/venonactl/pkg/store/store.go @@ -43,6 +43,7 @@ type ( ConfigPath string Namespace string ContextName string + InCluster bool } CodefreshAPI struct {