Basically, my kubeconfig file has:
apiVersion: v1
clusters:
- cluster:
server: <OAM ip address> this is what I want
(...)
I want to get the server address. Previously searching , I've found this solution:
config, err := clientcmd.BuildConfigFromFlags("", *kubeconfig)
if err != nil {
panic(err.Error())
}
// creates the clientset
clientset, err := kubernetes.NewForConfig(config)
if err != nil {
panic(err.Error())
}
nodes, err := clientset.CoreV1().Nodes().List(metav1.ListOptions{})
if err != nil {
panic(err)
}
nodeip := []corev1.NodeAddress{}
for i := 0; i < len(nodes.Items); i++ {
nodeip = nodes.Items[i].Status.Addresses
fmt.Println(nodeip[0].Address)
}
fmt.Println(nodes.Items[0].Status.Addresses)
But it gives me the Internal IP, not the OAM server IP (which is inside the Kubernetes config file)
If you want the server address from the
kubeconfigfile, just read it from yourconfigvariable:If you're curious what other fields are available on the
rest.Configobject, a quick solution is to print out theconfigvariable using the%+vformat specifier:For more details, look at the reference documentation.