Skip to content

Commit d4acfe0

Browse files
dilyevskyclaude
andcommitted
[apiserver] default TLS on ref-target DomainRecords
Ref targets (e.g. Gateway refs) always terminate TLS, but DomainRecords created without spec.tls caused the controller to skip TLS provisioning. Default spec.tls to an empty DomainTLSSpec when target.ref is set. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent ec69172 commit d4acfe0

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

api/core/v1alpha3/domainrecord_validate.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ func (r *DomainRecord) Default() {
1919
defaultTTL := int32(300)
2020
r.Spec.TTL = &defaultTTL
2121
}
22+
// Default TLS for ref targets — ref targets always terminate TLS.
23+
if r.Spec.Target.Ref != nil && r.Spec.TLS == nil {
24+
r.Spec.TLS = &DomainTLSSpec{}
25+
}
2226
}
2327

2428
var _ resourcestrategy.PrepareForCreater = &DomainRecord{}

api/core/v1alpha3/domainrecord_validate_test.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,4 +319,76 @@ func TestValidateUpdate_DeletionBypassesValidation(t *testing.T) {
319319
assert.Empty(t, errs, "expected no validation errors when object is being deleted")
320320
}
321321

322+
func TestDefault_RefTargetGetsTLS(t *testing.T) {
323+
tests := []struct {
324+
name string
325+
record *DomainRecord
326+
wantTLS bool
327+
}{
328+
{
329+
name: "ref target with no TLS gets TLS defaulted",
330+
record: &DomainRecord{
331+
Spec: DomainRecordSpec{
332+
Name: "example",
333+
Target: DomainRecordTarget{
334+
Ref: &LocalObjectReference{
335+
Group: "gateway.networking.k8s.io",
336+
Kind: "Gateway",
337+
Name: "my-gw",
338+
},
339+
},
340+
},
341+
},
342+
wantTLS: true,
343+
},
344+
{
345+
name: "ref target with existing TLS is not overwritten",
346+
record: &DomainRecord{
347+
Spec: DomainRecordSpec{
348+
Name: "example",
349+
Target: DomainRecordTarget{
350+
Ref: &LocalObjectReference{
351+
Group: "gateway.networking.k8s.io",
352+
Kind: "Gateway",
353+
Name: "my-gw",
354+
},
355+
},
356+
TLS: &DomainTLSSpec{CertificateAuthority: "letsencrypt"},
357+
},
358+
},
359+
wantTLS: true,
360+
},
361+
{
362+
name: "DNS target does not get TLS defaulted",
363+
record: &DomainRecord{
364+
Spec: DomainRecordSpec{
365+
Name: "example",
366+
Target: DomainRecordTarget{
367+
DNS: &DomainRecordTargetDNS{
368+
A: []string{"1.2.3.4"},
369+
},
370+
},
371+
},
372+
},
373+
wantTLS: false,
374+
},
375+
}
376+
377+
for _, tt := range tests {
378+
t.Run(tt.name, func(t *testing.T) {
379+
origTLS := tt.record.Spec.TLS
380+
tt.record.Default()
381+
if tt.wantTLS {
382+
require.NotNil(t, tt.record.Spec.TLS, "expected spec.tls to be non-nil")
383+
// If TLS was already set, ensure it wasn't overwritten.
384+
if origTLS != nil {
385+
assert.Equal(t, origTLS.CertificateAuthority, tt.record.Spec.TLS.CertificateAuthority)
386+
}
387+
} else {
388+
assert.Nil(t, tt.record.Spec.TLS, "expected spec.tls to remain nil")
389+
}
390+
})
391+
}
392+
}
393+
322394
func strPtr(s string) *string { return &s }

0 commit comments

Comments
 (0)