LoadFromFile takes a filename and deserializes the contents into Config object
(filename string)
| 348 | |
| 349 | // LoadFromFile takes a filename and deserializes the contents into Config object |
| 350 | func 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. |