Skip to content

Commit

Permalink
allow passing flag --in-cluster to get build the kube client based on…
Browse files Browse the repository at this point in the history
… in pod config (#20)
  • Loading branch information
Oleg Sucharevich authored Feb 12, 2019
1 parent ea5e0b6 commit de11810
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
5 changes: 5 additions & 0 deletions venonactl/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var (

kubeNamespace string
kubeContextName string
inCluster bool
)

// installCmd represents the install command
Expand All @@ -60,6 +61,9 @@ var installCmd = &cobra.Command{
if kubeNamespace == "" {
kubeNamespace = "default"
}

s.KubernetesAPI.InCluster = inCluster

s.KubernetesAPI.ContextName = kubeContextName
s.KubernetesAPI.Namespace = kubeNamespace

Expand Down Expand Up @@ -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() {
Expand Down
10 changes: 6 additions & 4 deletions venonactl/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions venonactl/pkg/operators/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions venonactl/pkg/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type (
ConfigPath string
Namespace string
ContextName string
InCluster bool
}

CodefreshAPI struct {
Expand Down

0 comments on commit de11810

Please sign in to comment.