sigs.k8s.io/cluster-api@v1.7.1/docs/book/src/developer/providers/implementers-guide/generate_crds.md (about) 1 ### Create a repository 2 3 ```bash 4 mkdir cluster-api-provider-mailgun 5 cd src/sigs.k8s.io/cluster-api-provider-mailgun 6 git init 7 ``` 8 9 You'll then need to set up [go modules][gomod] 10 11 ```bash 12 go mod init github.com/liztio/cluster-api-provider-mailgun 13 ``` 14 ```bash 15 go: creating new go.mod: module github.com/liztio/cluster-api-provider-mailgun 16 ``` 17 [gomod]: https://github.com/golang/go/wiki/Modules#how-to-define-a-module 18 19 ### Generate scaffolding 20 21 ```bash 22 kubebuilder init --domain cluster.x-k8s.io 23 ``` 24 25 `kubebuilder init` will create the basic repository layout, including a simple containerized manager. 26 It will also initialize the external go libraries that will be required to build your project. 27 28 Commit your changes so far: 29 30 ```bash 31 git commit -m "Generate scaffolding." 32 ``` 33 34 ### Generate provider resources for Clusters and Machines 35 36 Here you will be asked if you want to generate resources and controllers. 37 You'll want both of them: 38 39 ```bash 40 kubebuilder create api --group infrastructure --version v1alpha1 --kind MailgunCluster 41 kubebuilder create api --group infrastructure --version v1alpha1 --kind MailgunMachine 42 ``` 43 44 ```bash 45 Create Resource under pkg/apis [y/n]? 46 y 47 Create Controller under pkg/controller [y/n]? 48 y 49 ``` 50 51 The latest API version of Cluster API and the version of your provider do not need to be in sync. Instead, prefer choosing a version that matches the stability of the provider API and its backward compatibility guarantees. 52 53 ### Add Status subresource 54 55 The [status subresource][status] lets Spec and Status requests for custom resources be addressed separately so requests don't conflict with each other. 56 It also lets you split RBAC rules between Spec and Status. You will have to [manually enable it in Kubebuilder][kbstatus]. 57 58 Add the `subresource:status` annotation to your `<provider>cluster_types.go` `<provider>machine_types.go` 59 60 ```go 61 // +kubebuilder:subresource:status 62 // +kubebuilder:object:root=true 63 64 // MailgunCluster is the Schema for the mailgunclusters API 65 type MailgunCluster struct { 66 ``` 67 68 ```go 69 // +kubebuilder:subresource:status 70 // +kubebuilder:object:root=true 71 72 // MailgunMachine is the Schema for the mailgunmachines API 73 type MailgunMachine struct { 74 ``` 75 76 And regenerate the CRDs: 77 ```bash 78 make manifests 79 ``` 80 81 [status]: https://kubernetes.io/docs/tasks/access-kubernetes-api/custom-resources/custom-resource-definitions/#status-subresource 82 [kbstatus]: https://book.kubebuilder.io/reference/generating-crd.html?highlight=status#status 83 84 ### Apply further customizations 85 86 The cluster API CRDs should be further customized: 87 88 - [Apply the contract version label to support conversions](../contracts.md#api-version-labels) (required to deploy _any_ custom resource of your provider) 89 - [Ensure you are compliant with the clusterctl provider contract](../../../clusterctl/provider-contract.md#components-yaml) 90 91 ### Commit your changes 92 93 ```bash 94 git add . 95 git commit -m "Generate Cluster and Machine resources." 96 ```