Skip to content

Implement direct controller for KMSCryptoKey#9712

Open
codebot-robot wants to merge 4 commits into
GoogleCloudPlatform:masterfrom
codebot-robot:issue_9711
Open

Implement direct controller for KMSCryptoKey#9712
codebot-robot wants to merge 4 commits into
GoogleCloudPlatform:masterfrom
codebot-robot:issue_9711

Conversation

@codebot-robot

Copy link
Copy Markdown
Collaborator

Implement the direct controller and record/verify E2E fixtures for KMSCryptoKey.

Changes:

  • Created the direct controller under pkg/controller/direct/kms/cryptokey_controller.go.
  • Configured KRM metadata labels synchronization.
  • Implemented KMS delete semantics, ensuring all underlying key versions are destroyed and automatic rotation is disabled upon deletion.
  • Extended the mockgcp KMS mock to handle rotation_period update requests in UpdateCryptoKey.
  • Enabled the direct controller dynamically in SupportedControllers list of static_config.go.
  • Generated and registered golden E2E test files for KMSCryptoKey under both old (Terraform) and new (Direct) reconcilers.

Fixes #9711

This patch:
1. Implements the direct controller for KMSCryptoKey under `pkg/controller/direct/kms/`.
2. Resolves and normalizes KeyRingRef and other spec fields.
3. Syncs KRM metadata labels to/from GCP labels.
4. Correctly manages KMS Delete semantics by listing/destroying all key versions and disabling automatic rotation.
5. Updates mockgcp's KMS server to support rotation period updates.
6. Records golden E2E test results for KMSCryptoKey.

Fixes GoogleCloudPlatform#9711
@google-oss-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign maqiuyujoyce for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Comment on lines +137 to +141
desired := KMSCryptoKeySpec_ToProto(mapCtx, &a.desired.Spec)
if mapCtx.Err() != nil {
return mapCtx.Err()
}
desired.Labels = label.NewGCPLabelsFromK8sLabels(a.desired.GetObjectMeta().GetLabels())

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should only call KMSCryptoKeySpec_ToProto (or equivalent) in AdapterForObject, and we should store desired as a proto - the same foramt as actual. Please update the skill to emphasize this.

}
desired.Labels = label.NewGCPLabelsFromK8sLabels(a.desired.GetObjectMeta().GetLabels())

skipInitialVersionCreation := false

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming this is why we deviated from calling KMSCryptoKeySpec_ToProto in AdapterForObject. For fields like this that are not represent in the API, let's store those separately in kmsCryptoKeyAdapter, maybe in this case desiredSkipInitialVersionCreation would be clearest

Comment on lines +148 to +152
parent := &krm.KMSKeyRingIdentity{
Project: a.id.Project,
Location: a.id.Location,
Keyring: a.id.KeyRing,
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to create a ParentString() method on the identity type (KMSCryptoKeyIdentity). Please update the skill if that's not clear.

it := a.gcpClient.ListCryptoKeyVersions(ctx, &kmspb.ListCryptoKeyVersionsRequest{Parent: a.id.String()})
for {
version, err := it.Next()
if err == iterator.Done {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linter has flagged this: comparing with == will fail on wrapped errors. Use errors.Is to check for a specific error (errorlint)

> {
> "error": {
> "code": 500,
> "message": "field \"destroyScheduledDuration\" is not yet handled in mock"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we need to update the mock to cover this

@codebot-robot codebot-robot removed their assignment Jun 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement direct controller and E2E fixtures for KMSCryptoKey

2 participants