MCPcopy
hub / github.com/kubernetes/client-go / WriteToFile

Function WriteToFile

tools/clientcmd/loader.go:405–421  ·  view source on GitHub ↗

WriteToFile serializes the config to yaml and writes it out to a file. If not present, it creates the file with the mode 0600. If it is present it stomps the contents

(config clientcmdapi.Config, filename string)

Source from the content-addressed store, hash-verified

403// WriteToFile serializes the config to yaml and writes it out to a file. If not present, it creates the file with the mode 0600. If it is present
404// it stomps the contents
405func WriteToFile(config clientcmdapi.Config, filename string) error {
406 content, err := Write(config)
407 if err != nil {
408 return err
409 }
410 dir := filepath.Dir(filename)
411 if _, err := os.Stat(dir); os.IsNotExist(err) {
412 if err = os.MkdirAll(dir, 0755); err != nil {
413 return err
414 }
415 }
416
417 if err := ioutil.WriteFile(filename, content, 0600); err != nil {
418 return err
419 }
420 return nil
421}
422
423func lockFile(filename string) error {
424 // TODO: find a way to do this with actual file locks. Will

Callers 11

TestLoadingEmptyMapsFunction · 0.85
TestResolveRelativePathsFunction · 0.85
TestMigratingFileFunction · 0.85
ModifyConfigFunction · 0.85
writeCurrentContextFunction · 0.85
writePreferencesFunction · 0.85

Calls 1

WriteFunction · 0.85