Skip to content

Commit c442d2d

Browse files
authored
Implement direct KRM types and generate.sh for ComputeBackendService (#10049)
Configure and run generate-types and generate-mapper for ComputeBackendService under apis/compute/v1beta1/generate.sh. Implement strict schema-compatible KRM types in backendservice_types.go and custom mapper functions in mappers.go. Ensure 100% equivalence in the generated CRD schema. Fixes #9960
2 parents 449a581 + 8844361 commit c442d2d

17 files changed

Lines changed: 4774 additions & 1730 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# ComputeBackendService Transition Journal
2+
3+
During the transition of `ComputeBackendService` to direct KRM Go types, several crucial lessons and patterns were identified:
4+
5+
1. **Casing Matching in Generator:**
6+
The `generate-mapper` tool expects specific casing suffixes for custom structs (e.g., `Cdn` instead of `CDN`, `Iap` instead of `IAP`, `Http` instead of `HTTP`).
7+
By naming the handcoded structs and their mapping functions exactly with the correct suffix (e.g., `BackendServiceCdnPolicy_v1beta1_ToProto` instead of `BackendServiceCDNPolicy_v1beta1_ToProto`), the generator successfully skipped generating conflicting mapper functions in `mapper.generated.go`.
8+
9+
2. **Isolated Secret Reference Types:**
10+
Because some common structs like `SecretKeyRef` can have subtle import differences or confuse `controller-gen`, defining a local `BackendServiceSecretKeyRef` under `backendservice_types.go` isolates the schema definitions and ensures successful build and clean, identical JSON schema generation.
11+
12+
3. **Flat Mapping and Regional/Global Logic:**
13+
The `connectionDrainingTimeoutSec` is flat-mapped in KRM but lives inside a nested `connection_draining` property in the proto. Custom logic in the top-level `ToProto`/`FromProto` mappers cleanly maps this flat field into the nested proto structure.
14+
Additionally, regional vs global mapping is handled dynamically by parsing the last component of the region URL or checking if the region is global.
15+
16+
4. **Strict Schema Equivalence:**
17+
Using `dev/tasks/diff-crds` frequently allowed ensuring that we kept the schema absolutely identical to the baseline CRD, including retaining the correct `tf2crd=true` label, metadata labels, and required field lists in nested structures.

apis/compute/v1beta1/computebackendservice_types.go

Lines changed: 571 additions & 0 deletions
Large diffs are not rendered by default.

apis/compute/v1beta1/generate.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ cd ${REPO_ROOT}/dev/tools/controllerbuilder
2525
go run . generate-types \
2626
--service google.cloud.compute.v1 \
2727
--api-version compute.cnrm.cloud.google.com/v1beta1 \
28+
--resource ComputeBackendService:BackendService \
2829
--resource ComputeBackendBucket:BackendBucket \
2930
--resource ComputeExternalVPNGateway:ExternalVpnGateway \
3031
--resource ComputeFirewall:Firewall \

apis/compute/v1beta1/types.generated.go

Lines changed: 808 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)