(configAccess ConfigAccess, newPrefs clientcmdapi.Preferences)
| 428 | } |
| 429 | |
| 430 | func 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. |
| 471 | func getConfigFromFile(filename string) (*clientcmdapi.Config, error) { |
no test coverage detected