| | |
| | | // If the source file is present, then it is copied to the destination file BEFORE any further loading happens. |
| | | MigrationRules map[string]string |
| | | |
| | | // DoNotResolvePaths indicates whether or not to resolve paths with respect to the originating files. This is phrased as a negative so |
| | | // DoNotResolvePaths indicates whether to resolve paths with respect to the originating files. This is phrased as a negative so |
| | | // that a default object that doesn't set this will usually get the behavior it wants. |
| | | DoNotResolvePaths bool |
| | | |
| | |
| | | |
| | | // 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 |
| | | // Otherwise, return a merged config based on the Precedence slice |
| | | // |
| | | // if the ExplicitPath, return the unmerged explicit file |
| | | // Otherwise, return a merged config based on the Precedence slice |
| | | // |
| | | // A missing ExplicitPath file produces an error. Empty filenames or other missing files are ignored. |
| | | // Read errors or files with non-deserializable content produce errors. |
| | | // The first file to set a particular map key wins and map key's value is never changed. |
| | |
| | | // This results in some odd looking logic to merge in one direction, merge in the other, and then merge the two. |
| | | // It also means that if two files specify a "red-user", only values from the first file's red-user are used. Even |
| | | // non-conflicting entries from the second file's "red-user" are discarded. |
| | | // Relative paths inside of the .kubeconfig files are resolved against the .kubeconfig file's parent folder |
| | | // Relative paths inside the .kubeconfig files are resolved against the .kubeconfig file's parent folder |
| | | // and only absolute file paths are returned. |
| | | func (rules *ClientConfigLoadingRules) Load() (*clientcmdapi.Config, error) { |
| | | if err := rules.Migrate(); err != nil { |
| | |
| | | mergo.MergeWithOverwrite(mapConfig, kubeconfig) |
| | | } |
| | | |
| | | // merge all of the struct values in the reverse order so that priority is given correctly |
| | | // merge all the struct values in the reverse order so that priority is given correctly |
| | | // errors are not added to the list the second time |
| | | nonMapConfig := clientcmdapi.NewConfig() |
| | | for i := len(kubeconfigs) - 1; i >= 0; i-- { |
| | |
| | | |
| | | if sourceInfo, err := os.Stat(source); err != nil { |
| | | if os.IsNotExist(err) || os.IsPermission(err) { |
| | | // if the source file doesn't exist or we can't access it, there's no work to do. |
| | | // if the source file doesn't exist, or we can't access it, there's no work to do. |
| | | continue |
| | | } |
| | | |
| | |
| | | if err != nil { |
| | | return nil, err |
| | | } |
| | | klog.V(6).Infoln("Config loaded from file: ", filename) |
| | | //klog.V(6).Infoln("Config loaded from file: ", filename) |
| | | |
| | | // set LocationOfOrigin on every Cluster, User, and Context |
| | | for key, obj := range config.AuthInfos { |
| | |
| | | } |
| | | |
| | | // ResolveLocalPaths resolves all relative paths in the config object with respect to the stanza's LocationOfOrigin |
| | | // this cannot be done directly inside of LoadFromFile because doing so there would make it impossible to load a file without |
| | | // this cannot be done directly inside LoadFromFile because doing so there would make it impossible to load a file without |
| | | // modification of its contents. |
| | | func ResolveLocalPaths(config *clientcmdapi.Config) error { |
| | | for _, cluster := range config.Clusters { |