This document outlines the process for promoting a KCC resource to a new API version (e.g., from v1alpha1 to v1beta1). Promotion is a critical process that involves moving a resource to a more stable, "direct" controller implementation while ensuring backward compatibility for existing users.
Promotion is a three-step process that should be performed in the following order. The mcp-kcc integration with the Gemini CLI provides tools to automate each step.
The first step is to create the new API version.
Tool: promote_api
What it does:
- Copies the source API package (e.g.,
apis/<service>/v1alpha1) to the new target version (e.g.,apis/<service>/v1beta1). - Updates all version strings in the new Go files from the source version to the target version.
- Adds crucial annotations to the primary type's
_types.gofile:// +kubebuilder:storageversion: Marks the new version as the storage version for the CRD.// +kubebuilder:metadata:labels: "internal.cloud.google.com/additional-versions={source_version}": Ensures the CRD definition preserves the previous version, which is critical for backward compatibility.
- Runs
dev/tasks/generate-crdsto validate the changes and update the CRD files in theconfig/crds/resources/directory.
Example:
To promote the storage API to v1beta1, you can instruct Gemini:
promote the api in
apis/storagetov1beta1
Next, promote the controller to use the new API version.
Tool: promote_controller
What it does:
- Updates the controller's Go files to import and use the new target API version. In complex cases where a controller directory contains files that reference types from both the old and new API versions, this tool intelligently refactors the code. It ensures that the new API version is aliased to
krm, while the old version is given a version-specific alias (e.g.,krmv1alpha1).
Manual Intervention and Validation:
While the promote_controller tool is powerful, complex scenarios may still result in compilation errors. If the tool fails, you can follow this manual process:
-
Use the
promote_controller_prompt: This tool provides detailed, context-specific instructions for fixing the compilation errors. It will guide you on how to correctly alias the imports and update type usages.Example:
give me a prompt to promote the controller in
pkg/controller/storage/storagebucketfor the api inapis/storagetov1beta1 -
Fix Imports Manually: The core idea is to have two imports for the service's API. The new version should be aliased to
krm, and the old version should get a version-specific alias.import ( krm "github.com/GoogleCloudPlatform/k8s-config-connector/apis/storage/v1beta1" krmv1alpha1 "github.com/GoogleCloudPlatform/k8s-config-connector/apis/storage/v1alpha1" )
You must then update all type usages in the file to use the correct alias (
krm.for promoted types,krmv1alpha1.for types remaining in the old version). -
Validate Repeatedly: After making manual changes, use the
promote_controller_validatetool to check your work. You can run this tool repeatedly until all compilation errors are resolved.Example:
validate the controller promotion for
pkg/controller/storage/storagebucket
Example:
To promote the storagebucket controller, you can instruct Gemini:
promote the controller in
pkg/controller/storage/storagebucketfor the api inapis/storagetov1beta1
Finally, update the test fixtures to use the new API version.
Tool: promote_tests
What it does:
- Scans the test fixtures in
pkg/test/resourcefixture/testdata/basic/for the specified Kind. - Copies the relevant test fixtures to a new directory named after the target version.
- Updates the
apiVersionin the test YAML files (create.yaml,update.yaml, etc.) to the new target version.
Example:
To promote the StorageBucket tests, you can instruct Gemini:
promote the tests in
pkg/test/resourcefixture/testdata/basic/storage/v1alpha1/storagebucketfor kindStorageBuckettov1beta1
After promoting the API, controller, and tests, it is critical to verify that the new direct controller behaves identically to the old one.
- Run the full test suite:
make test - Run the golden tests:
- Record new golden files against a real GCP project:
hack/record-gcp <test-name> - Compare the new behavior against the mock GCP layer:
hack/compare-mock <test-name>
- Record new golden files against a real GCP project:
This verification ensures that we do not introduce breaking changes for users.
- Promotion is a three-step process: API, Controller, Tests. Always perform them in order.
- Use Gemini and the integrated MCP tools to automate the promotion steps.
- Backward compatibility is paramount. The
additional-versionslabel is essential. - Verification is not optional. Always run the golden tests to prevent regressions.
- Manual intervention may be required, especially for fixing compilation errors in the controller.