### Feature Gate Usage Examples Source: https://github.com/rancher/turtles/blob/main/_autodocs/api-reference/utilities.md Demonstrates how to check if a feature is enabled and how to enable a feature during setup. ```go // Check if feature is enabled if feature.Gates.Enabled(feature.UIPlugin) { // UIPlugin feature is enabled // Initialize UI plugin reconciler } // Enable feature during setup feature.MutableGates.Set(feature.AgentTLSMode, true) ``` -------------------------------- ### Provider Configuration Example Source: https://github.com/rancher/turtles/blob/main/_autodocs/api-reference/clusterctlconfig.md Example demonstrating how to configure different providers (InfrastructureProvider, BootstrapProvider, ControlPlaneProvider) with their respective URLs. ```yaml providers: - name: aws type: InfrastructureProvider url: "https://github.com/kubernetes-sigs/cluster-api-provider-aws/releases/download/v2.3.0/infrastructure-components.yaml" - name: kubeadm type: BootstrapProvider url: "https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.9.3/bootstrap-components.yaml" - name: kubeadm type: ControlPlaneProvider url: "https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.9.3/control-plane-components.yaml" ``` -------------------------------- ### Install krew and crust-gather Source: https://github.com/rancher/turtles/blob/main/test/e2e/README.md Installs the krew plugin manager and the crust-gather kubectl plugin for artifact collection. Ensure krew is installed correctly before proceeding. ```bash ( set -x; cd "$(mktemp -d)" && OS="$(uname | tr '[:upper:]' '[:lower:]')" && ARCH="$(uname -m | sed -e 's/x86_64/amd64/' -e 's/\(arm\)\(64\)?.*/\1\2/' -e 's/aarch64$/arm64/)" && KREW="krew-${OS}_${ARCH}" && curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/${KREW}.tar.gz" && tar zxvf "${KREW}.tar.gz" && ./"${KREW}" install krew ) kubectl krew install crust-gather ``` -------------------------------- ### Complete ClusterctlConfig Example Source: https://github.com/rancher/turtles/blob/main/_autodocs/api-reference/clusterctlconfig.md A full example of a ClusterctlConfig resource, demonstrating the use of both image overrides and custom provider configurations. ```yaml apiVersion: turtles-capi.cattle.io/v1alpha1 kind: ClusterctlConfig metadata: name: clusterctl-config namespace: cattle-cluster-api-provider spec: images: - name: all repository: my-registry.example.com/capi tag: v1.9.3 - name: aws repository: my-registry.example.com/aws-provider tag: v2.3.0 providers: - name: aws type: InfrastructureProvider url: "https://internal-mirror.example.com/capi-providers/aws-v2.3.0.yaml" - name: kubeadm type: BootstrapProvider url: "https://internal-mirror.example.com/capi-providers/kubeadm-bootstrap-v1.9.3.yaml" - name: kubeadm type: ControlPlaneProvider url: "https://internal-mirror.example.com/capi-providers/kubeadm-control-plane-v1.9.3.yaml" ``` -------------------------------- ### Verify UI Plugin Installation Source: https://github.com/rancher/turtles/blob/main/_autodocs/workflows.md Confirm that the UI plugin has been successfully installed by checking for its associated resources and verifying that its Pod is running. ```bash # Check for UI plugin resources kubectl get uiplugin -A # Verify plugin Pod running kubectl get pods -n capi-system | grep ui-plugin ``` -------------------------------- ### Finalizer Examples Source: https://github.com/rancher/turtles/blob/main/_autodocs/architecture.md Examples of finalizers used to manage resource deletion and prevent orphaned resources. ```text - "capicluster.turtles.cattle.io" — Added to CAPI clusters and Rancher clusters - Removed by cleanup reconciler when appropriate - Prevents orphaned resources ``` -------------------------------- ### Run the Examples CLI Tool Source: https://github.com/rancher/turtles/blob/main/examples/README.md Execute the main program of the CLI tool by providing a search key for cluster classes. ```bash go run main.go ``` -------------------------------- ### Provider Installation Flow Source: https://github.com/rancher/turtles/blob/main/_autodocs/architecture.md This diagram outlines the process of installing and managing CAPI providers using the CAPIProvider resource. ```text CAPIProvider Created ↓ OperatorReconciler.SetupWithManager() └─ CAPIProviderReconciler.Reconcile() ├─ Convert Type to provider kind ├─ Create/update ConfigSecret ├─ Apply credentials ├─ Sync environment variables └─ Trigger CAPI Operator installation ↓ Provider components deployed to cluster ↓ Provider phase transitions: Pending → Provisioning → Ready ``` -------------------------------- ### Example Usage of Annotation Constants Source: https://github.com/rancher/turtles/blob/main/_autodocs/api-reference/utilities.md Demonstrates how to apply annotation constants to a cluster object. ```go cluster.Annotations[annotations.ClusterImportedAnnotation] = "true" cluster.Annotations[annotations.ClusterDescriptionAnnotation] = "My CAPI Cluster" cluster.Annotations[annotations.UpstreamSystemAgentAnnotation] = "true" ``` -------------------------------- ### Install Build Dependencies Source: https://github.com/rancher/turtles/blob/main/docs/image-builder/ec2-kubeadm.md Install Packer, Ansible, and other necessary tools for the AMI build process. This command also initializes Packer plugins. ```bash make deps-ami ``` -------------------------------- ### Apply Extracted Examples with Kubectl Source: https://github.com/rancher/turtles/blob/main/examples/README.md Pipe the output of the CLI tool to kubectl apply to deploy the extracted cluster class examples. ```bash go run main.go | kubectl apply -f - ``` -------------------------------- ### CAPIProvider Example Source: https://github.com/rancher/turtles/blob/main/_autodocs/api-reference/capiprovider.md An example of a CAPIProvider resource configuration for the AWS provider, specifying version, credentials, features, and variables. ```yaml apiVersion: turtles-capi.cattle.io/v1alpha1 kind: CAPIProvider metadata: name: aws-provider spec: name: aws type: infrastructure version: v2.3.0 credentials: rancherCloudCredential: my-aws-credential features: machinePool: true clusterResourceSet: true clusterTopology: true variables: AWS_B64ENCODED_CREDENTIALS: "LS0tLS1CRUdJTi..." enableAutomaticUpdate: false ``` -------------------------------- ### Install Build Dependencies Source: https://github.com/rancher/turtles/blob/main/docs/image-builder/gcp-kubeadm.md Install necessary build tools including Python, Ansible, and Packer, along with initializing Packer plugins. For macOS users, ensure the tools installed in .local/bin are added to your PATH. ```bash make deps-gce ``` ```bash export PATH="$(pwd)/.local/bin:$PATH" ``` -------------------------------- ### Backport PR Command Example Source: https://github.com/rancher/turtles/blob/main/docs/release-automation-workflows.md An example of the backport command, specifying a milestone and a target branch for the backport. ```bash /backport v2.14.0 release/v0.26 ``` -------------------------------- ### List Available Cluster Classes Source: https://github.com/rancher/turtles/blob/main/examples/README.md Use the -l flag to list all available cluster class names from the examples. ```bash go run main.go -l ``` -------------------------------- ### Run the Latest Version of the Examples CLI Tool Source: https://github.com/rancher/turtles/blob/main/examples/README.md Execute the most recent version of the CLI tool directly from the module path without local cloning. ```bash go run github.com/rancher/turtles/examples@latest ``` -------------------------------- ### Install Build Dependencies Source: https://github.com/rancher/turtles/blob/main/docs/image-builder/vsphere-kubeadm.md Install required build tools including Packer and Ansible using the provided Makefile. ```bash make deps-ova ``` -------------------------------- ### Run the Examples CLI Tool from a Specific Tag Source: https://github.com/rancher/turtles/blob/main/examples/README.md Execute a specific tagged version of the CLI tool for reproducible results. Replace with the desired tag name. ```bash go run github.com/rancher/turtles/examples@ ``` -------------------------------- ### Manager Startup Flags Source: https://github.com/rancher/turtles/blob/main/_autodocs/API-SUMMARY.md Lists the configuration flags available for starting the manager, including their types, default values, and purposes. ```text | Flag | Type | Default | Purpose | |------|------|---------|---------| | `--metrics-bind-addr` | string | `:8080` | Metrics endpoint address | | `--health-addr` | string | `:9440` | Health check endpoint address | | `--profiler-address` | string | Empty | pprof profiler address | | `--leader-elect` | bool | false | Enable leader election | | `--leader-elect-lease-duration` | duration | 15s | Lease acquisition interval | | `--leader-elect-renew-deadline` | duration | 10s | Lease renewal deadline | | `--leader-elect-retry-period` | duration | 2s | Lease retry period | | `--watch-filter` | string | Empty | CAPI watch label value filter | | `--sync-period` | duration | 2m | Resource sync interval | | `--concurrency` | int | 1 | Per-controller parallelism | | `--manager-concurrency` | int | 15 | Global parallelism | | `--insecure-skip-verify` | bool | false | Skip TLS verification | ``` -------------------------------- ### Example: Release Rancher Turtles v0.26.0 to rancher/rancher Source: https://github.com/rancher/turtles/blob/main/docs/release-automation-workflows.md Example of triggering the release-against-rancher workflow to update Rancher Turtles from v0.25.0 to v0.26.0 in the release/v2.14 branch of rancher/rancher. ```yaml rancher_ref: release/v2.14 prev_turtles: v0.25.0 new_turtles: v0.26.0 bump_major: true ``` -------------------------------- ### Example ClusterctlConfig Resource Creation Source: https://github.com/rancher/turtles/blob/main/_autodocs/api-reference/clusterctlconfig-reconciler.md A sample ClusterctlConfig resource that a user might create to define image overrides. ```yaml apiVersion: turtles-capi.cattle.io/v1alpha1 kind: ClusterctlConfig metadata: name: clusterctl-config namespace: cattle-cluster-api-provider spec: images: - name: all repository: internal-registry ``` -------------------------------- ### Image Override Example Source: https://github.com/rancher/turtles/blob/main/_autodocs/api-reference/clusterctlconfig.md An example of how to configure image overrides for providers, including a general override for all images and specific overrides for the 'aws' provider. ```yaml images: - name: all repository: internal-registry.example.com/capi-providers tag: v1.9.3 - name: aws repository: internal-registry.example.com/aws tag: v2.3.0 ``` -------------------------------- ### Create Kubernetes Configuration File Source: https://github.com/rancher/turtles/blob/main/docs/image-builder/gcp-kubeadm.md Create a JSON configuration file specifying the desired Kubernetes version and related details for the image build. This example uses Kubernetes v1.33.5. ```bash cat > my-k8s-config.json < 0 { // Will be retried after specified duration } ``` -------------------------------- ### Search for a Specific Cluster Class Source: https://github.com/rancher/turtles/blob/main/examples/README.md Provide a cluster class name as a search key to find a specific example. ```bash go run main.go azure-aks ``` -------------------------------- ### Example: Release Rancher Turtles v0.26.0 to rancher/charts Source: https://github.com/rancher/turtles/blob/main/docs/release-automation-workflows.md Example of triggering the release-against-charts workflow to update Rancher Turtles to v0.26.0 in the dev-v2.14 branch of rancher/charts, following a previous version of v0.26.0-rc.0. ```yaml charts_ref: dev-v2.14 prev_turtles: v0.26.0-rc.0 new_turtles: v0.26.0 bump_major: false ``` -------------------------------- ### Apply All Azure Example Cluster Classes from a Tag Source: https://github.com/rancher/turtles/blob/main/examples/README.md Apply all cluster classes matching the 'azure' regex from a tagged version of the CLI tool to a custom namespace. Replace with the target namespace. ```bash go run github.com/rancher/turtles/examples@ -r azure | kubectl apply -f -n - ``` -------------------------------- ### Create and Push Release Tags Source: https://github.com/rancher/turtles/blob/main/docs/release.md Create signed and annotated tags locally for the release, including specific prefixes for testing and examples, and then push these tags to the upstream repository. ```bash # Create tags locally git tag -s -a ${RELEASE_TAG} -m ${RELEASE_TAG} git tag -s -a test/${RELEASE_TAG} -m "Testing framework ${RELEASE_TAG}" git tag -s -a examples/${RELEASE_TAG} -m "ClusterClass examples ${RELEASE_TAG}" # Push tags git push upstream ${RELEASE_TAG} git push upstream test/${RELEASE_TAG} git push upstream examples/${RELEASE_TAG} ``` -------------------------------- ### Add Local Binaries to PATH Source: https://github.com/rancher/turtles/blob/main/docs/image-builder/vsphere-kubeadm.md If on macOS, add the locally installed build tools to your PATH environment variable. ```bash export PATH="$(pwd)/.local/bin:$PATH" ``` -------------------------------- ### ConfigSecret Contents Example Source: https://github.com/rancher/turtles/blob/main/_autodocs/api-reference/operator-provider.md Illustrates the structure and potential contents of a ConfigSecret managed by the reconciler, including clusterctl configuration and environment variables. ```yaml apiVersion: v1 kind: Secret metadata: name: namespace: type: Opaque stringData: clusterctl-move: | # Clusterctl move configuration clusterctl: | # Clusterctl provider configuration # Environment variables CLUSTER_TOPOLOGY: "true" EXP_CLUSTER_RESOURCE_SET: "true" EXP_MACHINE_POOL: "true" # User-provided variables ... ``` -------------------------------- ### Run Full E2E Tests Source: https://github.com/rancher/turtles/blob/main/test/e2e/README.md Execute the main E2E test suite from the project root directory. This command installs dependencies, builds a Docker image, generates a release chart, runs tests, and collects artifacts. ```bash make test-e2e ``` -------------------------------- ### SetupWithManager for CAPICleanupReconciler Source: https://github.com/rancher/turtles/blob/main/_autodocs/api-reference/capi-cleanup.md Configures the CAPICleanupReconciler with the controller manager, specifying concurrency and watch filters. Use this to integrate the cleanup reconciler into your controller runtime setup. ```go if err := (&controllers.CAPICleanupReconciler{ Client: mgr.GetClient(), Scheme: mgr.GetScheme(), }).SetupWithManager(ctx, mgr, controller.Options{ MaxConcurrentReconciles: 5, }); err != nil { return err } ``` -------------------------------- ### Add Local Binaries to PATH Source: https://github.com/rancher/turtles/blob/main/docs/image-builder/ec2-kubeadm.md If you are on macOS, the build dependencies are installed in a local directory. Add this directory to your PATH to ensure the tools can be found. ```bash export PATH=$PWD/.local/bin:$PATH ``` -------------------------------- ### Apply a Specific Cluster Class from a Specific Tag Source: https://github.com/rancher/turtles/blob/main/examples/README.md Apply examples for a specific cluster class (e.g., azure-aks) from a tagged version of the CLI tool to the default namespace. ```bash go run github.com/rancher/turtles/examples@ azure-aks | kubectl apply -f - ``` -------------------------------- ### Create CAPIProvider Resource Source: https://github.com/rancher/turtles/blob/main/_autodocs/workflows.md Define and create a CAPIProvider resource to install a specific CAPI provider (e.g., AWS). Ensure the `rancherCloudCredential` matches your created credential. ```yaml apiVersion: turtles-capi.cattle.io/v1alpha1 kind: CAPIProvider metadata: name: aws-provider spec: name: aws type: infrastructure version: v2.3.0 credentials: rancherCloudCredential: my-aws-credential features: machinePool: true clusterResourceSet: true clusterTopology: true variables: EXP_MACHINE_POOL: "true" EXP_CLUSTER_RESOURCE_SET: "true" EXP_CLUSTER_TOPOLOGY: "true" ``` -------------------------------- ### CAPIProviderStatus Definition Source: https://github.com/rancher/turtles/blob/main/_autodocs/api-reference/capiprovider.md Defines the status fields for a CAPIProvider resource, including provisioning phase, environment variables, and installed version. ```go type CAPIProviderStatus struct { // Embedded ProviderStatus from upstream CAPI Operator ProviderStatus operatorv1.ProviderStatus `json:",inline" // Phase of provider provisioning Phase Phase `json:"phase,omitempty" // Environment variables in ConfigSecret Variables map[string]string `json:"variables,omitempty" // Actual provider name Name string `json:"name,omitempty" } ``` -------------------------------- ### Enable Debug Logging via Deployment Args Source: https://github.com/rancher/turtles/blob/main/_autodocs/errors-and-troubleshooting.md Configure debug logging for the Rancher Turtles operator by modifying the deployment arguments. Increase the verbosity level (0-4) to get more detailed logs. ```yaml spec: containers: - name: manager args: - -v=2 # Increase verbosity (0-4) ``` -------------------------------- ### CAPIProvider Resource Specification Source: https://github.com/rancher/turtles/blob/main/docs/adr/0007-rancher-turtles-public-api.md Example specification of the CAPIProvider custom resource. This resource is used to template CAPI Operator manifests, map Rancher credentials, and ensure GitOps compatibility. It defines the provider kind, configuration secrets, and features to be provisioned. ```yaml apiVersion: turtles-capi.cattle.io/v1alpha1 kind: CAPIProvider metadata: name: aws-infra namespace: default # Resource is namespace scoped. spec: name: aws # Defines the provider kind to provision. type: infrastructure # CAPI Provider resource kind to provision. variables: # Additional environment variables to be declared inside the referenced spec.configSecret CAPA_LOGLEVEL: "4" configSecret: name: aws-credentials # This secret will be created or adjusted based on the content of the spec.features and spec.variables, without overriding non-overlapping content. credentials: rancherCloudCredential: user-credential # Rancher secret content will be translated to CAPI Operator environment secret. features: # Additional features to be declared inside the referenced spec.configSecret. clusterResourceSet: true clusterTopology: true machinePool: true status: phase: Pending # Current state of the provisioning. variables: # Variables batch appended to the CAPI Provider secret. CLUSTER_TOPOLOGY: "true" EXP_CLUSTER_RESOURCE_SET: "true" EXP_MACHINE_POOL: "true" CAPA_LOGLEVEL: "4" conditions: ... # A list of conditions reflecting the current status of applied resources. ``` -------------------------------- ### Startup Sequence Steps Source: https://github.com/rancher/turtles/blob/main/_autodocs/architecture.md Outlines the sequential steps involved in the startup process of the application. ```text 1. Flag Parsing — Read command-line configuration 2. Logger Setup — Initialize structured logging 3. Scheme Registration — Register all API types 4. Manager Creation — Initialize controller manager 5. Cache Configuration — Setup resource watching 6. Health Checks — Add readiness/liveness probes 7. Reconciler Setup — Register all controllers 8. Manager Start — Begin reconciliation loops ``` -------------------------------- ### Configure Go Workspace and Download Dependencies Source: https://github.com/rancher/turtles/blob/main/examples/README.md Set up the Go workspace and download necessary dependencies before running the CLI tool. ```bash go work use ./ go mod download ``` -------------------------------- ### Initialize and Use Go Workspace for E2E Tests Source: https://github.com/rancher/turtles/blob/main/test/e2e/README.md Set up a multi-module Go workspace for E2E tests by initializing the workspace and adding test directories. This may affect the vendoring process. ```bash go work init go work use ./test ./ ``` -------------------------------- ### SetupWithManager Configuration Source: https://github.com/rancher/turtles/blob/main/_autodocs/api-reference/clusterctlconfig-reconciler.md Configures the ClusterctlConfigReconciler with the controller manager, setting up watches for ClusterctlConfig and ConfigMap resources. ```go if err := (&controllers.ClusterctlConfigReconciler{ Client: mgr.GetClient(), }).SetupWithManager(ctx, mgr, controller.Options{}); err != nil { return err } ``` -------------------------------- ### SetupWithManager Source: https://github.com/rancher/turtles/blob/main/_autodocs/api-reference/clusterctlconfig-reconciler.md Configures the ClusterctlConfigReconciler with the controller manager, setting up watches for ClusterctlConfig and ConfigMap resources. ```APIDOC ## SetupWithManager ### Description Configures the ClusterctlConfigReconciler with the controller manager. ### Signature ```go func (r *ClusterctlConfigReconciler) SetupWithManager( ctx context.Context, mgr ctrl.Manager, _ controller.Options ) error ``` ### Parameters #### Path Parameters - **ctx** (context.Context) - Context for setup operations (unused) - **mgr** (ctrl.Manager) - Controller manager - **_** (controller.Options) - Controller options (unused in this reconciler) ### Return Value **Type:** error Returns nil on successful setup, error otherwise. ### Behavior 1. **Primary Watch**: Watches ClusterctlConfig resources (turtles-capi.cattle.io/v1alpha1) on create/update/delete. 2. **Secondary Watch**: Watches ConfigMap resources (v1) named "clusterctl-config" using `configMapMapper`. 3. **Handler Mapping**: Maps ConfigMap changes to ClusterctlConfig reconciliation requests. ``` -------------------------------- ### Resulting ConfigMap After ClusterctlConfig Creation Source: https://github.com/rancher/turtles/blob/main/_autodocs/api-reference/clusterctlconfig-reconciler.md The ConfigMap generated by the reconciler in response to the example ClusterctlConfig resource. ```yaml apiVersion: v1 kind: ConfigMap metadata: name: clusterctl-config namespace: cattle-cluster-api-provider data: images: | all: repository: "internal-registry" ``` -------------------------------- ### Configure Kubernetes Version Source: https://github.com/rancher/turtles/blob/main/docs/image-builder/vsphere-kubeadm.md Create a JSON configuration file specifying the desired Kubernetes version details for the OVA build. ```bash cat > my-k8s-config.json < ``` -------------------------------- ### OperatorReconciler Structure and Method Source: https://github.com/rancher/turtles/blob/main/_autodocs/API-SUMMARY.md Defines the OperatorReconciler for installing and managing CAPI providers. It has a SetupWithManager method for integration with the controller manager. ```go type OperatorReconciler struct{} func (r *OperatorReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options ctr.Options) error ``` -------------------------------- ### Build Ubuntu 24.04 AMI with Kubernetes Source: https://github.com/rancher/turtles/blob/main/docs/image-builder/ec2-kubeadm.md Execute the AMI build process using Packer, specifying the custom Kubernetes configuration file. This command initiates the creation of an Ubuntu 24.04 AMI with the selected Kubernetes version. ```bash PACKER_VAR_FILES="$(pwd)/my-k8s-config.json" make build-ami-ubuntu-2404 ``` -------------------------------- ### CAPIProvider Status Source: https://github.com/rancher/turtles/blob/main/_autodocs/api-reference/capiprovider.md This section describes the status fields of a CAPIProvider resource, indicating the current state of the provider installation and configuration. ```APIDOC ## CAPIProvider Status ### Status Fields | Field | Type | Description | |-------|------|-------------| | phase | Phase | Current provisioning state: `Pending`, `Provisioning`, `Ready`, or `Failed` | | variables | map[string]string | Environment variables currently set in ConfigSecret (defaults include CLUSTER_TOPOLOGY, EXP_CLUSTER_RESOURCE_SET, EXP_MACHINE_POOL) | | name | string | Actual provider name as it appears in `kubectl get capiproviders` output | | conditions | []Condition | Upstream provider conditions from CAPI Operator | | installedVersion | string | Version of installed provider | ### Phase Values - **Pending** — Provider resource created but not yet provisioning - **Provisioning** — Provider installation in progress - **Ready** — Provider fully installed and ready to use - **Failed** — Provider installation failed ``` -------------------------------- ### Create vSphere Credentials File Source: https://github.com/rancher/turtles/blob/main/docs/image-builder/vsphere-kubeadm.md Create a JSON file containing your vSphere connection details. Ensure sensitive information like passwords is handled securely. ```bash cat > packer/ova/vsphere.json < kubectl logs -n capi-system -l provider= --tail=50 ``` -------------------------------- ### Complete Cluster Import Decision Flow Source: https://github.com/rancher/turtles/blob/main/_autodocs/api-reference/utilities.md Demonstrates the complete logic for deciding whether to auto-import a cluster. It checks import conditions, existing annotations, and control plane readiness. ```go // 1. Check if cluster should be imported shouldImport, err := util.ShouldAutoImport( ctx, log, client, capiCluster, "cluster-api.cattle.io/rancher-auto-import", ) if err != nil { return err } if !shouldImport { // Skip import if label says not to return nil } // 2. Check if already imported if annotations.HasClusterImportAnnotation(capiCluster) { // Already imported, skip re-import return nil } // 3. Check control plane readiness (predicate handles this) // Reconciliation already filtered by ClusterWithReadyControlPlane predicate // 4. Proceed with import rancherCluster := createRancherCluster(capiCluster) // 5. Mark as imported capiCluster.Annotations[annotations.ClusterImportedAnnotation] = "true" client.Update(ctx, capiCluster) return nil ``` -------------------------------- ### Build vSphere OVA Template Source: https://github.com/rancher/turtles/blob/main/docs/image-builder/vsphere-kubeadm.md Initiate the OVA build process for Ubuntu 24.04 with the specified Kubernetes version using Packer and Ansible. ```bash PACKER_VAR_FILES="$(pwd)/my-k8s-config.json" make build-node-ova-vsphere-ubuntu-2404 ``` -------------------------------- ### Search for Cluster Classes Using a Regex Source: https://github.com/rancher/turtles/blob/main/examples/README.md Utilize the -r flag with a regular expression to search for multiple matching cluster class examples. ```bash go run main.go -r "azure" ``` -------------------------------- ### CAPICleanupReconciler Structure and Methods Source: https://github.com/rancher/turtles/blob/main/_autodocs/API-SUMMARY.md Defines the CAPICleanupReconciler for removing finalizers on cluster deletion. It includes fields for client and scheme, and methods for setup and reconciliation. ```go type CAPICleanupReconciler struct { Client client.Client Scheme *runtime.Scheme } func (r *CAPICleanupReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error func (r *CAPICleanupReconciler) Reconcile(ctx context.Context, cluster *managementv3.Cluster) (ctrl.Result, error) ``` -------------------------------- ### Create GCP Service Account Key Source: https://github.com/rancher/turtles/blob/main/docs/image-builder/gcp-kubeadm.md Create a JSON key file for your GCP service account, which will be used for authentication during the image building process. ```bash export GCP_PROJECT_ID="your-project-id" export SERVICE_ACCOUNT_NAME="capg-packer-service-account" gcloud iam service-accounts keys create capg-packer-key.json \ --iam-account=${SERVICE_ACCOUNT_NAME}@${GCP_PROJECT_ID}.iam.gserviceaccount.com ``` -------------------------------- ### Get Rancher Turtles Version Information Source: https://github.com/rancher/turtles/blob/main/_autodocs/configuration.md Retrieve version information logged by the manager on startup. This is useful for debugging and verifying the deployed version. ```bash kubectl logs -n -l app=rancher-turtles | grep version ``` -------------------------------- ### Set ngrok Authentication and API Keys Source: https://github.com/rancher/turtles/blob/main/test/e2e/README.md Configure ngrok for local e2e testing by setting authentication and API keys as environment variables. ```bash export NGROK_AUTHTOKEN=[AUTHTOKEN] export NGROK_API_KEY=[API_KEY] ``` -------------------------------- ### Provider Management APIs Source: https://github.com/rancher/turtles/blob/main/_autodocs/README.md Details the APIs for managing providers, including OperatorReconciler and CAPIProviderReconciler. Covers provider installation lifecycle, ConfigSecret management, and automatic updates. ```APIDOC ## Provider Management APIs ### Description This section details the APIs and reconcilers involved in managing Cluster API providers within the Rancher Turtles system, including their installation, configuration, and update processes. ### Key Reconcilers - **OperatorReconciler**: Oversees the overall operator lifecycle and management of providers. - **CAPIProviderReconciler**: Specifically manages the lifecycle and reconciliation of Cluster API providers. ### Provider Installation Lifecycle - **Discovery**: Identifies available providers. - **Installation**: Handles the deployment and setup of providers. - **Configuration**: Manages provider-specific settings and configurations. ### ConfigSecret Management - **Creation**: Automatically creates Kubernetes Secrets to store provider credentials and configuration. - **Updates**: Manages updates to these ConfigSecrets as provider configurations change. - **Security**: Ensures secure handling of sensitive information within Secrets. ### Automatic Updates - **Version Checking**: Monitors for new provider versions. - **Update Mechanism**: Implements a controlled process for updating installed providers. ### Type Mapping and Features - **Type Mapping**: Defines how different provider types are recognized and handled. - **Feature Enablement**: Manages the activation and configuration of provider-specific features. ### Example Usage (Conceptual) ```go // OperatorReconciler might watch for CAPIProvider resources // and trigger CAPIProviderReconciler actions. // CAPIProviderReconciler would handle the detailed logic // for installing and configuring a specific provider. ``` ``` -------------------------------- ### Verify Pod Permissions for Lease Operations Source: https://github.com/rancher/turtles/blob/main/_autodocs/errors-and-troubleshooting.md Check if the Rancher Turtles ServiceAccount has the necessary permissions to 'get' and 'update' Lease resources. This is critical for leader election. ```bash kubectl auth can-i get leases --as=system:serviceaccount:cattle-cluster-api-provider:rancher-turtles kubectl auth can-i update leases --as=system:serviceaccount:cattle-cluster-api-provider:rancher-turtles ``` -------------------------------- ### SetupWithManager Configuration Source: https://github.com/rancher/turtles/blob/main/_autodocs/api-reference/capi-cluster-import.md Configures the CAPIImportReconciler with the controller manager, including predicates for filtering and watches for related resources. Use this to initialize the reconciler in your application. ```go if err := (&controllers.CAPIImportReconciler{ Client: mgr.GetClient(), Scheme: mgr.GetScheme(), UncachedClient: uncachedClient, WatchFilterValue: "watchLabelValue", InsecureSkipVerify: false, }).SetupWithManager(ctx, mgr, controller.Options{ MaxConcurrentReconciles: 5, }); err != nil { return err } ``` -------------------------------- ### Run Short E2E Tests with Specific Configuration Source: https://github.com/rancher/turtles/blob/main/test/e2e/README.md Run E2E tests tagged with 'short' for PR verification. Configure the management cluster environment, Ginkgo label filter, source repository, and GitHub head reference. ```bash MANAGEMENT_CLUSTER_ENVIRONMENT=isolated-kind TAG=v0.0.1 GINKGO_LABEL_FILTER=short SOURCE_REPO=https://github.com/your-organization/turtles GITHUB_HEAD_REF=your_feature_branch make test-e2e ``` -------------------------------- ### Enable UI Plugin via Deployment Args Source: https://github.com/rancher/turtles/blob/main/_autodocs/workflows.md Enable the UI plugin feature by specifying the feature gate in the manager container's arguments within its deployment configuration. ```yaml spec: containers: - name: manager args: - --feature-gates=ui-plugin=true ``` -------------------------------- ### Build CAPIProviderReconciler Controller Builder Source: https://github.com/rancher/turtles/blob/main/_autodocs/api-reference/operator-provider.md Customizes the controller builder for CAPIProvider reconciliation, including field indexing and secret/provider watch setup. Use this to configure how the CAPIProviderReconciler interacts with resources. ```go builder, err := reconciler.BuildWithManager(ctx, mgr) if err != nil { log.Error(err, "failed to build controller") } // builder is ready for additional watches/configuration ``` -------------------------------- ### ClusterctlConfig Custom Resource Definition Source: https://github.com/rancher/turtles/blob/main/docs/adr/0012-clusterctl-provider.md Defines the structure for overriding clusterctl images and providers. Use this to specify custom image repositories or provider URLs for air-gapped installations or custom provider integrations. ```yaml apiVersion: turtles-capi.cattle.io/v1alpha1 kind: ClusterctlConfig metadata: name: clusterctl-config # Constant name namespace: rancher-turtles-system # Release namaespace spec: images: # https://cluster-api.sigs.k8s.io/clusterctl/configuration#image-overrides - name: all repository: myorg.io/local-repo providers: # https://cluster-api.sigs.k8s.io/clusterctl/configuration#provider-repositories - name: "my-infra-provider" url: "https://github.com/myorg/myrepo/releases/latest/infrastructure-components.yaml" type: "InfrastructureProvider" ``` -------------------------------- ### CAPICleanupReconciler.SetupWithManager Source: https://github.com/rancher/turtles/blob/main/_autodocs/api-reference/capi-cleanup.md Configures the CAPICleanupReconciler with the controller manager, specifying how it watches and filters Rancher Cluster resources for cleanup operations. ```APIDOC ## CAPICleanupReconciler.SetupWithManager ### Description Configures the CAPICleanupReconciler with the controller manager. This method sets up the reconciler to watch Rancher Cluster resources, applying specific filters and options for the cleanup process. ### Signature ```go func (r *CAPICleanupReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error ``` ### Parameters #### Path Parameters * None #### Query Parameters * None #### Request Body * None ### Parameters - **ctx** (context.Context) - Context for setup operations (unused in this reconciler) - **mgr** (ctrl.Manager) - Controller manager - **options** (controller.Options) - Controller configuration (max concurrent reconciles) ### Return Value **Type:** error Returns nil on successful setup, error otherwise. ### Behavior 1. **Controller Setup**: Creates a new controller named "cleanup", watches Rancher management.cattle.io/v3 Cluster resources, and filters clusters by `cluster-api.cattle.io/owned` label presence. 2. **Predicate Configuration**: Only processes clusters that have the `cluster-api.cattle.io/owned` label, ignoring those without it. 3. **Controller Options**: Applies concurrency settings from provided options and uses reconcile.AsReconciler pattern for single-argument reconciliation. ### Request Example ```go if err := (&controllers.CAPICleanupReconciler{ Client: mgr.GetClient(), Scheme: mgr.GetScheme(), }).SetupWithManager(ctx, mgr, controller.Options{ MaxConcurrentReconciles: 5, }); err != nil { return err } ``` ``` -------------------------------- ### Describe Problematic Resources Source: https://github.com/rancher/turtles/blob/main/_autodocs/errors-and-troubleshooting.md Get detailed information about a specific cluster or CAPI provider resource. This command provides a comprehensive view of the resource's state, including its configuration, status, and events. ```bash kubectl describe cluster > cluster-describe.txt kubectl describe capiprovider > provider-describe.txt ``` -------------------------------- ### ClusterctlConfig CRD Source: https://github.com/rancher/turtles/blob/main/_autodocs/README.md Details the configuration structure for the ClusterctlConfig Custom Resource Definition (CRD). It covers image overrides, provider definitions, integration with provider installation, and use cases like airgapped environments. ```APIDOC ## ClusterctlConfig CRD ### Description Defines the structure and usage of the ClusterctlConfig Custom Resource Definition (CRD), which is used to configure Cluster API components and providers, especially in non-standard environments. ### Resource Definition ```yaml apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: name: clusterctlconfigs.cluster.x-k8s.io spec: group: cluster.x-k8s.io names: kind: ClusterctlConfig plural: clusterctlconfigs singular: clusterctlconfig scope: Namespaced versions: - name: v1beta1 served: true storage: true schema: openAPIV3Schema: type: object properties: spec: type: object properties: providers: type: array items: { type: object } # Provider definition details imageOverrides: type: object # Image override details # ... other spec fields ... ``` ### Parameters #### Spec Parameters - **providers** (array) - Required - A list of provider definitions, including their names, types, and versions. - **imageOverrides** (object) - Optional - Allows overriding default container image references for Cluster API components. ### Use Cases - **Airgap Deployments**: Specify local image registries. - **Custom Mirrors**: Use alternative image sources. - **Provider Installation**: Define how providers are installed and managed. ### Examples ```yaml apiVersion: cluster.x-k8s.io/v1beta1 kind: ClusterctlConfig metadata: name: default-clusterctl-config spec: providers: - name: cluster-api type: Core version: v1.4.0 imageOverrides: cluster-api: my-registry/cluster-api:v1.4.0 ``` ``` -------------------------------- ### CAPIProvider CRD Source: https://github.com/rancher/turtles/blob/main/_autodocs/README.md Details the Resource Definition and Specification for the CAPIProvider Custom Resource Definition (CRD). It includes parameter tables, status fields, phases, validation rules, and configuration examples for credentials and features. ```APIDOC ## CAPIProvider CRD ### Description Provides the resource definition and specification for the CAPIProvider Custom Resource Definition (CRD). This document outlines the structure, parameters, status fields, and validation rules for managing Cluster API providers within Rancher. ### Resource Definition ```yaml apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: name: capiproviders.cluster.x-k8s.io spec: group: cluster.x-k8s.io names: kind: CAPIProvider plural: capiproviders singular: capiprovider scope: Namespaced versions: - name: v1beta1 served: true storage: true schema: openAPIV3Schema: type: object properties: spec: type: object properties: # ... spec fields ... status: type: object properties: phase: { type: string } # ... status fields ... ``` ### Parameters #### Spec Parameters - **credentials** (object) - Optional - Configuration for accessing cloud provider credentials. - **features** (object) - Optional - Configuration for enabling specific provider features. #### Status Fields - **phase** (string) - The current phase of the CAPIProvider reconciliation. - **conditions** ([]object) - Machine-readable status conditions. ### Validation Rules - Fields within `spec` and `status` are subject to specific validation rules detailed in the full type definitions. ### Examples ```yaml apiVersion: cluster.x-k8s.io/v1beta1 kind: CAPIProvider metadata: name: my-provider spec: credentials: # ... credential details ... features: # ... feature details ... ``` ``` -------------------------------- ### Disclosure of AI Assistance in Commits Source: https://github.com/rancher/turtles/blob/main/AI_POLICY.md When AI is used to generate parts of a contribution, disclose it in the PR description and add an 'Assisted-by:' trailer to the relevant commits. This example shows the format for such trailers. ```git commit message Assisted-by: GitHub Copilot Assisted-by: Claude Opus 4.5 Assisted-by: ChatGPT 5.2 ``` -------------------------------- ### CAPIProvider Creation Source: https://github.com/rancher/turtles/blob/main/_autodocs/api-reference/capiprovider.md This section details how to create a CAPIProvider resource. It outlines the specification parameters required to define the provider's configuration, including its name, type, credentials, features, and update settings. ```APIDOC ## CAPIProvider Creation ### Specification Parameters | Parameter | Type | Required | Default | Description | |-----------|------|----------|---------|-------------| | name | string | optional | — | Name of the provider (e.g., "aws", "vsphere", "azure") | | type | Type | **required** | — | Provider type: `infrastructure`, `core`, `controlplane`, `bootstrap`, `addon`, `ipam`, or `runtimeextension` | | credentials | Credentials | optional | — | Credentials object for provider authentication; only one credential type can be set | | features | Features | optional | — | Features object to enable MachinePool, ClusterResourceSet, or ClusterTopology | | variables | map[string]string | optional | — | Map of environment variables to add to the provider's ConfigSecret | | enableAutomaticUpdate | bool | optional | false | When true, automatically update provider to newest available version | ### Return Type Returns a CAPIProvider resource with populated status reflecting the provider installation state. ### Example ```yaml apiVersion: turtles-capi.cattle.io/v1alpha1 kind: CAPIProvider metadata: name: aws-provider spec: name: aws type: infrastructure version: v2.3.0 credentials: rancherCloudCredential: my-aws-credential features: machinePool: true clusterResourceSet: true clusterTopology: true variables: AWS_B64ENCODED_CREDENTIALS: "LS0tLS1CRUdJTi..." enableAutomaticUpdate: false ``` ```