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

Function Example_mergingEverythingNoConflicts

tools/clientcmd/loader_test.go:679–762  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

677}
678
679func Example_mergingEverythingNoConflicts() {
680 commandLineFile, _ := ioutil.TempFile("", "")
681 defer os.Remove(commandLineFile.Name())
682 envVarFile, _ := ioutil.TempFile("", "")
683 defer os.Remove(envVarFile.Name())
684 currentDirFile, _ := ioutil.TempFile("", "")
685 defer os.Remove(currentDirFile.Name())
686 homeDirFile, _ := ioutil.TempFile("", "")
687 defer os.Remove(homeDirFile.Name())
688
689 WriteToFile(testConfigAlfa, commandLineFile.Name())
690 WriteToFile(testConfigBravo, envVarFile.Name())
691 WriteToFile(testConfigCharlie, currentDirFile.Name())
692 WriteToFile(testConfigDelta, homeDirFile.Name())
693
694 loadingRules := ClientConfigLoadingRules{
695 Precedence: []string{commandLineFile.Name(), envVarFile.Name(), currentDirFile.Name(), homeDirFile.Name()},
696 }
697
698 mergedConfig, err := loadingRules.Load()
699
700 json, err := runtime.Encode(clientcmdlatest.Codec, mergedConfig)
701 if err != nil {
702 fmt.Printf("Unexpected error: %v", err)
703 }
704 output, err := yaml.JSONToYAML(json)
705 if err != nil {
706 fmt.Printf("Unexpected error: %v", err)
707 }
708
709 fmt.Printf("%v", string(output))
710 // Output:
711 // apiVersion: v1
712 // clusters:
713 // - cluster:
714 // server: http://chicken.org:8080
715 // name: chicken-cluster
716 // - cluster:
717 // server: http://cow.org:8080
718 // name: cow-cluster
719 // - cluster:
720 // server: http://horse.org:8080
721 // name: horse-cluster
722 // - cluster:
723 // server: http://pig.org:8080
724 // name: pig-cluster
725 // contexts:
726 // - context:
727 // cluster: cow-cluster
728 // namespace: hammer-ns
729 // user: red-user
730 // name: federal-context
731 // - context:
732 // cluster: chicken-cluster
733 // namespace: plane-ns
734 // user: blue-user
735 // name: gothic-context
736 // - context:

Callers

nothing calls this directly

Calls 4

LoadMethod · 0.95
WriteToFileFunction · 0.85
NameMethod · 0.45
EncodeMethod · 0.45

Tested by

no test coverage detected