@@ -58,6 +58,15 @@ type PathOptions struct {
58
58
LoadingRules * ClientConfigLoadingRules
59
59
}
60
60
61
+ var (
62
+ // UseModifyConfigLock ensures that access to kubeconfig file using ModifyConfig method
63
+ // is being guarded by a lock file.
64
+ // This variable is intentionaly made public so other consumers of this library
65
+ // can modify its default behavior, but be caution when disabling it since
66
+ // this will make your code not threadsafe.
67
+ UseModifyConfigLock = true
68
+ )
69
+
61
70
func (o * PathOptions ) GetEnvVarFiles () []string {
62
71
if len (o .EnvVar ) == 0 {
63
72
return []string {}
@@ -156,15 +165,17 @@ func NewDefaultPathOptions() *PathOptions {
156
165
// 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
157
166
// modified element.
158
167
func ModifyConfig (configAccess ConfigAccess , newConfig clientcmdapi.Config , relativizePaths bool ) error {
159
- possibleSources := configAccess .GetLoadingPrecedence ()
160
- // sort the possible kubeconfig files so we always "lock" in the same order
161
- // to avoid deadlock (note: this can fail w/ symlinks, but... come on).
162
- sort .Strings (possibleSources )
163
- for _ , filename := range possibleSources {
164
- if err := lockFile (filename ); err != nil {
165
- return err
168
+ if UseModifyConfigLock {
169
+ possibleSources := configAccess .GetLoadingPrecedence ()
170
+ // sort the possible kubeconfig files so we always "lock" in the same order
171
+ // to avoid deadlock (note: this can fail w/ symlinks, but... come on).
172
+ sort .Strings (possibleSources )
173
+ for _ , filename := range possibleSources {
174
+ if err := lockFile (filename ); err != nil {
175
+ return err
176
+ }
177
+ defer unlockFile (filename )
166
178
}
167
- defer unlockFile (filename )
168
179
}
169
180
170
181
startingConfig , err := configAccess .GetStartingConfig ()
0 commit comments