Merge pull request #61287 from deads2k/client-03-clientconfig

Automatic merge from submit-queue (batch tested with PRs 61644, 61624, 61743, 61019, 61287). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

provide easy methods for direct kubeconfig loading from bytes

Adds a `RESTConfigFromKubeConfig([]byte)` method for taking a kubeconfig and getting back the rest.Config.  There are ways to do this now, but it takes a fair amount of wiring that is a pain.

As kube starts dropping `--master` flags from its commands, it will be able to use this.  For current consumers, this will be a big simplification.

```release-note
NONE
```

Kubernetes-commit: 90c09c75d67831ad46cc0c9abb954b6936ca86b3
This commit is contained in:
Kubernetes Publisher 2018-03-27 06:41:23 -07:00
commit d74b6802c2
2 changed files with 73 additions and 53 deletions

106
Godeps/Godeps.json generated
View File

@ -364,215 +364,215 @@
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/api/equality", "ImportPath": "k8s.io/apimachinery/pkg/api/equality",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/api/errors", "ImportPath": "k8s.io/apimachinery/pkg/api/errors",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/api/meta", "ImportPath": "k8s.io/apimachinery/pkg/api/meta",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/api/resource", "ImportPath": "k8s.io/apimachinery/pkg/api/resource",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/api/testing", "ImportPath": "k8s.io/apimachinery/pkg/api/testing",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/api/testing/fuzzer", "ImportPath": "k8s.io/apimachinery/pkg/api/testing/fuzzer",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/api/testing/roundtrip", "ImportPath": "k8s.io/apimachinery/pkg/api/testing/roundtrip",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/apimachinery", "ImportPath": "k8s.io/apimachinery/pkg/apimachinery",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/apimachinery/announced", "ImportPath": "k8s.io/apimachinery/pkg/apimachinery/announced",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/apimachinery/registered", "ImportPath": "k8s.io/apimachinery/pkg/apimachinery/registered",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/apis/meta/fuzzer", "ImportPath": "k8s.io/apimachinery/pkg/apis/meta/fuzzer",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/apis/meta/internalversion", "ImportPath": "k8s.io/apimachinery/pkg/apis/meta/internalversion",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/apis/meta/v1", "ImportPath": "k8s.io/apimachinery/pkg/apis/meta/v1",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured", "ImportPath": "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/apis/meta/v1beta1", "ImportPath": "k8s.io/apimachinery/pkg/apis/meta/v1beta1",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/conversion", "ImportPath": "k8s.io/apimachinery/pkg/conversion",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/conversion/queryparams", "ImportPath": "k8s.io/apimachinery/pkg/conversion/queryparams",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/fields", "ImportPath": "k8s.io/apimachinery/pkg/fields",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/labels", "ImportPath": "k8s.io/apimachinery/pkg/labels",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/runtime", "ImportPath": "k8s.io/apimachinery/pkg/runtime",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/runtime/schema", "ImportPath": "k8s.io/apimachinery/pkg/runtime/schema",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer", "ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/json", "ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/json",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/protobuf", "ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/protobuf",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/recognizer", "ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/recognizer",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/streaming", "ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/streaming",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/versioning", "ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/versioning",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/selection", "ImportPath": "k8s.io/apimachinery/pkg/selection",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/types", "ImportPath": "k8s.io/apimachinery/pkg/types",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/cache", "ImportPath": "k8s.io/apimachinery/pkg/util/cache",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/clock", "ImportPath": "k8s.io/apimachinery/pkg/util/clock",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/diff", "ImportPath": "k8s.io/apimachinery/pkg/util/diff",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/errors", "ImportPath": "k8s.io/apimachinery/pkg/util/errors",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/framer", "ImportPath": "k8s.io/apimachinery/pkg/util/framer",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/httpstream", "ImportPath": "k8s.io/apimachinery/pkg/util/httpstream",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/httpstream/spdy", "ImportPath": "k8s.io/apimachinery/pkg/util/httpstream/spdy",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/intstr", "ImportPath": "k8s.io/apimachinery/pkg/util/intstr",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/json", "ImportPath": "k8s.io/apimachinery/pkg/util/json",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/mergepatch", "ImportPath": "k8s.io/apimachinery/pkg/util/mergepatch",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/net", "ImportPath": "k8s.io/apimachinery/pkg/util/net",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/remotecommand", "ImportPath": "k8s.io/apimachinery/pkg/util/remotecommand",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/runtime", "ImportPath": "k8s.io/apimachinery/pkg/util/runtime",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/sets", "ImportPath": "k8s.io/apimachinery/pkg/util/sets",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/strategicpatch", "ImportPath": "k8s.io/apimachinery/pkg/util/strategicpatch",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/validation", "ImportPath": "k8s.io/apimachinery/pkg/util/validation",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/validation/field", "ImportPath": "k8s.io/apimachinery/pkg/util/validation/field",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/wait", "ImportPath": "k8s.io/apimachinery/pkg/util/wait",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/yaml", "ImportPath": "k8s.io/apimachinery/pkg/util/yaml",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/version", "ImportPath": "k8s.io/apimachinery/pkg/version",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/watch", "ImportPath": "k8s.io/apimachinery/pkg/watch",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/third_party/forked/golang/json", "ImportPath": "k8s.io/apimachinery/third_party/forked/golang/json",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/third_party/forked/golang/netutil", "ImportPath": "k8s.io/apimachinery/third_party/forked/golang/netutil",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/third_party/forked/golang/reflect", "ImportPath": "k8s.io/apimachinery/third_party/forked/golang/reflect",
"Rev": "7175867f4d9f782220ceae4fc323e3aaae35f23a" "Rev": "210bcde8e5a7715fe776460ca1df1a3f2738725e"
}, },
{ {
"ImportPath": "k8s.io/kube-openapi/pkg/util/proto", "ImportPath": "k8s.io/kube-openapi/pkg/util/proto",

View File

@ -100,6 +100,26 @@ func NewInteractiveClientConfig(config clientcmdapi.Config, contextName string,
return &DirectClientConfig{config, contextName, overrides, fallbackReader, configAccess, promptedCredentials{}} return &DirectClientConfig{config, contextName, overrides, fallbackReader, configAccess, promptedCredentials{}}
} }
// NewClientConfigFromBytes takes your kubeconfig and gives you back a ClientConfig
func NewClientConfigFromBytes(configBytes []byte) (ClientConfig, error) {
config, err := Load(configBytes)
if err != nil {
return nil, err
}
return &DirectClientConfig{*config, "", &ConfigOverrides{}, nil, nil, promptedCredentials{}}, nil
}
// RESTConfigFromKubeConfig is a convenience method to give back a restconfig from your kubeconfig bytes.
// For programmatic access, this is what you want 80% of the time
func RESTConfigFromKubeConfig(configBytes []byte) (*restclient.Config, error) {
clientConfig, err := NewClientConfigFromBytes(configBytes)
if err != nil {
return nil, err
}
return clientConfig.ClientConfig()
}
func (config *DirectClientConfig) RawConfig() (clientcmdapi.Config, error) { func (config *DirectClientConfig) RawConfig() (clientcmdapi.Config, error) {
return config.config, nil return config.config, nil
} }