Load is a modified copy of k8s.io/kubernetes/pkg/client/unversioned/clientcmd.ClientConfigLoadingRules.Load Load starts by running the MigrationRules and then takes the loading rules and returns a Config object based on following rules. - if the ExplicitPath, return the unmerged explicit file - Oth
()
| 532 | // Relative paths inside of the .kubeconfig files are resolved against the .kubeconfig file's parent folder |
| 533 | // and only absolute file paths are returned. |
| 534 | func (rules *clientConfigLoadingRules) Load() (*clientcmdConfig, error) { |
| 535 | errlist := []error{} |
| 536 | |
| 537 | kubeConfigFiles := []string{} |
| 538 | |
| 539 | // REMOVED: explicit path support |
| 540 | kubeConfigFiles = append(kubeConfigFiles, rules.Precedence...) |
| 541 | |
| 542 | kubeconfigs := []*clientcmdConfig{} |
| 543 | // read and cache the config files so that we only look at them once |
| 544 | for _, filename := range kubeConfigFiles { |
| 545 | if len(filename) == 0 { |
| 546 | // no work to do |
| 547 | continue |
| 548 | } |
| 549 | |
| 550 | config, err := loadFromFile(filename) |
| 551 | if os.IsNotExist(err) { |
| 552 | // skip missing files |
| 553 | continue |
| 554 | } |
| 555 | if err != nil { |
| 556 | errlist = append(errlist, fmt.Errorf("loading config file %q: %w", filename, err)) |
| 557 | continue |
| 558 | } |
| 559 | |
| 560 | kubeconfigs = append(kubeconfigs, config) |
| 561 | } |
| 562 | |
| 563 | // first merge all of our maps |
| 564 | mapConfig := clientcmdNewConfig() |
| 565 | for _, kubeconfig := range kubeconfigs { |
| 566 | if err := mergo.MergeWithOverwrite(mapConfig, kubeconfig); err != nil { |
| 567 | return nil, err |
| 568 | } |
| 569 | } |
| 570 | |
| 571 | // merge all of the struct values in the reverse order so that priority is given correctly |
| 572 | // errors are not added to the list the second time |
| 573 | nonMapConfig := clientcmdNewConfig() |
| 574 | for _, kubeconfig := range slices.Backward(kubeconfigs) { |
| 575 | if err := mergo.MergeWithOverwrite(nonMapConfig, kubeconfig); err != nil { |
| 576 | return nil, err |
| 577 | } |
| 578 | } |
| 579 | |
| 580 | // since values are overwritten, but maps values are not, we can merge the non-map config on top of the map config and |
| 581 | // get the values we expect. |
| 582 | config := clientcmdNewConfig() |
| 583 | if err := mergo.MergeWithOverwrite(config, mapConfig); err != nil { |
| 584 | return nil, err |
| 585 | } |
| 586 | if err := mergo.MergeWithOverwrite(config, nonMapConfig); err != nil { |
| 587 | return nil, err |
| 588 | } |
| 589 | |
| 590 | // REMOVED: Possibility to skip this. |
| 591 | if err := resolveLocalPaths(config); err != nil { |