Scaffolding
Objective: To create the initial project structure for our provider. Learn about the scaffolding tooling. NOTE: these steps are applicable to any operator you want to build.
- Open your favourite terminal and go to
cluster-api-provider-docker
directory. - Run the following commands to scaffold the project
kubebuilder init --domain cluster.x-k8s.io --repo github.com/myname/cluster-api-provider-docker --project-version 3
- Run the following commands to scaffold the API & controllers for the DockerCluster and DockerMachine, ensuring you answer Y to the following: a. Create Resource b. Create Controller
kubebuilder create api --group infrastructure --version v1alpha1 --kind DockerCluster
kubebuilder create api --group infrastructure --version v1alpha1 --kind DockerMachine
If you get the following error:
/usr/local/go/src/net/cgo_linux.go:12:8: no such package located
Then you should install gcc
and set the CGO_ENABLED
environment variable to 0 to disable cgo
- Run the following commands:
make generate
make manifests
make build
Take a look at the generated code:
api/v1alpha1
folder contains the CRD definitions for your infrastructure cluster & machinecontrollers
contains the controllers that will reconcile instances of your infrastructure CRDsconfig
contains the Kubernetes artifacts that will be bundled together and used when deploying our provider
Make a change to
main.go
change the port for the health-probe-bind-address flag from8081
to9440
:
flag.StringVar(&probeAddr, "health-probe-bind-address", ":9440", "The address the probe endpoint binds to.")
This change is required as the liveness/readiness probes get generated using port 9440 but the code uses 8081 by default. If you don't change this then when you deploy the liveness and readiness probes will fail