close
Skip to content

fix(export): allow exporting sets containing nested resource references - #11800

Merged
ldanielmadariaga merged 1 commit into
GoogleCloudPlatform:masterfrom
gemmahou:export-computebackendservice
Jul 24, 2026
Merged

fix(export): allow exporting sets containing nested resource references#11800
ldanielmadariaga merged 1 commit into
GoogleCloudPlatform:masterfrom
gemmahou:export-computebackendservice

Conversation

@gemmahou

@gemmahou gemmahou commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

BRIEF Change description

Generated by GeminiCLI.

Fixes a bug in convertTFSetToKCCSet where any set field containing nested resource references (such as backend field in ComputeBackendService) was completely omitted from the exported YAML output.

During normal reconciliation, the converter falls back to the user's declared KRM spec (prevSpecVal) for sets containing reference fields. This is necessary because set-hashing of unresolved local references (which use a local resource name) will never match the resolved GCP URLs (which use full resource links) from the live state. This hash mismatch would otherwise cause the converter to assume the elements are different, clobbering the user's local references and causing infinite diff reconciliation loops.

However, during a config-connector export or import command, there is no previous specification available (prevSpecVal is nil). Falling back unconditionally to prevSpecVal in this case discarded the live state elements, resulting in a missing set field in the final exported YAML.

  • Modified convertTFSetToKCCSet in pkg/krmtotf/tftokrm.go to only apply the reference fallback safeguard if prevSpecVal != nil.
  • Added a comprehensive unit test in pkg/krmtotf/tftokrm_test.go that specifically simulates an export scenario (prevSpec == nil) of a set containing nested reference fields, verifying correct live state conversion.

Fixes #8672

WHY do we need this change?

Special notes for your reviewer:

Does this PR add something which needs to be 'release noted'?

ComputeBackendService: Fix config-connector export tool to export `backend` field.
  • Reviewer reviewed release note.

Additional documentation e.g., references, usage docs, etc.:


Intended Milestone

Please indicate the intended milestone.

  • Reviewer tagged PR with the actual milestone.

Tests you have done

Before:

config-connector export //compute.googleapis.com/v1/projects/cnrm-yuhou/global/backendServices/computebackendservice-test
---
apiVersion: compute.cnrm.cloud.google.com/v1beta1
kind: ComputeBackendService
metadata:
  annotations:
    cnrm.cloud.google.com/project-id: cnrm-yuhou
  name: computebackendservice-test
spec:
  connectionDrainingTimeoutSec: 300
  healthChecks:
  - healthCheckRef:
      external: https://www.googleapis.com/compute/v1/projects/cnrm-yuhou/global/httpHealthChecks/computehttphealthcheck-test
  loadBalancingScheme: EXTERNAL
  location: global
  portName: http
  protocol: HTTP
  resourceID: computebackendservice-test
  sessionAffinity: NONE
  timeoutSec: 10

After

go run github.com/GoogleCloudPlatform/k8s-config-connector/cmd/config-connector export //compute.googleapis.com/v1/projects/cnrm-yuhou/global/backendServices/computebackendservice-test
apiVersion: compute.cnrm.cloud.google.com/v1beta1
kind: ComputeBackendService
metadata:
  annotations:
    cnrm.cloud.google.com/project-id: cnrm-yuhou
  name: computebackendservice-test
spec:
  backend:
  - balancingMode: UTILIZATION
    capacityScaler: 1
    group:
      instanceGroupRef:
        external: https://www.googleapis.com/compute/v1/projects/cnrm-yuhou/zones/us-central1-a/instanceGroups/computeinstancegroup-test
  connectionDrainingTimeoutSec: 300
  healthChecks:
  - healthCheckRef:
      external: https://www.googleapis.com/compute/v1/projects/cnrm-yuhou/global/httpHealthChecks/computehttphealthcheck-test
  loadBalancingScheme: EXTERNAL
  location: global
  portName: http
  protocol: HTTP
  resourceID: computebackendservice-test
  sessionAffinity: NONE
  timeoutSec: 10

backend field is populated correctly.

  • Run make ready-pr to ensure this PR is ready for review.
  • Perform necessary E2E testing for changed resources.

@google-oss-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ldanielmadariaga

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

The pull request process is described 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

Merged via the queue into GoogleCloudPlatform:master with commit 368b564 Jul 24, 2026
205 checks passed
@gemmahou
gemmahou deleted the export-computebackendservice branch July 24, 2026 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Export tool does not export backendservice backends

2 participants