How to init config from memory on client go

8/17/2021
var kubeconfig *string
if home := homedir.HomeDir(); home != "" {
	kubeconfig = flag.String("kubeconfig", filepath.Join(home, ".kube", "config"), "(optional) absolute path to the kubeconfig file")
} else {
	kubeconfig = flag.String("kubeconfig", "", "absolute path to the kubeconfig file")
}
flag.Parse()

config, err := clientcmd.BuildConfigFromFlags("", *kubeconfig)
if err != nil {
	panic(err)
}

Above code snippet from the client go example. For BuildConfigFromFlags function second parameter is the path of config file. I have to read the content in the memory. Is there any alternate API i can use?

-- Weikun Lin
client-go
kubernetes

0 Answers