MCPcopy
hub / github.com/kubernetes/client-go / LoadFromFile

Function LoadFromFile

tools/clientcmd/loader.go:350–386  ·  view source on GitHub ↗

LoadFromFile takes a filename and deserializes the contents into Config object

(filename string)

Source from the content-addressed store, hash-verified

348
349// LoadFromFile takes a filename and deserializes the contents into Config object
350func LoadFromFile(filename string) (*clientcmdapi.Config, error) {
351 kubeconfigBytes, err := ioutil.ReadFile(filename)
352 if err != nil {
353 return nil, err
354 }
355 config, err := Load(kubeconfigBytes)
356 if err != nil {
357 return nil, err
358 }
359 klog.V(6).Infoln("Config loaded from file: ", filename)
360
361 // set LocationOfOrigin on every Cluster, User, and Context
362 for key, obj := range config.AuthInfos {
363 obj.LocationOfOrigin = filename
364 config.AuthInfos[key] = obj
365 }
366 for key, obj := range config.Clusters {
367 obj.LocationOfOrigin = filename
368 config.Clusters[key] = obj
369 }
370 for key, obj := range config.Contexts {
371 obj.LocationOfOrigin = filename
372 config.Contexts[key] = obj
373 }
374
375 if config.AuthInfos == nil {
376 config.AuthInfos = map[string]*clientcmdapi.AuthInfo{}
377 }
378 if config.Clusters == nil {
379 config.Clusters = map[string]*clientcmdapi.Cluster{}
380 }
381 if config.Contexts == nil {
382 config.Contexts = map[string]*clientcmdapi.Context{}
383 }
384
385 return config, nil
386}
387
388// Load takes a byte slice and deserializes the contents into Config object.
389// Encapsulates deserialization without assuming the source is a file.

Callers 7

TestLoadingEmptyMapsFunction · 0.70
TestDuplicateClusterNameFunction · 0.70
TestDuplicateContextNameFunction · 0.70
TestDuplicateUserNameFunction · 0.70
LoadMethod · 0.70
getConfigFromFileFunction · 0.70

Calls 1

LoadFunction · 0.85

Tested by 5

TestLoadingEmptyMapsFunction · 0.56
TestDuplicateClusterNameFunction · 0.56
TestDuplicateContextNameFunction · 0.56
TestDuplicateUserNameFunction · 0.56