mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 19:31:44 +00:00
Add the ability to opt-out from config lock file
This commit is contained in:
parent
180af4240c
commit
3574d88e22
@ -58,6 +58,15 @@ type PathOptions struct {
|
|||||||
LoadingRules *ClientConfigLoadingRules
|
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 {
|
func (o *PathOptions) GetEnvVarFiles() []string {
|
||||||
if len(o.EnvVar) == 0 {
|
if len(o.EnvVar) == 0 {
|
||||||
return []string{}
|
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
|
// 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.
|
// modified element.
|
||||||
func ModifyConfig(configAccess ConfigAccess, newConfig clientcmdapi.Config, relativizePaths bool) error {
|
func ModifyConfig(configAccess ConfigAccess, newConfig clientcmdapi.Config, relativizePaths bool) error {
|
||||||
possibleSources := configAccess.GetLoadingPrecedence()
|
if UseModifyConfigLock {
|
||||||
// sort the possible kubeconfig files so we always "lock" in the same order
|
possibleSources := configAccess.GetLoadingPrecedence()
|
||||||
// to avoid deadlock (note: this can fail w/ symlinks, but... come on).
|
// sort the possible kubeconfig files so we always "lock" in the same order
|
||||||
sort.Strings(possibleSources)
|
// to avoid deadlock (note: this can fail w/ symlinks, but... come on).
|
||||||
for _, filename := range possibleSources {
|
sort.Strings(possibleSources)
|
||||||
if err := lockFile(filename); err != nil {
|
for _, filename := range possibleSources {
|
||||||
return err
|
if err := lockFile(filename); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer unlockFile(filename)
|
||||||
}
|
}
|
||||||
defer unlockFile(filename)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
startingConfig, err := configAccess.GetStartingConfig()
|
startingConfig, err := configAccess.GetStartingConfig()
|
||||||
|
Loading…
Reference in New Issue
Block a user