mirror of https://github.com/k3s-io/k3s
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 ```pull/8/head
commit
90c09c75d6
|
@ -100,6 +100,26 @@ func NewInteractiveClientConfig(config clientcmdapi.Config, contextName string,
|
|||
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) {
|
||||
return config.config, nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue