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

Function writePreferences

tools/clientcmd/config.go:430–468  ·  view source on GitHub ↗
(configAccess ConfigAccess, newPrefs clientcmdapi.Preferences)

Source from the content-addressed store, hash-verified

428}
429
430func writePreferences(configAccess ConfigAccess, newPrefs clientcmdapi.Preferences) error {
431 if startingConfig, err := configAccess.GetStartingConfig(); err != nil {
432 return err
433 } else if reflect.DeepEqual(startingConfig.Preferences, newPrefs) {
434 return nil
435 }
436
437 if configAccess.IsExplicitFile() {
438 file := configAccess.GetExplicitFile()
439 currConfig, err := getConfigFromFile(file)
440 if err != nil {
441 return err
442 }
443 currConfig.Preferences = newPrefs
444 if err := WriteToFile(*currConfig, file); err != nil {
445 return err
446 }
447
448 return nil
449 }
450
451 for _, file := range configAccess.GetLoadingPrecedence() {
452 currConfig, err := getConfigFromFile(file)
453 if err != nil {
454 return err
455 }
456
457 if !reflect.DeepEqual(currConfig.Preferences, newPrefs) {
458 currConfig.Preferences = newPrefs
459 if err := WriteToFile(*currConfig, file); err != nil {
460 return err
461 }
462
463 return nil
464 }
465 }
466
467 return errors.New("no config found to write preferences")
468}
469
470// getConfigFromFile tries to read a kubeconfig file and if it can't, returns an error. One exception, missing files result in empty configs, not an error.
471func getConfigFromFile(filename string) (*clientcmdapi.Config, error) {

Callers 1

ModifyConfigFunction · 0.85

Calls 6

getConfigFromFileFunction · 0.85
WriteToFileFunction · 0.85
GetStartingConfigMethod · 0.65
IsExplicitFileMethod · 0.65
GetExplicitFileMethod · 0.65
GetLoadingPrecedenceMethod · 0.65

Tested by

no test coverage detected