Skip to content

Commit de11810

Browse files
author
Oleg Sucharevich
authored
allow passing flag --in-cluster to get build the kube client based on in pod config (#20)
1 parent ea5e0b6 commit de11810

File tree

5 files changed

+21
-7
lines changed

5 files changed

+21
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "venona",
3-
"version": "0.12.1",
3+
"version": "0.13.0",
44
"description": "Codefresh agent to run on Codefresh's runtime environment and execute pipeline",
55
"main": "index.js",
66
"scripts": {

venonactl/cmd/install.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ var (
4141

4242
kubeNamespace string
4343
kubeContextName string
44+
inCluster bool
4445
)
4546

4647
// installCmd represents the install command
@@ -60,6 +61,9 @@ var installCmd = &cobra.Command{
6061
if kubeNamespace == "" {
6162
kubeNamespace = "default"
6263
}
64+
65+
s.KubernetesAPI.InCluster = inCluster
66+
6367
s.KubernetesAPI.ContextName = kubeContextName
6468
s.KubernetesAPI.Namespace = kubeNamespace
6569

@@ -113,6 +117,7 @@ func init() {
113117
installCmd.Flags().StringVar(&kubeNamespace, "kube-namespace", viper.GetString("kube-namespace"), "Name of the namespace on which venona should be installed [$KUBE_NAMESPACE]")
114118
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]")
115119
installCmd.Flags().BoolVar(&setDefaultRuntime, "set-default", false, "Mark the install runtime-environment as default one after installation")
120+
installCmd.Flags().BoolVar(&inCluster, "in-cluster", false, "Set flag if venona is been installed from inside a cluster")
116121
}
117122

118123
func installRuntimeEnvironment() {

venonactl/cmd/root.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,12 @@ var rootCmd = &cobra.Command{
134134

135135
if kubeConfigPath == "" {
136136
currentUser, _ := user.Current()
137-
kubeConfigPath = path.Join(currentUser.HomeDir, ".kube", "config")
138-
logrus.WithFields(logrus.Fields{
139-
"Kube-Config-Path": kubeConfigPath,
140-
}).Debug("Path to kubeconfig not set, using default")
137+
if currentUser != nil {
138+
kubeConfigPath = path.Join(currentUser.HomeDir, ".kube", "config")
139+
logrus.WithFields(logrus.Fields{
140+
"Kube-Config-Path": kubeConfigPath,
141+
}).Debug("Path to kubeconfig not set, using default")
142+
}
141143
}
142144

143145
s.AppName = store.ApplicationName

venonactl/pkg/operators/helper.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,17 @@ func NewKubeRESTClientConfig(s *store.Values) (*rest.Config, error) {
122122

123123
// NewKubeClientset - returns clientset
124124
func NewKubeClientset(s *store.Values) (*kubernetes.Clientset, error) {
125-
kubeClientConfig, err := NewKubeRESTClientConfig(s)
125+
var config *rest.Config
126+
var err error
127+
if s.KubernetesAPI.InCluster {
128+
config, err = rest.InClusterConfig()
129+
} else {
130+
config, err = NewKubeRESTClientConfig(s)
131+
}
126132
if err != nil {
127133
return nil, err
128134
}
129-
return kubernetes.NewForConfig(kubeClientConfig)
135+
return kubernetes.NewForConfig(config)
130136
}
131137

132138
func getKubeObjectsFromTempalte(values map[string]interface{}) (map[string]runtime.Object, error) {

venonactl/pkg/store/store.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ type (
4343
ConfigPath string
4444
Namespace string
4545
ContextName string
46+
InCluster bool
4647
}
4748

4849
CodefreshAPI struct {

0 commit comments

Comments
 (0)