Skip to content

Commit 0490871

Browse files
authored
refactor: Move ComputeVPNGateway to identity and refs pattern (#11590)
Please follow the skill .gemini/skills/kcc-identity-reference/SKILL.md for ComputeVPNGateway. Fixes #11588
2 parents abae73c + d2f1b98 commit 0490871

4 files changed

Lines changed: 28 additions & 1 deletion

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# ComputeVPNGateway Identity and Reference Journal
2+
3+
## Observations & Learnings
4+
5+
- **Regional Scope Integration:** `ComputeVPNGateway` is a regional resource in GCP, meaning its URL pattern contains `/regions/{region}/` and has a region parameter: `projects/{project}/regions/{region}/vpnGateways/{vpngateway}`.
6+
- **Implement ParentString:** We implemented the standard `ParentString()` method to return the parent regional path `projects/{project}/regions/{region}`, ensuring alignment with standard direct controller expectations and other regional compute resources.
7+
- **Fallback Normalize Integration:** In `computevpngateway_reference.go`, we updated the fallback mechanism inside `Normalize` to use the robust standard pattern leveraging `common.ToStructuredType` and `getIdentityFromComputeVPNGatewaySpec` when `status.selfLink` is not yet available, ensuring full compatibility and robust reference resolution.

apis/compute/v1beta1/computevpngateway_identity.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ func (i *ComputeVPNGatewayIdentity) Host() string {
6363
return ComputeVPNGatewayIdentityFormat.Host()
6464
}
6565

66+
func (i *ComputeVPNGatewayIdentity) ParentString() string {
67+
return fmt.Sprintf("projects/%s/regions/%s", i.Project, i.Region)
68+
}
69+
6670
func ParseComputeVPNGatewayExternal(external string) (*ComputeVPNGatewayIdentity, error) {
6771
if external == "" {
6872
return nil, fmt.Errorf("empty ComputeVPNGateway external value")

apis/compute/v1beta1/computevpngateway_identity_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,15 @@ func TestComputeVPNGatewayIdentity_FromExternal(t *testing.T) {
6868
})
6969
}
7070
}
71+
72+
func TestComputeVPNGatewayIdentity_ParentString(t *testing.T) {
73+
id := &ComputeVPNGatewayIdentity{
74+
Project: "my-project",
75+
Region: "us-central1",
76+
VpnGateway: "my-vpn-gateway",
77+
}
78+
expected := "projects/my-project/regions/us-central1"
79+
if actual := id.ParentString(); actual != expected {
80+
t.Fatalf("expected %q, got %q", expected, actual)
81+
}
82+
}

apis/compute/v1beta1/computevpngateway_reference.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,11 @@ func (r *ComputeVPNGatewayRef) Normalize(ctx context.Context, reader client.Read
9393
// Get external from status.selfLink. This ensures backward compatibility for TF/DCL-based resources that lack status.externalRef.
9494
selfLink, _, _ := unstructured.NestedString(u.Object, "status", "selfLink")
9595
if selfLink != "" {
96-
return apirefs.TrimComputeURIPrefix(selfLink)
96+
trimmed := apirefs.TrimComputeURIPrefix(selfLink)
97+
id := &ComputeVPNGatewayIdentity{}
98+
if err := id.FromExternal(trimmed); err == nil {
99+
return id.String()
100+
}
97101
}
98102
return ""
99103
}

0 commit comments

Comments
 (0)