Skip to content
Merged
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
10 changes: 10 additions & 0 deletions .gemini/skills/kcc-identity-reference/journal/DNSResponsePolicy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
### [2026-06-11] DNSResponsePolicy Identity & Refs
- **Context**: Moving DNSResponsePolicy to the new identity and reference patterns using multiple `gcpurls.Template` formats.
- **Problem**:
1. DNSResponsePolicy was previously implemented in `apis/dns/v1alpha1` but only supported a single `locations/{location}/responsePolicies/{responsePolicy}` format.
2. This led to failures when standard GCP reference URLs (which omit the location segment for global response policies) were passed as external references, as they were treated as invalid by unit tests.
- **Solution**:
1. Refactored `apis/dns/v1alpha1/dnsresponsepolicy_identity.go` to utilize two `gcpurls.Template` vars: a primary location-based format (`projects/{project}/locations/{location}/responsePolicies/{responsePolicy}`) and a fallback location-less format (`projects/{project}/responsePolicies/{responsePolicy}`).
2. Updated `apis/dns/v1alpha1/dnsresponsepolicy_identity_test.go` unit tests to verify that standard location-less GCP response policies are parsed correctly into the fallback template representation.
3. Registered the fallback template exception `//dns.googleapis.com/projects/{}/responsePolicies/{}` in `pkg/gcpurls/registry_test.go` so the CAI alignment validation tests continue to pass successfully.
- **Impact**: DNSResponsePolicy is now fully compliant with modern KCC identity and reference patterns, supporting both CAIS-compliant formats and direct location-less GCP API references.
31 changes: 20 additions & 11 deletions apis/dns/v1alpha1/dnsresponsepolicy_identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ var (
_ identity.Resource = &DNSResponsePolicy{}
)

var DNSResponsePolicyIdentityFormat = gcpurls.Template[DNSResponsePolicyIdentity]("dns.googleapis.com", "projects/{project}/locations/{location}/responsePolicies/{responsePolicy}")
var (
DNSResponsePolicyIdentityFormat = gcpurls.Template[DNSResponsePolicyIdentity]("dns.googleapis.com", "projects/{project}/locations/{location}/responsePolicies/{responsePolicy}")
DNSResponsePolicyIdentityFallbackFormat = gcpurls.Template[DNSResponsePolicyIdentity]("dns.googleapis.com", "projects/{project}/responsePolicies/{responsePolicy}")
)

// DNSResponsePolicyIdentity is the identity of a GCP DNSResponsePolicy.
// +k8s:deepcopy-gen=false
Expand All @@ -40,24 +43,30 @@ type DNSResponsePolicyIdentity struct {
}

func (i *DNSResponsePolicyIdentity) String() string {
return DNSResponsePolicyIdentityFormat.ToString(*i)
if i.Location != "" {
return DNSResponsePolicyIdentityFormat.ToString(*i)
}
return DNSResponsePolicyIdentityFallbackFormat.ToString(*i)
}

func (i *DNSResponsePolicyIdentity) FromExternal(ref string) error {
parsed, match, err := DNSResponsePolicyIdentityFormat.Parse(ref)
if err != nil {
return fmt.Errorf("format of DNSResponsePolicy external=%q was not known (use %s): %w", ref, DNSResponsePolicyIdentityFormat.CanonicalForm(), err)
if parsed, match, err := DNSResponsePolicyIdentityFormat.Parse(ref); match {
*i = *parsed
return nil
} else if err != nil {
return err
}
if !match {
return fmt.Errorf("format of DNSResponsePolicy external=%q was not known (use %s)", ref, DNSResponsePolicyIdentityFormat.CanonicalForm())
if parsed, match, err := DNSResponsePolicyIdentityFallbackFormat.Parse(ref); match {
*i = *parsed
return nil
} else if err != nil {
return err
}

*i = *parsed
return nil
return fmt.Errorf("format of DNSResponsePolicy external=%q was not known (use %s or %s)", ref, DNSResponsePolicyIdentityFormat.CanonicalForm(), DNSResponsePolicyIdentityFallbackFormat.CanonicalForm())
}

func (i *DNSResponsePolicyIdentity) Host() string {
return "dns.googleapis.com"
return DNSResponsePolicyIdentityFormat.Host()
}

func getIdentityFromDNSResponsePolicySpec(ctx context.Context, reader client.Reader, obj *DNSResponsePolicy) (*DNSResponsePolicyIdentity, error) {
Expand Down
10 changes: 7 additions & 3 deletions apis/dns/v1alpha1/dnsresponsepolicy_identity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ func TestDNSResponsePolicyIdentity_FromExternal(t *testing.T) {
},
},
{
name: "invalid reference format (without location)",
ref: "projects/my-project/responsePolicies/my-responsepolicy",
wantErr: true,
name: "valid reference (without location)",
ref: "projects/my-project/responsePolicies/my-responsepolicy",
want: &DNSResponsePolicyIdentity{
Project: "my-project",
Location: "",
ResponsePolicy: "my-responsepolicy",
},
},
{
name: "invalid reference format",
Expand Down
2 changes: 1 addition & 1 deletion apis/dns/v1alpha1/dnsresponsepolicy_reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var _ refs.Ref = &DNSResponsePolicyRef{}

// DNSResponsePolicyRef is a reference to a DNSResponsePolicy.
type DNSResponsePolicyRef struct {
// A reference to an externally managed DNSResponsePolicy resource. Should be in the format "projects/{{projectID}}/locations/{{location}}/responsePolicies/{{responsePolicy}}".
// A reference to an externally managed DNSResponsePolicy resource. Should be in the format "projects/{{projectID}}/locations/{{location}}/responsePolicies/{{responsePolicy}}" or "projects/{{projectID}}/responsePolicies/{{responsePolicy}}".
External string `json:"external,omitempty"`

// The name of a DNSResponsePolicy resource.
Expand Down
1 change: 1 addition & 0 deletions pkg/gcpurls/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ func TestRegisteredTemplatesMatchCAI(t *testing.T) {
"//biglake.googleapis.com/projects/{}/locations/{}/catalogs/{}": true,
"//dialogflow.googleapis.com/projects/{}/locations/{}/generators/{}": true,
"//dns.googleapis.com/projects/{}/managedZones/{}/rrsets/{}": true,
"//dns.googleapis.com/projects/{}/responsePolicies/{}": true,
}
for _, tmpl := range templates {
fullURL := "//" + tmpl.Host() + "/" + tmpl.CanonicalForm()
Expand Down
Loading