1 Star 0 Fork 0

zhuchance / kubernetes

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
generating-clientset.md 3.19 KB
一键复制 编辑 原始数据 按行查看 历史
Chao Xu 提交于 2016-10-31 11:59 . remove release_1_4

Generation and release cycle of clientset

Client-gen is an automatic tool that generates clientset based on API types. This doc introduces the use the client-gen, and the release cycle of the generated clientsets.

Using client-gen

The workflow includes three steps:

  1. Marking API types with tags: in pkg/apis/${GROUP}/${VERSION}/types.go, mark the types (e.g., Pods) that you want to generate clients for with the // +genclient=true tag. If the resource associated with the type is not namespace scoped (e.g., PersistentVolume), you need to append the nonNamespaced=true tag as well.

  • a. If you are developing in the k8s.io/kubernetes repository, you just need to run hack/update-codegen.sh.

  • b. If you are running client-gen outside of k8s.io/kubernetes, you need to use the command line argument --input to specify the groups and versions of the APIs you want to generate clients for, client-gen will then look into pkg/apis/${GROUP}/${VERSION}/types.go and generate clients for the types you have marked with the genclient tags. For example, to generated a clientset named "my_release" including clients for api/v1 objects and extensions/v1beta1 objects, you need to run:

$ client-gen --input="api/v1,extensions/v1beta1" --clientset-name="my_release"
  1. Adding expansion methods: client-gen only generates the common methods, such as CRUD. You can manually add additional methods through the expansion interface. For example, this file adds additional methods to Pod's client. As a convention, we put the expansion interface and its methods in file ${TYPE}_expansion.go. In most cases, you don't want to remove existing expansion files. So to make life easier, instead of creating a new clientset from scratch, you can copy and rename an existing clientset (so that all the expansion files are copied), and then run client-gen.

Output of client-gen

  • clientset: the clientset will be generated at pkg/client/clientset_generated/ by default, and you can change the path via the --clientset-path command line argument.

  • Individual typed clients and client for group: They will be generated at pkg/client/clientset_generated/${clientset_name}/typed/generated/${GROUP}/${VERSION}/

Released clientsets

If you are contributing code to k8s.io/kubernetes, try to use the release_X_Y clientset in this directory.

If you need a stable Go client to build your own project, please refer to the client-go repository.

We are migrating k8s.io/kubernetes to use client-go as well, see issue #35159.

[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/devel/generating-clientset.md?pixel)]()

Analytics

马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/meoom/kubernetes.git
git@gitee.com:meoom/kubernetes.git
meoom
kubernetes
kubernetes
v1.5.4-beta.0

搜索帮助

344bd9b3 5694891 D2dac590 5694891