29
vendor/k8s.io/client-go/tools/clientcmd/config.go
generated
vendored
29
vendor/k8s.io/client-go/tools/clientcmd/config.go
generated
vendored
@ -24,7 +24,7 @@ import (
|
||||
"reflect"
|
||||
"sort"
|
||||
|
||||
"k8s.io/klog"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
restclient "k8s.io/client-go/rest"
|
||||
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
|
||||
@ -58,6 +58,15 @@ type PathOptions struct {
|
||||
LoadingRules *ClientConfigLoadingRules
|
||||
}
|
||||
|
||||
var (
|
||||
// UseModifyConfigLock ensures that access to kubeconfig file using ModifyConfig method
|
||||
// is being guarded by a lock file.
|
||||
// This variable is intentionaly made public so other consumers of this library
|
||||
// can modify its default behavior, but be caution when disabling it since
|
||||
// this will make your code not threadsafe.
|
||||
UseModifyConfigLock = true
|
||||
)
|
||||
|
||||
func (o *PathOptions) GetEnvVarFiles() []string {
|
||||
if len(o.EnvVar) == 0 {
|
||||
return []string{}
|
||||
@ -156,15 +165,17 @@ func NewDefaultPathOptions() *PathOptions {
|
||||
// that means that this code will only write into a single file. If you want to relativizePaths, you must provide a fully qualified path in any
|
||||
// modified element.
|
||||
func ModifyConfig(configAccess ConfigAccess, newConfig clientcmdapi.Config, relativizePaths bool) error {
|
||||
possibleSources := configAccess.GetLoadingPrecedence()
|
||||
// sort the possible kubeconfig files so we always "lock" in the same order
|
||||
// to avoid deadlock (note: this can fail w/ symlinks, but... come on).
|
||||
sort.Strings(possibleSources)
|
||||
for _, filename := range possibleSources {
|
||||
if err := lockFile(filename); err != nil {
|
||||
return err
|
||||
if UseModifyConfigLock {
|
||||
possibleSources := configAccess.GetLoadingPrecedence()
|
||||
// sort the possible kubeconfig files so we always "lock" in the same order
|
||||
// to avoid deadlock (note: this can fail w/ symlinks, but... come on).
|
||||
sort.Strings(possibleSources)
|
||||
for _, filename := range possibleSources {
|
||||
if err := lockFile(filename); err != nil {
|
||||
return err
|
||||
}
|
||||
defer unlockFile(filename)
|
||||
}
|
||||
defer unlockFile(filename)
|
||||
}
|
||||
|
||||
startingConfig, err := configAccess.GetStartingConfig()
|
||||
|
Reference in New Issue
Block a user