mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-06 10:43:56 +00:00
Merge pull request #4659 from deads2k/deads-tolerate-empty-file
tolerate empty .kubeconfig files
This commit is contained in:
commit
eb343d2768
@ -183,7 +183,12 @@ func LoadFromFile(filename string) (*clientcmdapi.Config, error) {
|
|||||||
// Load takes a byte slice and deserializes the contents into Config object.
|
// Load takes a byte slice and deserializes the contents into Config object.
|
||||||
// Encapsulates deserialization without assuming the source is a file.
|
// Encapsulates deserialization without assuming the source is a file.
|
||||||
func Load(data []byte) (*clientcmdapi.Config, error) {
|
func Load(data []byte) (*clientcmdapi.Config, error) {
|
||||||
config := &clientcmdapi.Config{}
|
config := clientcmdapi.NewConfig()
|
||||||
|
// if there's no data in a file, return the default object instead of failing (DecodeInto reject empty input)
|
||||||
|
if len(data) == 0 {
|
||||||
|
return config, nil
|
||||||
|
}
|
||||||
|
|
||||||
if err := clientcmdlatest.Codec.DecodeInto(data, config); err != nil {
|
if err := clientcmdlatest.Codec.DecodeInto(data, config); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user