看了网上很多博客都是在使用restclient访问pod资源,于是想使用他查询一些pod以外的资源,比如deployment,使用途中遇到了一个问题,不知道怎么选择config的APIPath,试了apps,api/apps,apps/v1发现都不行, 于是思考了一下这个APIPath到底指的是什么,与试了一下apis, 这下成功了。
所以这里的APIPath其实也就是资源的上一级url吧
config.APIPath = "apis"
config.NegotiatedSerializer = scheme.Codecs
config.GroupVersion = &v1.SchemeGroupVersion
restClient, err := rest.RESTClientFor(config)
if err != nil {
return
}
deploys := &v1.DeploymentList{}
err = restClient.Get().Namespace("default").Resource("deployments").Do(context.TODO()).Into(deploys)
if err != nil {
panic(err)
}
fmt.Println(deploys.Items)