INNER CODE UNIT · Go
main
iximiuz/client-go-examples · cli-runtime-flags/main.go:15
func main() {
configFlags := genericclioptions.NewConfigFlags(true)
cmd := &cobra.Command{
Use: "kubectl (well, almost)",
Run: func(cmd *cobra.Command, args []string) {
// Interesting methods:
// - ToRawKubeConfigLoader (returns clientcmd.ClientConfig)
// - ToRESTConfig
// - ToRESTMapper
// - ToDiscoveryClient
kubeconfig, err := configFlags.ToRawKubeConfigLoader().RawConfig()
if err != nil {
panic(err.Error())
}
for name := range kubeconfig.Contexts {
fmt.Printf("Found context %s\n", name)