k8s.io/client-go@v0.22.2/tools/clientcmd/api/types_test.go (about) 1 /* 2 Copyright 2014 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package api 18 19 import ( 20 "fmt" 21 22 "sigs.k8s.io/yaml" 23 ) 24 25 func Example_emptyConfig() { 26 defaultConfig := NewConfig() 27 28 output, err := yaml.Marshal(defaultConfig) 29 if err != nil { 30 fmt.Printf("Unexpected error: %v", err) 31 } 32 33 fmt.Printf("%v", string(output)) 34 // Output: 35 // clusters: {} 36 // contexts: {} 37 // current-context: "" 38 // preferences: {} 39 // users: {} 40 } 41 42 func Example_ofOptionsConfig() { 43 defaultConfig := NewConfig() 44 defaultConfig.Preferences.Colors = true 45 defaultConfig.Clusters["alfa"] = &Cluster{ 46 Server: "https://alfa.org:8080", 47 InsecureSkipTLSVerify: true, 48 CertificateAuthority: "path/to/my/cert-ca-filename", 49 } 50 defaultConfig.Clusters["bravo"] = &Cluster{ 51 Server: "https://bravo.org:8080", 52 InsecureSkipTLSVerify: false, 53 } 54 defaultConfig.AuthInfos["white-mage-via-cert"] = &AuthInfo{ 55 ClientCertificate: "path/to/my/client-cert-filename", 56 ClientKey: "path/to/my/client-key-filename", 57 } 58 defaultConfig.AuthInfos["red-mage-via-token"] = &AuthInfo{ 59 Token: "my-secret-token", 60 } 61 defaultConfig.AuthInfos["black-mage-via-auth-provider"] = &AuthInfo{ 62 AuthProvider: &AuthProviderConfig{ 63 Name: "gcp", 64 Config: map[string]string{ 65 "foo": "bar", 66 "token": "s3cr3t-t0k3n", 67 }, 68 }, 69 } 70 defaultConfig.Contexts["bravo-as-black-mage"] = &Context{ 71 Cluster: "bravo", 72 AuthInfo: "black-mage-via-auth-provider", 73 Namespace: "yankee", 74 } 75 defaultConfig.Contexts["alfa-as-black-mage"] = &Context{ 76 Cluster: "alfa", 77 AuthInfo: "black-mage-via-auth-provider", 78 Namespace: "zulu", 79 } 80 defaultConfig.Contexts["alfa-as-white-mage"] = &Context{ 81 Cluster: "alfa", 82 AuthInfo: "white-mage-via-cert", 83 } 84 defaultConfig.CurrentContext = "alfa-as-white-mage" 85 86 output, err := yaml.Marshal(defaultConfig) 87 if err != nil { 88 fmt.Printf("Unexpected error: %v", err) 89 } 90 91 fmt.Printf("%v", string(output)) 92 // Output: 93 // clusters: 94 // alfa: 95 // LocationOfOrigin: "" 96 // certificate-authority: path/to/my/cert-ca-filename 97 // insecure-skip-tls-verify: true 98 // server: https://alfa.org:8080 99 // bravo: 100 // LocationOfOrigin: "" 101 // server: https://bravo.org:8080 102 // contexts: 103 // alfa-as-black-mage: 104 // LocationOfOrigin: "" 105 // cluster: alfa 106 // namespace: zulu 107 // user: black-mage-via-auth-provider 108 // alfa-as-white-mage: 109 // LocationOfOrigin: "" 110 // cluster: alfa 111 // user: white-mage-via-cert 112 // bravo-as-black-mage: 113 // LocationOfOrigin: "" 114 // cluster: bravo 115 // namespace: yankee 116 // user: black-mage-via-auth-provider 117 // current-context: alfa-as-white-mage 118 // preferences: 119 // colors: true 120 // users: 121 // black-mage-via-auth-provider: 122 // LocationOfOrigin: "" 123 // auth-provider: 124 // config: 125 // foo: bar 126 // token: s3cr3t-t0k3n 127 // name: gcp 128 // red-mage-via-token: 129 // LocationOfOrigin: "" 130 // token: my-secret-token 131 // white-mage-via-cert: 132 // LocationOfOrigin: "" 133 // client-certificate: path/to/my/client-cert-filename 134 // client-key: path/to/my/client-key-filename 135 }