Skip to content

Commit 367e9e4

Browse files
author
gentele
committed
fix #233
1 parent 0fda603 commit 367e9e4

4 files changed

Lines changed: 35 additions & 76 deletions

File tree

Gopkg.lock

Lines changed: 19 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/devspace/clients/kubectl/client.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@ import (
77
"io"
88
"net/http"
99
"os"
10+
"path/filepath"
1011
"sync"
1112

1213
"github.com/covexo/devspace/pkg/devspace/config/configutil"
14+
"github.com/covexo/devspace/pkg/util/fsutil"
1315
"github.com/covexo/devspace/pkg/util/log"
1416
dockerterm "github.com/docker/docker/pkg/term"
1517
k8sv1 "k8s.io/api/core/v1"
1618
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1719
"k8s.io/client-go/kubernetes"
20+
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
1821
"k8s.io/client-go/rest"
1922
"k8s.io/client-go/tools/clientcmd"
2023
"k8s.io/client-go/tools/portforward"
@@ -210,15 +213,19 @@ func GetClientConfig() (*rest.Config, error) {
210213
return nil, errors.New("Couldn't load cluster config, did you run devspace init")
211214
}
212215

213-
return &rest.Config{
214-
Host: *config.Cluster.APIServer,
215-
Username: *config.Cluster.User.Username,
216-
TLSClientConfig: rest.TLSClientConfig{
217-
CAData: []byte(*config.Cluster.CaCert),
218-
CertData: []byte(*config.Cluster.User.ClientCert),
219-
KeyData: []byte(*config.Cluster.User.ClientKey),
220-
},
221-
}, nil
216+
if (config.Cluster.UseKubeConfig != nil && *config.Cluster.UseKubeConfig) || config.Cluster.APIServer == nil {
217+
return clientcmd.BuildConfigFromFlags("", filepath.Join(fsutil.GetHomeDir(), ".kube", "config"))
218+
} else {
219+
return &rest.Config{
220+
Host: *config.Cluster.APIServer,
221+
Username: *config.Cluster.User.Username,
222+
TLSClientConfig: rest.TLSClientConfig{
223+
CAData: []byte(*config.Cluster.CaCert),
224+
CertData: []byte(*config.Cluster.User.ClientCert),
225+
KeyData: []byte(*config.Cluster.User.ClientKey),
226+
},
227+
}, nil
228+
}
222229
}
223230

224231
// ForwardPorts forwards the specified ports from the cluster to the local machine

pkg/devspace/config/configutil/get.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,6 @@ func GetConfig(reload bool) *v1.Config {
6262
merge(config, configRaw, unsafe.Pointer(&config), unsafe.Pointer(configRaw))
6363
merge(config, overwriteConfig, unsafe.Pointer(&config), unsafe.Pointer(overwriteConfig))
6464
}
65-
66-
if (config.Cluster.UseKubeConfig != nil && *config.Cluster.UseKubeConfig) || config.Cluster.APIServer == nil {
67-
loadClusterConfig(config.Cluster, false)
68-
}
6965
return config
7066
}
7167

pkg/devspace/config/configutil/load.go

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@ package configutil
22

33
import (
44
"io/ioutil"
5-
"path/filepath"
65

76
"github.com/covexo/devspace/pkg/devspace/config/v1"
8-
"github.com/covexo/devspace/pkg/util/fsutil"
97
yaml "gopkg.in/yaml.v2"
10-
"k8s.io/client-go/tools/clientcmd"
118
)
129

1310
func loadConfig(config *v1.Config, path string) error {
@@ -18,60 +15,3 @@ func loadConfig(config *v1.Config, path string) error {
1815
}
1916
return yaml.Unmarshal(yamlFileContent, config)
2017
}
21-
22-
//LoadClusterConfig loads the config for a kubernetes cluster
23-
func loadClusterConfig(config *v1.Cluster, overwriteExistingValues bool) {
24-
kubeconfig, kubeconfigErr := clientcmd.BuildConfigFromFlags("", filepath.Join(fsutil.GetHomeDir(), ".kube", "config"))
25-
26-
if kubeconfigErr == nil {
27-
if config.APIServer == nil {
28-
if len(kubeconfig.Host) != 0 {
29-
config.APIServer = String(kubeconfig.Host)
30-
}
31-
}
32-
33-
if config.CaCert == nil {
34-
if len(kubeconfig.TLSClientConfig.CAData) == 0 {
35-
caData, caFileErr := fsutil.ReadFile(kubeconfig.TLSClientConfig.CAFile, 0)
36-
37-
if caFileErr == nil {
38-
config.CaCert = String(string(caData))
39-
}
40-
} else {
41-
config.CaCert = String(string(kubeconfig.CAData))
42-
}
43-
}
44-
45-
if config.User == nil {
46-
config.User = &v1.ClusterUser{}
47-
}
48-
49-
if config.User.Username == nil {
50-
config.User.Username = String(kubeconfig.Username)
51-
}
52-
53-
if config.User.ClientCert == nil {
54-
if len(kubeconfig.TLSClientConfig.CertData) == 0 {
55-
certData, certFileErr := fsutil.ReadFile(kubeconfig.TLSClientConfig.CertFile, 0)
56-
57-
if certFileErr == nil {
58-
config.User.ClientCert = String(string(certData))
59-
}
60-
} else {
61-
config.User.ClientCert = String(string(kubeconfig.TLSClientConfig.CertData))
62-
}
63-
}
64-
65-
if config.User.ClientKey == nil {
66-
if len(kubeconfig.TLSClientConfig.KeyData) == 0 {
67-
keyData, keyFileErr := fsutil.ReadFile(kubeconfig.TLSClientConfig.KeyFile, 0)
68-
69-
if keyFileErr == nil {
70-
config.User.ClientKey = String(string(keyData))
71-
}
72-
} else {
73-
config.User.ClientKey = String(string(kubeconfig.TLSClientConfig.KeyData))
74-
}
75-
}
76-
}
77-
}

0 commit comments

Comments
 (0)