我是 k8s go-client 的新手。我想将项目传递deploymentsClient.List(metav1.ListOptions{})给函数。fmt.Printf("%T\n", deploy)说它是类型v1.Deployment。因此,我编写了一个函数,该函数接受(deploy *v1.Deployment)并传递它&deploy,其中部署是deploymentsClient.List. 然而,这个错误cmd/list.go:136:38: undefined: v1。我究竟做错了什么?这是我的进口import ( // "encoding/json" "flag" "fmt" //yaml "github.com/ghodss/yaml" "github.com/spf13/cobra" // "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" "k8s.io/client-go/tools/clientcmd" "os" "path/filepath")然后我得到部署列表: deploymentsClient := clientset.AppsV1().Deployments(ns) deployments, err := deploymentsClient.List(metav1.ListOptions{}) if err != nil { panic(err.Error()) } for _, deploy := range deployments.Items { fmt.Println(deploy.ObjectMeta.SelfLink) // printDeploymentSpecJson(deploy) // printDeploymentSpecYaml(deploy) }
- 1 回答
- 0 关注
- 94 浏览
添加回答
举报
0/150
提交
取消