### Install Azure Infrastructure Provider Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/README.md Example of installing the Azure Infrastructure Provider. This includes creating a Kubernetes Secret with necessary Azure credentials and a GitHub token, and then defining the InfrastructureProvider resource. Ensure the 'capz-system' namespace exists. ```yaml --- apiVersion: v1 kind: Secret metadata: name: azure-variables namespace: capz-system type: Opaque stringData: AZURE_CLIENT_ID_B64: Zm9vCg== AZURE_CLIENT_SECRET_B64: Zm9vCg== AZURE_SUBSCRIPTION_ID_B64: Zm9vCg== AZURE_TENANT_ID_B64: Zm9vCg== github-token: ghp_fff --- apiVersion: operator.cluster.x-k8s.io/v1alpha1 kind: InfrastructureProvider metadata: name: azure namespace: capz-system spec: version: v1.9.3 configSecret: name: azure-variables ``` -------------------------------- ### Start Tilt Development Environment Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/AGENTS.md Command to start the Tilt development environment from the cluster-api directory. ```bash make tilt-up ``` -------------------------------- ### Install cluster-api-operator Plugin Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/03_topics/03_plugin/01_installation.md Install the cluster-api-operator plugin using the krew install command. ```bash kubectl krew install operator/clusterctl-operator ``` -------------------------------- ### Install CoreProvider Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/03_topics/03_basic-cluster-api-provider-installation/01_installing-core-provider.md Use this YAML definition to install the CoreProvider. Ensure the target namespace exists before applying. ```yaml apiVersion: operator.cluster.x-k8s.io/v1alpha2 kind: CoreProvider metadata: name: cluster-api namespace: capi-system spec: version: v1.4.3 ``` -------------------------------- ### ProviderStatus YAML Example Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/05_reference/06_providers.md An example of the ProviderStatus structure, showing contract, conditions, observed generation, and installed version. ```yaml status: contract: "v1beta1" conditions: - type: "Ready" status: "True" reason: "ProviderAvailable" message: "Provider is available and ready" observedGeneration: 1 installedVersion: "v0.1.0" ``` -------------------------------- ### Start Tilt for Development Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/04_developer/02_guide.md Use Tilt to automatically build, push, and reload Docker containers for your Kubernetes deployment. This command starts the Tilt development environment. ```bash tilt up ``` -------------------------------- ### Example of setting up OCI authentication Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/03_topics/03_plugin/03_publish_subcommand.md Demonstrates setting environment variables for OCI registry authentication. The `publish` command automatically uses these credentials. ```bash export OCI_USERNAME=myusername export OCI_PASSWORD=mypassword ``` ```bash kubectl operator publish -u my-oci-registry.com/${IMAGE_NAME}:v0.0.1 -d manifests ``` -------------------------------- ### Configure Tilt for Local Development Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/CONTRIBUTING.md Example configuration for `tilt-settings.yaml` to enable local development with Tilt. Ensure the cluster-api repository is cloned alongside this one. ```yaml provider_repos: - "../cluster-api-operator" enable_providers: - capi-operator enable_core_provider: false ``` -------------------------------- ### Verify cluster-api-operator Plugin Installation Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/03_topics/03_plugin/01_installation.md Verify the installation by running the kubectl operator command. This should display help information. ```bash kubectl operator ``` -------------------------------- ### FetchConfiguration YAML Example Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/03_topics/02_configuration/05_provider-spec-configuration.md Specifies how the operator will fetch components and metadata, using a URL for remote releases or a label selector for ConfigMaps. ```yaml ... spec: fetchConfig: url: "https://github.com/owner/repo/releases" selector: matchLabels: ... ``` -------------------------------- ### Install cert-manager Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/02_installation/01_prerequisites.md Install cert-manager using kubectl. Ensure this is completed before installing the Cluster API operator. ```bash kubectl apply -f https://github.com/jetstack/cert-manager/releases/latest/download/cert-manager.yaml ``` -------------------------------- ### FetchConfiguration YAML Example Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/README.md Defines options for fetching provider components and metadata, including a URL for remote repositories or a label selector for in-cluster ConfigMaps. ```yaml ... spec: fetchConfig: url: "https://github.com/owner/repo/releases" selector: matchLabels: ... ``` -------------------------------- ### Add Helm Repository and Install Operator Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/02_installation/04_helm-chart-installation.md Add the Cluster API operator Helm repository and install the operator. This is the initial step before configuring providers. ```bash helm repo add capi-operator https://kubernetes-sigs.github.io/cluster-api-operator helm repo update helm install capi-operator capi-operator/cluster-api-operator --create-namespace -n capi-operator-system ``` -------------------------------- ### Run Tilt for Local Development Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/local-development.md Execute these commands from the `cluster-api` folder to build local CAPI images and start Tilt. Tilt will automatically reload deployments on code changes. ```bash make docker-build-e2e # Use locally built CAPI images ``` ```bash make tilt-up ``` -------------------------------- ### Install Operator with Multiple Enabled Providers Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/02_installation/04_helm-chart-installation.md Install the Cluster API operator enabling both Docker and Azure infrastructure providers. The `--wait` flag is required. ```bash helm install capi-operator capi-operator/cluster-api-operator --create-namespace -n capi-operator-system --set infrastructure.docker.enabled=true,infrastructure.azure.enabled=true --wait --timeout 90s # core Cluster API with kubeadm bootstrap and control plane providers will also be installed ``` -------------------------------- ### DeploymentSpec YAML Example Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/03_topics/02_configuration/05_provider-spec-configuration.md Specifies deployment properties for a provider, including replicas, node selectors, tolerations, affinity, and containers. ```yaml ... spec: deployment: replicas: 2 nodeSelector: disktype: ssd tolerations: - key: "example" operator: "Exists" effect: "NoSchedule" affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - key: "example" operator: "In" values: - "true" containers: - name: "containerA" imageUrl: "example.com/repo/image-name:v1.0.0" args: exampleArg: "value" ... ``` -------------------------------- ### Install Operator with Custom Provider Namespaces and Versions Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/02_installation/04_helm-chart-installation.md Install the Cluster API operator with custom namespaces and specific versions for Docker and Azure infrastructure providers. The `--wait` flag is required. ```bash helm install capi-operator capi-operator/cluster-api-operator --create-namespace -n capi-operator-system --set infrastructure.docker.namespace=capd-custom-ns,infrastructure.docker.version=v1.4.2,infrastructure.azure.namespace=capz-custom-ns,infrastructure.azure.version=v1.10.0 --wait --timeout 90s # core Cluster API with kubeadm bootstrap and control plane providers will also be installed ``` -------------------------------- ### Run pprof Commands Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/04_developer/03_profiling.md Once port-forwarding is established, execute pprof commands against the operator's debug endpoint. This example collects profile data for 30 seconds. ```bash go tool pprof http://localhost:6060/debug/pprof/profile?seconds=30 ``` -------------------------------- ### Install Cluster API Operator with Manifest Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/02_installation/03_manifest-installation.md Apply the operator components manifest directly from the latest release assets to install the Cluster API operator. ```bash kubectl apply -f https://github.com/kubernetes-sigs/cluster-api-operator/releases/latest/download/operator-components.yaml ``` -------------------------------- ### Install Cert Manager Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/01_user/02_quick-start.md Installs cert-manager using Helm, ensuring CRDs are installed. This is a prerequisite for the Cluster API Operator. ```bash helm install cert-manager jetstack/cert-manager --namespace cert-manager --create-namespace --set installCRDs=true ``` -------------------------------- ### Use Default Fetch Configurations for Providers Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/03_topics/02_configuration/03_examples-of-api-usage.md Install an InfrastructureProvider (e.g., 'vsphere') without explicitly defining fetch configurations, allowing the operator to use default repository URLs based on the provider name. ```yaml --- apiVersion: operator.cluster.x-k8s.io/v1alpha2 kind: InfrastructureProvider metadata: name: vsphere namespace: capv-system spec: version: v1.6.1 configSecret: name: vsphere-variables ``` -------------------------------- ### Install Operator with Specific Component Versions Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/02_installation/04_helm-chart-installation.md Install the Cluster API operator specifying exact versions for core Cluster API, control plane, bootstrap, and Docker infrastructure providers. The `--wait` flag is required. ```bash helm install capi-operator capi-operator/cluster-api-operator --create-namespace -n capi-operator-system --set core.cluster-api.version=v1.4.2 --set controlPlane.kubeadm.version=v1.4.2 --set bootstrap.kubeadm.version=v1.4.2 --set infrastructure.docker.version=v1.4.2 --wait --timeout 90s ``` -------------------------------- ### Install AWS Infrastructure Provider with Custom Controller Flags Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/03_topics/02_configuration/03_examples-of-api-usage.md Install the AWS infrastructure provider with specific controller flags for manager concurrency. Requires a Secret for AWS credentials. ```yaml apiVersion: v1 kind: Secret metadata: name: aws-variables namespace: capa-system type: Opaque data: AWS_B64ENCODED_CREDENTIALS: ... --- apiVersion: operator.cluster.x-k8s.io/v1alpha2 kind: InfrastructureProvider metadata: name: aws namespace: capa-system spec: version: v2.1.4 configSecret: name: aws-variables manager: # These top level controller manager flags, supported by all the providers. # These flags come with sensible defaults, thus requiring no or minimal # changes for the most common scenarios. metrics: bindAddress: ":8181" syncPeriod: "500s" fetchConfig: url: https://github.com/kubernetes-sigs/cluster-api-provider-aws/releases deployment: containers: - name: manager args: # These are controller flags that are specific to a provider; usage # is reserved for advanced scenarios only. "--awscluster-concurrency": "12" "--awsmachine-concurrency": "11" ``` -------------------------------- ### Install AWS Infrastructure Provider with Controller Flags Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/README.md Installs the AWS infrastructure provider with specific controller manager flags for metrics and synchronization period. Requires a secret for AWS credentials. ```yaml apiVersion: v1 kind: Secret metadata: name: aws-variables namespace: capa-system type: Opaque data: AWS_B64ENCODED_CREDENTIALS: ... ``` ```yaml apiVersion: operator.cluster.x-k8s.io/v1alpha2 kind: InfrastructureProvider metadata: name: aws namespace: capa-system spec: version: v2.1.4 configSecret: name: aws-variables manager: # These top level controller manager flags, supported by all the providers. # These flags come with sensible defaults, thus requiring no or minimal # changes for the most common scenarios. metrics: bindAddress: ":8181" syncPeriod: "500s" fetchConfig: url: https://github.com/kubernetes-sigs/cluster-api-provider-aws/releases deployment: containers: - name: manager args: # These are controller flags that are specific to a provider; usage # is reserved for advanced scenarios only. "--awscluster-concurrency": "12" "--awsmachine-concurrency": "11" ``` -------------------------------- ### DeploymentSpec YAML Example Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/README.md Defines deployment properties for a provider, including replicas, node selectors, tolerations, affinity, containers, service account, and image pull secrets. ```yaml ... spec: deployment: replicas: 2 nodeSelector: disktype: ssd tolerations: - key: "example" operator: "Exists" effect: "NoSchedule" affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - key: "example" operator: "In" values: - "true" containers: - name: "containerA" imageUrl: "example.com/repo/image-name:v1.0.0" args: exampleArg: "value" ... ``` -------------------------------- ### Create Provider Resources in E2E Tests Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/test/e2e/README.md Example of creating a CoreProvider resource using the Kubernetes client within an E2E test. This is a standard pattern for deploying providers. ```go coreProvider := &operatorv1.CoreProvider{ ObjectMeta: metav1.ObjectMeta{ Name: "cluster-api", Namespace: operatorNamespace, }, Spec: operatorv1.CoreProviderSpec{ ProviderSpec: operatorv1.ProviderSpec{ Version: "v1.9.0", }, }, } Expect(bootstrapClusterProxy.GetClient().Create(ctx, coreProvider)).To(Succeed()) ``` -------------------------------- ### Install Cluster API Operator with Docker Provider Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/01_user/02_quick-start.md Installs the Cluster API Operator using Helm, enabling the Docker provider and configuring it to use the previously created credentials secret. The --wait flag is required for the Helm command to function correctly, ensuring webhooks are ready before returning. ```bash helm install capi-operator capi-operator/cluster-api-operator --create-namespace -n capi-operator-system --set infrastructure.docker.enabled=true --set configSecret.name=${CREDENTIALS_SECRET_NAME} --set configSecret.namespace=${CREDENTIALS_SECRET_NAMESPACE} --wait --timeout 90s ``` -------------------------------- ### Helm Installation with Cert-Manager and CAPI Operator Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/README.md Installs cert-manager, the CAPI operator with a modified log level, Core CAPI provider, and Docker infrastructure. Ensure Helm repositories are added and updated before running. ```bash helm repo add jetstack https://charts.jetstack.io --force-update helm repo update helm install cert-manager jetstack/cert-manager --namespace cert-manager --create-namespace --set installCRDs=true helm install capi-operator capi-operator/cluster-api-operator --create-namespace -n capi-operator-system --set infrastructure.docker.version=v1.5.0 --wait --timeout 90s ``` -------------------------------- ### Install Operator with Docker Provider and Wait Flag Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/02_installation/04_helm-chart-installation.md Install the Cluster API operator with a specific version of the Docker infrastructure provider. The `--wait` flag is required for this command to function correctly with providers. ```bash helm install capi-operator capi-operator/cluster-api-operator --create-namespace -n capi-operator-system --set infrastructure.docker.version=v1.4.2 --wait --timeout 90s # core Cluster API with kubeadm bootstrap and control plane providers will also be installed ``` -------------------------------- ### ProviderSpec YAML Example Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/README.md Defines the desired state of a Provider, including version, manager, deployment, config secret, and fetch configuration. ```yaml ... spec: version: "v0.1.0" manager: maxConcurrentReconciles: 5 deployment: replicas: 1 configSecret: name: "provider-secret" fetchConfig: url: "https://github.com/owner/repo/releases" ... ``` -------------------------------- ### ProviderSpec YAML Example Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/03_topics/02_configuration/05_provider-spec-configuration.md Defines the desired state of a provider, including version, manager, deployment, config secret, and fetch configuration. ```yaml ... spec: version: "v0.1.0" manager: maxConcurrentReconciles: 5 deployment: replicas: 1 configSecret: name: "provider-secret" fetchConfig: url: "https://github.com/owner/repo/releases" ... ``` -------------------------------- ### Install cert-manager Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/04_developer/02_guide.md Apply the cert-manager manifest to your management cluster. Ensure the webhook service is ready before proceeding with Cluster API Operator components. ```bash kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.14.2/cert-manager.yaml ``` -------------------------------- ### Add cluster-api-operator Plugin Index to Krew Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/03_topics/03_plugin/01_installation.md Add the plugin index to krew to make the cluster-api-operator plugin available for installation. ```bash kubectl krew index add operator https://github.com/kubernetes-sigs/cluster-api-operator.git ``` -------------------------------- ### ContainerSpec YAML Example Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/03_topics/02_configuration/05_provider-spec-configuration.md Defines properties for a provider's container, including image URL, arguments, environment variables, resources, and command. ```yaml ... spec: deployment: containers: - name: "example-container" imageUrl: "example.com/repo/image-name:v1.0.0" args: exampleArg: "value" env: - name: "EXAMPLE_ENV" value: "example-value" resources: limits: cpu: "1" memory: "1Gi" requests: cpu: "500m" memory: "500Mi" command: - "/bin/bash" ... ``` -------------------------------- ### ContainerSpec YAML Example Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/README.md Specifies properties for a provider's container, including name, image URL, arguments, environment variables, resources, and command. ```yaml ... spec: deployment: containers: - name: "example-container" imageUrl: "example.com/repo/image-name:v1.0.0" args: exampleArg: "value" env: - name: "EXAMPLE_ENV" value: "example-value" resources: limits: cpu: "1" memory: "1Gi" requests: cpu: "500m" memory: "500Mi" command: - "/bin/bash" ... ``` -------------------------------- ### Configure Cluster API Operator Deployment Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/README.md Example of configuring the Cluster API Operator deployment with metrics, leader election, and diagnostics options. Ensure the CAPI_OPERATOR_DIAGNOSTICS_ADDRESS environment variable is set if using diagnostics. ```yaml apiVersion: apps/v1 kind: Deployment metadata: name: cluster-api-operator namespace: capi-operator-system spec: template: spec: containers: - name: manager args: - --metrics-bind-addr=:8080 - --leader-elect - --leader-elect-retry-period=5s - "--diagnostics-address=${CAPI_OPERATOR_DIAGNOSTICS_ADDRESS:=:8443}" - "--insecure-diagnostics=${CAPI_OPERATOR_INSECURE_DIAGNOSTICS:=false}" - --v=5 env:... ``` -------------------------------- ### Get Cluster API Operator Help Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/README.md Command to display help information for the Cluster API Operator, including all available configuration options. Ensure the CAPI_OPERATOR_VERSION is set to the desired version. ```bash export CAPI_OPERATOR_VERSION=v0.3.0 docker run -it --rm registry.k8s.io/capi-operator/cluster-api-operator:${CAPI_OPERATOR_VERSION} /manager --help ``` -------------------------------- ### Patching Provider Manifests with `patches` (RFC 6902 JSON Patch) Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/03_topics/02_configuration/04_patching-provider-manifests.md Apply RFC 6902 JSON patches using `spec.patches` for fine-grained modifications. This example adds an argument to a container in a Deployment. ```yaml --- aspect: operator.cluster.x-k8s.io/v1alpha2 kind: CoreProvider metadata: name: cluster-api namespace: capi-system spec: patches: - patch: | - op: add path: /spec/template/spec/containers/0/args/- value: --additional-sync-machine-labels=topology.kubernetes.io/.* target: group: apps version: v1 kind: Deployment name: capi-controller-manager namespace: capi-system ``` -------------------------------- ### Patching Provider Manifests with `patches` (Strategic Merge Patch) Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/03_topics/02_configuration/04_patching-provider-manifests.md Utilize `spec.patches` with a strategic merge patch to modify provider manifests. This example targets a Service by its kind and applies a label. ```yaml --- aspect: operator.cluster.x-k8s.io/v1alpha2 kind: CoreProvider metadata: name: cluster-api namespace: capi-system spec: patches: - patch: | apiVersion: v1 kind: Service metadata: labels: test-label: test-value target: kind: Service ``` -------------------------------- ### Build Local Book Copy Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/README.md Run this command from the `docs/book` path to build the local copy of the book. ```shell make build ``` -------------------------------- ### Build, Push, and Apply Manifests with Kustomize Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/04_developer/02_guide.md This sequence of commands builds and pushes Docker images, then applies the manifests to your cluster using Kustomize and envsubst for variable substitution. ```bash # Build all the images make docker-build # Push images make docker-push # Apply the manifests kustomize build config/default | ./hack/tools/bin/envsubst | kubectl apply -f - ``` -------------------------------- ### Serve Local Book for Preview Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/README.md Execute this command to serve the book locally at http://localhost:3000/. mdBook will automatically detect changes and refresh the browser. ```shell make serve ``` -------------------------------- ### Run Unit Tests with Make Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/AGENTS.md Execute all unit tests for the project using the make command. ```bash make test ``` -------------------------------- ### Prepare Provider ConfigMap for Multiple Infrastructure Providers from OCI Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/03_topics/03_plugin/02_preload_subcommand.md Fetches and loads manifests for multiple infrastructure providers from an OCI registry. Use multiple `--infrastructure` flags to specify each provider. ```bash kubectl operator preload --infrastructure=aws --infrastructure=vsphere -u my-registry.example.com/infrastructure-provider ``` -------------------------------- ### Build Operator Binary and Docker Image Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/CONTRIBUTING.md Use these make commands to build the operator binary and its Docker image. ```bash # Build the operator binary make build ``` ```bash # Build the Docker image make docker-build ``` -------------------------------- ### Publish with both directory and specific files Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/03_topics/03_plugin/03_publish_subcommand.md Combines publishing manifests from a directory and specific files to the OCI registry. Use `--artifact-url` for the registry, `--dir` for the directory, and `--file` for individual files. ```bash kubectl operator publish -u ttl.sh/${IMAGE_NAME}:5m -d manifests -f metadata.yaml -f infrastructure-components.yaml ``` -------------------------------- ### Publish provider manifests from a directory Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/03_topics/03_plugin/03_publish_subcommand.md Publishes all files in the specified directory to the OCI registry. Use the `--artifact-url` flag for the registry and `--dir` for the manifest directory. ```bash kubectl operator publish -u ttl.sh/${IMAGE_NAME}:5m -d manifests ``` -------------------------------- ### Rename kubectl-operator to clusterctl-operator Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/03_topics/03_plugin/01_installation.md Optionally, rename the installed kubectl-operator binary to clusterctl-operator to use it with clusterctl. ```bash cp ~/.krew/bin/kubectl-operator ~/.krew/bin/clusterctl-operator ``` -------------------------------- ### SecretReference YAML Example Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/README.md References a secret object by name and optionally namespace, used for provider configuration. ```yaml ... spec: configSecret: name: capa-secret namespace: capa-system ... ``` -------------------------------- ### Publish with OCI authentication using environment variables Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/03_topics/03_plugin/03_publish_subcommand.md Publishes manifests to an OCI registry while using environment variables for authentication. Set `OCI_USERNAME` and `OCI_PASSWORD` before running the command. ```bash export OCI_USERNAME=myusername export OCI_PASSWORD=mypassword kubectl operator publish -u ttl.sh/${IMAGE_NAME}:5m -d manifests ``` -------------------------------- ### SecretReference YAML Example Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/03_topics/02_configuration/05_provider-spec-configuration.md References a secret object by name and optionally namespace, used for provider configuration. ```yaml ... spec: configSecret: name: capa-secret namespace: capa-system ... ``` -------------------------------- ### Run E2E Tests with Make Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/AGENTS.md Execute end-to-end tests for the project using the make command. ```bash make test-e2e ``` -------------------------------- ### ManagerSpec YAML Example Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/03_topics/02_configuration/05_provider-spec-configuration.md Configures controller manager properties for a provider, such as concurrency, verbosity, and feature gates. ```yaml ... spec: manager: profilerAddress: "localhost:6060" maxConcurrentReconciles: 5 verbosity: 1 featureGates: FeatureA: true FeatureB: false ... ``` -------------------------------- ### Upgrade cluster-api-operator Plugin Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/03_topics/03_plugin/01_installation.md Upgrade the installed plugin to the latest release using the kubectl krew upgrade command. ```bash kubectl krew upgrade ``` -------------------------------- ### Load Provider Manifests from Existing Cluster Providers Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/03_topics/03_plugin/02_preload_subcommand.md Discovers all existing providers in the cluster and prepares ConfigMaps containing their manifests. Use the `-e` or `--existing` flag for this operation. ```bash kubectl operator preload -e ``` -------------------------------- ### Prepare Provider ConfigMap from GitHub for Specific Infrastructure Provider Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/03_topics/03_plugin/02_preload_subcommand.md Fetches the latest available version of a specified infrastructure provider from a GitHub repository release and creates a ConfigMap. The `-u` flag specifies the GitHub release URL. ```bash kubectl operator preload --infrastructure=aws -u https://github.com/kubernetes-sigs/cluster-api-provider-aws/releases/latest/infrastructure-components.yaml ``` -------------------------------- ### Promote images to production registry Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/04_developer/01_release.md Use the 'make promote-images' target to create a PR for promoting images to the production registry. Ensure GITHUB_TOKEN and USER_FORK are exported. ```bash # Export the tag of the release to be cut, e.g.: export GITHUB_TOKEN= export USER_FORK= make promote-images ``` -------------------------------- ### Run Local E2E Tests Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/test/e2e/README.md Quickly run the full E2E suite locally by creating a Kind cluster, deploying cert-manager and the operator. ```bash make test-e2e-local ``` -------------------------------- ### Check Provider Conditions with HaveStatusConditionsTrue Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/test/e2e/README.md Verify that specific conditions on a provider resource are met. This helper is used to assert the state of provider installations. ```go HaveStatusConditionsTrue( provider, operatorv1.PreflightCheckCondition, operatorv1.ProviderInstalledCondition, ) ``` -------------------------------- ### Prepare Provider ConfigMap with Specific Version from GitHub Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/03_topics/03_plugin/02_preload_subcommand.md Loads a specific version of an infrastructure provider from a GitHub release into the default namespace. When using a Git release as the source, the version must be specified within the URL. ```bash kubectl operator preload --infrastructure=aws -u https://github.com/kubernetes-sigs/cluster-api-provider-aws/releases/v2.3.0/infrastructure-components.yaml ``` -------------------------------- ### Override CAPA Deployment Container Image Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/03_topics/02_configuration/03_examples-of-api-usage.md Install the AWS infrastructure provider and override the default container image for the CAPA deployment manager. ```yaml --- apiVersion: operator.cluster.x-k8s.io/v1alpha2 kind: InfrastructureProvider metadata: name: aws namespace: capa-system spec: version: v2.1.4 configSecret: name: aws-variables deployment: containers: - name: manager imageUrl: "gcr.io/myregistry/capa-controller:v2.1.4-foo" ``` -------------------------------- ### Generate Mocks and Deep Copy with Make Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/AGENTS.md Run make targets to generate necessary mocks and deep copy functions for the project. ```bash make generate ``` -------------------------------- ### Enable Port-Forwarding for pprof Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/04_developer/03_profiling.md Use `kubectl port-forward` to make the pprof server accessible on your local machine. Replace `` with your actual namespace. ```bash kubectl port-forward deployment/capi-operator -n 6060 ``` -------------------------------- ### Prepare Provider ConfigMap from OCI for Specific Infrastructure Provider Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/03_topics/03_plugin/02_preload_subcommand.md Fetches the latest available version of a specified infrastructure provider from an OCI registry and creates a ConfigMap. The `-u` flag specifies the OCI artifact URL. ```bash kubectl operator preload --infrastructure=aws -u my-registry.example.com/infrastructure-provider ``` -------------------------------- ### Prepare Provider ConfigMap with Specific Version from OCI Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/03_topics/03_plugin/02_preload_subcommand.md Loads a specific version of an infrastructure provider from an OCI registry into the default namespace. The version is specified after the provider name with a colon. ```bash kubectl operator preload --infrastructure=aws::v2.3.0 -u my-registry.example.com/infrastructure-provider ``` -------------------------------- ### Run Tests and Linters Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/CONTRIBUTING.md Execute unit tests, linters, and end-to-end tests using make commands. E2E tests require a Kubernetes cluster. ```bash # Run unit tests make test ``` ```bash # Run linters make lint ``` ```bash # Run E2E tests (requires a cluster) make test-e2e ``` -------------------------------- ### Delete Cluster API Providers Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/README.md Commands to remove installed CoreProvider and InfrastructureProvider resources from the cluster. This will also delete all related Kubernetes objects managed by these providers. ```bash kubectl delete coreprovider cluster-api kubectl delete infrastructureprovider azure ``` -------------------------------- ### Prepare Provider ConfigMap with Specific Version and Namespace from OCI Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/03_topics/03_plugin/02_preload_subcommand.md Loads a specific version of an infrastructure provider into a custom namespace from an OCI registry. The namespace and version are specified after the provider name with colons. ```bash kubectl operator preload --infrastructure=aws:custom-namespace:v2.3.0 -u my-registry.example.com/infrastructure-provider ``` -------------------------------- ### Delete Infrastructure and Core Providers Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/03_topics/01_capi-providers-lifecycle/04_deleting-provider.md Use these kubectl commands to delete the installed infrastructure and core Cluster API providers. This action removes all related Kubernetes objects. ```bash kubectl delete infrastructureprovider azure kubectl delete coreprovider cluster-api ``` -------------------------------- ### Prepare Provider ConfigMap with Custom Namespace from GitHub Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/03_topics/03_plugin/02_preload_subcommand.md Loads the latest version of a specified infrastructure provider into a custom namespace from a GitHub release. The namespace is specified after the provider name with a colon. ```bash kubectl operator preload --infrastructure=aws:custom-namespace -u https://github.com/kubernetes-sigs/cluster-api-provider-aws/releases/latest/infrastructure-components.yaml ``` -------------------------------- ### Run Linters with Make Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/AGENTS.md Execute linters to check code style and quality using the make command. ```bash make lint ``` -------------------------------- ### Deploy Cluster API AWS Provider Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/01_user/02_quick-start.md Deploys the Cluster API AWS provider with a specific version and configures it to use a credentials secret. This example specifies version v2.1.4. ```yaml --- apiVersion: operator.cluster.x-k8s.io/v1alpha2 kind: InfrastructureProvider metadata: name: aws namespace: capa-system spec: version: v2.1.4 configSecret: name: credentials-secret ``` -------------------------------- ### GitHub Actions: Book Publishing Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/05_reference/05_ci-jobs.md Deploys the operator book to GitHub Pages. ```yaml name: book publishing on: push: branches: - main jobs: publish-book-job: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v3 - name: Publish Operator Book uses: "kubernetes/test-infra/actions/publish-book" env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} ``` -------------------------------- ### Fetch Provider Components from URL Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/03_topics/02_configuration/01_air-gapped-environtment.md Configure the InfrastructureProvider to fetch components directly from a specified URL. This is useful if components are hosted in a repository. ```yaml apiVersion: operator.cluster.x-k8s.io/v1alpha2 kind: InfrastructureProvider metadata: name: azure namespace: capz-system spec: version: v1.9.3 configSecret: name: azure-variables fetchConfig: url: "https://my-internal-repo.example.com/providers/azure/v1.9.3.yaml" ``` -------------------------------- ### Use Patch Helper for Updates Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/AGENTS.md Always use the patch helper for updates to ensure proper handling of object modifications. Initialize the helper with the object and client, and defer the Patch call. ```go patchHelper, err := patch.NewHelper(provider, r.Client) if err != nil { return ctrl.Result{}, err } deferr := func() { if err := patchHelper.Patch(ctx, provider); err != nil { reterr = kerrors.NewAggregate([]error{reterr, err}) } }() ``` -------------------------------- ### GitHub Actions: golangci-lint Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/05_reference/05_ci-jobs.md Runs golangci-lint for Go code analysis. Can be executed locally using 'make lint'. ```yaml name: PR golangci-lint jobs: golangci-lint-job: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v3 - name: Setup Go uses: actions/setup-go@v4 with: go-version: '1.20' - name: golangci-lint uses: golangci/golangci-lint-action@v3 with: args: --timeout=5m ``` -------------------------------- ### Structure Tests with Ginkgo Containers Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/test/e2e/README.md Organize E2E tests using Ginkgo's Describe, Context, and It blocks for BDD-style test structuring. Use Ordered for sequential tests that share state. ```go var _ = Describe("My Feature", func() { It("should do something", func() { // Test implementation }) }) ``` ```go var _ = Describe("Sequential tests", Ordered, func() { It("step 1", func() { /* ... */ }) It("step 2", func() { /* ... */ }) }) ``` -------------------------------- ### Add New E2E Test File Structure Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/test/e2e/README.md Boilerplate for creating a new E2E test file. Includes necessary build tags, package declaration, and imports for Ginkgo, Gomega, and Cluster API Operator types. ```go //go:build e2e package e2e import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" operatorv1 "sigs.k8s.io/cluster-api-operator/api/v1alpha2" . "sigs.k8s.io/cluster-api-operator/test/framework" ) ``` -------------------------------- ### Create Cloud Provider Credentials Secret Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/01_user/02_quick-start.md Creates a Kubernetes secret to store cloud provider credentials, which Cluster API Operator uses instead of environment variables. This example uses AWS credentials. ```bash export CREDENTIALS_SECRET_NAME="credentials-secret" export CREDENTIALS_SECRET_NAMESPACE="default" kubectl create secret generic "${CREDENTIALS_SECRET_NAME}" --from-literal=AWS_B64ENCODED_CREDENTIALS="${AWS_B64ENCODED_CREDENTIALS}" --namespace "${CREDENTIALS_SECRET_NAMESPACE}" ``` -------------------------------- ### Update Helm and Krew Repositories Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/04_developer/01_release.md Switch to the main branch and execute the make command to update the operator Helm chart repository and the local krew plugin manifest index. ```bash git checkout main make update-helm-plugin-repo ``` -------------------------------- ### Run E2E Tests on Existing Cluster Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/test/e2e/README.md Execute the E2E test suite against an already provisioned Kubernetes cluster. ```bash USE_EXISTING_CLUSTER=true make test-e2e ``` -------------------------------- ### Prepare Provider ConfigMap with Custom Namespace from OCI Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/03_topics/03_plugin/02_preload_subcommand.md Loads the latest version of a specified infrastructure provider into a custom namespace from an OCI registry. The namespace is specified after the provider name with a colon. ```bash kubectl operator preload --infrastructure=aws:custom-namespace -u my-registry.example.com/infrastructure-provider ``` -------------------------------- ### Publish specific manifest files Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/03_topics/03_plugin/03_publish_subcommand.md Publishes only the listed manifest files to the OCI registry. Use the `--artifact-url` flag for the registry and `--file` for each manifest file. ```bash kubectl operator publish -u ttl.sh/${IMAGE_NAME}:5m -f metadata.yaml -f infrastructure-components.yaml ``` -------------------------------- ### Create and push signed tags Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/04_developer/01_release.md Create local signed and test tags, then push them to the upstream repository. The 'test' tag must not be annotated. ```bash # Create tags locally # Warning: The test tag MUST NOT be an annotated tag. git tag -s -a ${RELEASE_TAG} -m ${RELEASE_TAG} git tag test/${RELEASE_TAG} # Push tags # Note: `upstream` must be the remote pointing to `github.com/kubernetes-sigs/cluster-api-operator`. git push upstream ${RELEASE_TAG} git push upstream test/${RELEASE_TAG} ``` -------------------------------- ### Prow Plugins Configuration: lgtm Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/05_reference/05_ci-jobs.md Enables retaining the 'lgtm' (Looks Good To Me) status through squash merges. ```yaml lgtm: # When enabled, LGTMs are retained through squash merges. preserve_lgtms: true ``` -------------------------------- ### Configure InfrastructureProvider using OCI Artifact Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/03_topics/02_configuration/01_air-gapped-environtment.md Configure the `fetchConfig.oci` field to pull provider components directly from an OCI registry. This is useful for air-gapped environments where direct internet access is not available. ```yaml apiVersion: operator.cluster.x-k8s.io/v1alpha2 kind: InfrastructureProvider metadata: name: azure namespace: capz-system spec: version: v1.9.3 configSecret: name: azure-variables fetchConfig: oci: "my-oci-registry.example.com/my-provider:v1.9.3" ``` -------------------------------- ### Fetch Provider Components from OCI Registry Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/03_topics/02_configuration/01_air-gapped-environtment.md Configure the InfrastructureProvider to fetch components from an OCI registry. Ensure the `configSecret` contains OCI credentials. ```yaml apiVersion: operator.cluster.x-k8s.io/v1alpha2 kind: InfrastructureProvider metadata: name: azure namespace: capz-system spec: version: v1.9.3 configSecret: name: azure-variables # Secret containing the OCI registry credentials fetchConfig: oci: "my-oci-registry.example.com/my-provider:v1.9.3" # Reference to the OCI artifact (provider) ``` -------------------------------- ### Use clusterctl-operator Plugin Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/03_topics/03_plugin/01_installation.md After renaming, you can use the plugin with clusterctl by running clusterctl operator --help. ```bash clusterctl operator --help ``` -------------------------------- ### ConfigMap and CoreProvider with Additional Manifests Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/03_topics/02_configuration/02_injecting-additional-manifests.md Define a ConfigMap containing additional manifests and reference it in the CoreProvider spec. The ConfigMap's `data.manifests` key holds the YAML content, and the CoreProvider's `spec.additionalManifests` field points to this ConfigMap by name and namespace. ```yaml --- apiVersion: v1 kind: ConfigMap metadata: name: additional-manifests namespace: capi-system data: manifests: | # Additional manifests go here --- apiVersion: operator.cluster.x-k8s.io/v1alpha2 kind: CoreProvider metadata: name: cluster-api namespace: capi-system spec: additionalManifests: name: additional-manifests ``` -------------------------------- ### Prow Plugins Configuration: plugins Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/05_reference/05_ci-jobs.md Enables the 'require-matching-label' plugin for managing PR labels. ```yaml plugins: # Enable the 'require-matching-label' plugin. - require-matching-label ``` -------------------------------- ### Publish multiple providers and versions into a single OCI image Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/03_topics/03_plugin/03_publish_subcommand.md Publishes versioned manifests for multiple providers into a single OCI image. Ensure your directory structure matches the expected layout for versioned components and metadata. ```bash capioperator publish -u my-registry.example.com/providers:latest -d manifests \ ``` -------------------------------- ### Load Core Provider Manifests from OCI Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/03_topics/03_plugin/02_preload_subcommand.md Loads the cluster-api core provider manifests from an OCI source. If no version is specified, the latest release is used. ```bash kubectl operator preload --core cluster-api ``` -------------------------------- ### GitHub Actions: Release Workflow Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/05_reference/05_ci-jobs.md Creates a GitHub release with release notes when tags are pushed. ```yaml name: release on: push: tags: - "v*.*.*" jobs: release-job: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v3 - name: Create GitHub Release uses: "kubernetes/test-infra/actions/release" env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} ``` -------------------------------- ### Create ConfigMap from Archived Data Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/03_topics/02_configuration/01_air-gapped-environtment.md Create a Kubernetes ConfigMap from archived component files and a metadata file using `kubectl create configmap`. The `components.gz` file is treated as compressed data. ```sh kubectl create configmap v1.9.3 -n capz-system --from-file=components=components.gz --from-file=metadata=metadata.yaml ``` -------------------------------- ### Fetch Azure Provider Components from Custom Repository Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/03_topics/02_configuration/03_examples-of-api-usage.md Configure the Azure infrastructure provider to fetch its components from a specific, non-default Git repository URL. ```yaml --- apiVersion: operator.cluster.x-k8s.io/v1alpha2 kind: InfrastructureProvider metadata: name: myazure namespace: capz-system spec: version: v1.9.3 configSecret: name: azure-variables fetchConfig: url: https://github.com/myorg/awesome-azure-provider/releases ``` -------------------------------- ### AddonProvider Go Struct Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/05_reference/06_providers.md Defines the AddonProvider API type, including its metadata, spec, and status. ```golang type AddonProvider struct { metav1.TypeMeta `json:",inline" metav1.ObjectMeta `json:"metadata,omitempty" Spec AddonProviderSpec `json:"spec,omitempty" Status AddonProviderStatus `json:"status,omitempty" } ``` -------------------------------- ### Clone the repository Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/04_developer/01_release.md Clone the Cluster API Operator repository locally to begin the release process. ```bash git clone git@github.com:kubernetes-sigs/cluster-api-operator.git ``` -------------------------------- ### Generate Code and Manifests Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/CONTRIBUTING.md Regenerate API code and manifests after modifying API types in `api/v1alpha2/`. ```bash make generate manifests ``` -------------------------------- ### v1alpha1 ImageMeta to v1alpha2 imageURL Conversion Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/04_developer/01_version_migration/01_v1alpha1-to-v1alpha2.md Illustrates the change from a structured ImageMeta object in v1alpha1 to a simple imageURL string in v1alpha2 for container image specifications. ```yaml spec: deployment: containers: - name: manager image: repository: "example.com/repo" name: "image-name" tag: "v1.0.0" ``` ```yaml spec: deployment: containers: - name: manager imageURL: "example.com/repo/image-name:v1.0.0" ``` -------------------------------- ### Configure Helm Values for Profiling Source: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/docs/book/src/04_developer/03_profiling.md Customize profiling settings by modifying these values in your `values.yaml` file. Profiling is enabled by default. ```yaml profilerAddress: ":6060" contentionProfiling: true ```