Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .gemini/commands/generate/labels.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# In: ~/.gemini/commands/generate/types.toml
# This command will be invoked via: /generate:labels "AlloyDBInstance"

description = "Asks the model to fix label sanitization."

prompt = """
You are a golang and config connector expert.
I am working on a customer issue, can you help me fix it? The errors the customer are seeing are as follows:
- googleapi: Error 400: resource labels are invalid: key "applyset.kubernetes.io/part-of" contains invalid character ''.'' at index 7
- googleapi: Error 400: resource labels are invalid: key "app.kubernetes.io/managed-by" contains invalid character ''.'' at index 2
- googleapi: Error 400: resource labels are invalid: key "configsync.gke.io/declared-version: v1beta1" contains invalid character ''.'' at index 9

The problematic label is in the {{args}} resources .metadata.labels field.
A sample of this fix can be found at https://github.com/GoogleCloudPlatform/k8s-config-connector/pull/4808.
The sample fix was for the ComputeForwardingRule resource and a "foo: bar" label.

Please start by reading the fix https://github.com/GoogleCloudPlatform/k8s-config-connector/pull/4808
Then make a plan to create a similar fix for {{args}}.
Please make sure the generated code compiles.
Please run 'hack/compare_mock fixtures/{{args}}' to regenerate the golden logs.
Please add tests as appropriate.
Prioritize Correctness: Always prioritize security, scalability, and maintainability in your implementations.

Your response should include:
1. Type objects which can be used to generate the CRD @config/crds/resources/apiextensions.k8s.io_v1_customresourcedefinition_containerclusters.container.cnrm.cloud.google.com.yaml .
2. A brief explanation of the key changes you made and why.
"""
9 changes: 5 additions & 4 deletions pkg/controller/direct/alloydb/instance_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct"
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct/directbase"
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct/registry"
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/label"

gcp "cloud.google.com/go/alloydb/apiv1beta"
alloydbpb "cloud.google.com/go/alloydb/apiv1beta/alloydbpb"
Expand Down Expand Up @@ -182,9 +183,9 @@ func (a *instanceAdapter) Create(ctx context.Context, createOp *directbase.Creat
if mapCtx.Err() != nil {
return mapCtx.Err()
}
resource.Labels = make(map[string]string)
for k, v := range a.desired.GetObjectMeta().GetLabels() {
resource.Labels[k] = v
resource.Labels = label.NewGCPLabelsFromK8sLabels(a.desired.GetObjectMeta().GetLabels())
if resource.Labels == nil {
resource.Labels = make(map[string]string)
}
resource.Labels["managed-by-cnrm"] = "true"
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: with NewGCPLabelsFromK8sLabels this line is no longer needed. as well as line 261


Expand Down Expand Up @@ -254,7 +255,7 @@ func (a *instanceAdapter) Update(ctx context.Context, updateOp *directbase.Updat
if err != nil {
return err
}
desiredLabels := a.desired.GetObjectMeta().GetLabels()
desiredLabels := label.NewGCPLabelsFromK8sLabels(a.desired.GetObjectMeta().GetLabels())
if desiredLabels == nil {
desiredLabels = make(map[string]string)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
apiVersion: alloydb.cnrm.cloud.google.com/v1beta1
kind: AlloyDBInstance
metadata:
finalizers:
- cnrm.cloud.google.com/finalizer
- cnrm.cloud.google.com/deletion-defender
generation: 1
labels:
app.kubernetes.io/managed-by: whatever
applyset.kubernetes.io/part-of: whatever
cnrm-test: "true"
configsync.gke.io/declared-version: v1beta1
name: alloydbinstance-${uniqueId}
namespace: ${uniqueId}
spec:
availabilityType: REGIONAL
clusterRef:
name: alloydbcluster-${uniqueId}
instanceTypeRef:
name: alloydbcluster-${uniqueId}
machineConfig:
cpuCount: 2
status:
conditions:
- lastTransitionTime: "1970-01-01T00:00:00Z"
message: The resource is up to date
reason: UpToDate
status: "True"
type: Ready
createTime: "1970-01-01T00:00:00Z"
externalRef: projects/${projectId}/locations/europe-west1/clusters/alloydbcluster-${uniqueId}/instances/alloydbinstance-${uniqueId}
ipAddress: 10.1.2.3
name: projects/${projectId}/locations/europe-west1/clusters/alloydbcluster-${uniqueId}/instances/alloydbinstance-${uniqueId}
observedGeneration: 1
state: READY
uid: "12345678"
updateTime: "1970-01-01T00:00:00Z"
Loading
Loading