我正在为 Kubernetes 使用 client-go 并尝试获取当前集群的 API url,即类似于kubectl cluster-info
. 我找到了一个名为getCluster
:
func (config *DirectClientConfig) ClientConfig() (*restclient.Config, error) {
// check that getAuthInfo, getContext, and getCluster do not return an error.
// Do this before checking if the current config is usable in the event that an
// AuthInfo, Context, or Cluster config with user-defined names are not found.
// This provides a user with the immediate cause for error if one is found
configAuthInfo, err := config.getAuthInfo()
if err != nil {
return nil, err
}
_, err = config.getContext()
if err != nil {
return nil, err
}
configClusterInfo, err := config.getCluster()
if err != nil {
return nil, err
}
...
}
当我在我的代码中编写以下内容时
config, err := clientcmd.BuildConfigFromFlags("", kubeconfig)
clusterInfo, err := config.getCluster()
我得到错误config.getCluster undefined (type *rest.Config has no field or method getCluster)
我怎样才能使用这个功能?还有其他方法可以获取此网址吗?