Skip to content

Commit 2585d78

Browse files
authored
Merge pull request kubernetes#92513 from soltysh/client_lock
Add the ability to opt-out from config lock file
2 parents 4066719 + 3574d88 commit 2585d78

File tree

1 file changed

+19
-8
lines changed
  • staging/src/k8s.io/client-go/tools/clientcmd

1 file changed

+19
-8
lines changed

staging/src/k8s.io/client-go/tools/clientcmd/config.go

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ type PathOptions struct {
5858
LoadingRules *ClientConfigLoadingRules
5959
}
6060

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+
6170
func (o *PathOptions) GetEnvVarFiles() []string {
6271
if len(o.EnvVar) == 0 {
6372
return []string{}
@@ -156,15 +165,17 @@ func NewDefaultPathOptions() *PathOptions {
156165
// 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
157166
// modified element.
158167
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)
166178
}
167-
defer unlockFile(filename)
168179
}
169180

170181
startingConfig, err := configAccess.GetStartingConfig()

0 commit comments

Comments
 (0)