To run the application against a cluster, you need to have a cluster in your local environment. You can either have access to your local environment or use Minikube or KinD in a Docker environment and use a Docker container for development, such as VSCode's Dev Containers feature.
If you set up the environment, the cluster should have Cert Manager installed to auto-generate certificates, which is required to test the webhook.
-
In
config/default/kustomization.yaml
, make the following change:# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in # crd/kustomization.yaml # - path: manager_webhook_patch.yaml # For local testing, use below and disable above patch - path: manager_local_webhook_patch.yaml
-
In
config/webkhook/kustomization.yaml
, Comment out the following section:# For local testing, disable here # configurations: # - kustomizeconfig.yaml
Create required resources in cluster
make deploy
Run the following command to download the generated certificates for the webhook to your project folder:
make download-secrets
Here is an example configuration for .devcontainer:
{
"name": "kubedns-shepherd",
"image": "mcr.microsoft.com/devcontainers/go:1-1.23-bookworm",
"mounts": [
"source=${localWorkspaceFolder}/tmp/k8s-webhook-server,target=/tmp/k8s-webhook-server,type=bind",
"source=${localEnv:HOME}${localEnv:USERPROFILE}/.kube/minikube-config,target=/home/vscode/.kube/config,readonly,type=bind"
],
"runArgs": [
"--network=minikube"
]
}
This configuration binds two different paths and sets the network to make sure they are correct.
-
To generate code containing
DeepCopy
,DeepCopyInto
, andDeepCopyObject
method implementations, orWebhookConfiguration
,ClusterRole
, andCustomResourceDefinition
objects, use:make generate
-
To generate manifests, use:
make manifest
NOTE: Run make help
for more information on all potential make
targets