Skip to content

Commit

Permalink
Merge pull request #7006 from justinsb/fix_kops_cli_with_crd
Browse files Browse the repository at this point in the history
Support using kops CLI with CRDs
  • Loading branch information
k8s-ci-robot authored May 16, 2019
2 parents 4ca73f8 + 71ff24b commit 8a49508
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cmd/kops/util/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ go_library(
"//pkg/client/simple/vfsclientset:go_default_library",
"//util/pkg/vfs:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
"//vendor/k8s.io/client-go/rest:go_default_library",
"//vendor/k8s.io/client-go/tools/clientcmd:go_default_library",
"//vendor/k8s.io/klog:go_default_library",
],
)
26 changes: 15 additions & 11 deletions cmd/kops/util/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"strings"

"k8s.io/apimachinery/pkg/util/validation/field"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/klog"
gceacls "k8s.io/kops/pkg/acls/gce"
s3acls "k8s.io/kops/pkg/acls/s3"
Expand Down Expand Up @@ -73,19 +73,24 @@ func (f *Factory) Clientset() (simple.Clientset, error) {
// We recognize a `k8s` scheme; this might change in future so we won't document it yet
// In practice nobody is going to hit this accidentally, so I don't think we need a feature flag.
if strings.HasPrefix(registryPath, "k8s://") {
u, err := url.Parse(registryPath)
if err != nil {
return nil, fmt.Errorf("Invalid kops server url: %q", registryPath)
}
loadingRules := clientcmd.NewDefaultClientConfigLoadingRules()

u.Scheme = "https"
configOverrides := &clientcmd.ConfigOverrides{}

config := &rest.Config{
Host: u.Scheme + "://" + u.Host,
if registryPath == "k8s://" {
} else {
u, err := url.Parse(registryPath)
if err != nil {
return nil, fmt.Errorf("Invalid kops server url: %q", registryPath)
}
configOverrides.CurrentContext = u.Host
}

klog.Warning("Using insecure TLS")
config.Insecure = true
kubeConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, configOverrides)
config, err := kubeConfig.ClientConfig()
if err != nil {
return nil, fmt.Errorf("error loading kubeconfig for %q", registryPath)
}

kopsClient, err := kopsclient.NewForConfig(config)
if err != nil {
Expand All @@ -95,7 +100,6 @@ func (f *Factory) Clientset() (simple.Clientset, error) {
f.clientset = &api.RESTClientset{
BaseURL: &url.URL{
Scheme: "k8s",
Host: u.Host,
},
KopsClient: kopsClient.Kops(),
}
Expand Down

0 comments on commit 8a49508

Please sign in to comment.