How to user code-generator
In this article, we will focus on how to use the K8s code-generator from scratch.
Let's assume we want to create CRD in group "foo.com", and there is a type called "HelloType" with a "message" field in the spec:
# Definition
---
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: hellotypes.foo.com
spec:
group: foo.com
version: v1
scope: Namespaced
names:
kind: HelloType
shortNames: ht
plural: hellotypes
singular: hellotype
# HelloType
---
apiVersion: foo.com/v1
kind: HelloType
metadata:
name: superman-hello
spec:
message: hello worldThere are two steps to generate the CRD resource code:
Write the type definition code with code generator tags
Run run the generator to create the client codes which include: clientset, informers, listers for your customer resource
Write type definition code
cd $GOPATH/srcmkdir -p github.com/superman/democd $GOPATH/src/github.com/superman/demoCreate the skeleton files as below under
$GOPATH/src/github.com/superman/demo
doc.go
types.go
register.go
Run code-generator to create client codes
After above steps, you will see the following file structure:
References:
Last updated
Was this helpful?