@@ -116,6 +116,18 @@ type DNSSpec struct {
116116 // 30 seconds or as noted in the respective Corefile for your version of OpenShift.
117117 // +optional
118118 Cache DNSCache `json:"cache,omitempty"`
119+
120+ // template is an optional configuration for custom DNS query handling via the CoreDNS template plugin.
121+ // The template defines how to handle queries matching specific zones and query types.
122+ //
123+ // The template applies to all domains (custom domains from spec.servers and the cluster domain)
124+ // to ensure consistent DNS resolution across all paths.
125+ //
126+ // When this field is not set, no template plugin configuration is added to CoreDNS.
127+ //
128+ // +optional
129+ // +openshift:enable:FeatureGate=DNSTemplatePlugin
130+ Template * Template `json:"template,omitempty"`
119131}
120132
121133// DNSCache defines the fields for configuring DNS caching.
@@ -467,6 +479,93 @@ const (
467479 DNSAvailable = "Available"
468480)
469481
482+ // QueryType represents DNS query types supported by templates.
483+ // +kubebuilder:validation:Enum=AAAA
484+ type QueryType string
485+
486+ const (
487+ // QueryTypeAAAA represents IPv6 address records (AAAA).
488+ QueryTypeAAAA QueryType = "AAAA"
489+ )
490+
491+ // QueryClass represents DNS query classes supported by templates.
492+ // Valid value is "IN".
493+ // +kubebuilder:validation:Enum=IN
494+ type QueryClass string
495+
496+ const (
497+ // QueryClassIN represents the Internet class.
498+ QueryClassIN QueryClass = "IN"
499+ )
500+
501+ // ResponseCode represents DNS response codes.
502+ // +kubebuilder:validation:Enum=NOERROR
503+ type ResponseCode string
504+
505+ const (
506+ // ResponseCodeNOERROR indicates a successful DNS query with or without answer records.
507+ ResponseCodeNOERROR ResponseCode = "NOERROR"
508+ )
509+
510+ // Template defines a template for custom DNS query handling via the CoreDNS template plugin.
511+ // Template enables filtering or custom responses for DNS queries matching specific zones and query types.
512+ // +openshift:enable:FeatureGate=DNSTemplatePlugin
513+ type Template struct {
514+ // zones specifies the DNS zones this template applies to.
515+ // Each zone must be a valid DNS name as defined in RFC 1123.
516+ // The special zone "." matches all domains (catch-all).
517+ // Multiple zones can be specified to apply the same template actions to multiple domains.
518+ //
519+ // Note: root zone (".") includes cluster domain (cluster.local); use specific zones to avoid impacting IPv6 queries in IPv6 or dual-stack clusters.
520+ //
521+ // Examples:
522+ // - ["."] matches all domains (catch-all for global AAAA filtering)
523+ // - ["example.com"] matches only example.com and its subdomains
524+ // - ["example.com", "test.com"] matches both domains and their subdomains
525+ //
526+ // +kubebuilder:validation:Required
527+ // +kubebuilder:validation:MinItems=1
528+ // +required
529+ Zones []string `json:"zones"`
530+
531+ // queryType specifies the DNS query type to match.
532+ //
533+ // +kubebuilder:validation:Required
534+ // +kubebuilder:default=AAAA
535+ // +required
536+ QueryType QueryType `json:"queryType"`
537+
538+ // queryClass specifies the DNS query class to match.
539+ //
540+ // +kubebuilder:validation:Required
541+ // +kubebuilder:default=IN
542+ // +required
543+ QueryClass QueryClass `json:"queryClass"`
544+
545+ // actions defines a list of actions to apply to matching queries.
546+ //
547+ // +kubebuilder:validation:Required
548+ // +kubebuilder:validation:MinItems=1
549+ // +required
550+ Actions []TemplateAction `json:"actions"`
551+ }
552+
553+ // TemplateAction defines how to construct a DNS response for queries matching the template.
554+ type TemplateAction struct {
555+ // rcode is the DNS response code to return.
556+ // Valid values are "NOERROR".
557+ //
558+ // When set, the template returns a response with no answer records. For AAAA filtering,
559+ // this means IPv6 address queries return successfully but with no IPv6 addresses,
560+ // causing clients to fall back to IPv4 (A record) queries.
561+ //
562+ // +kubebuilder:validation:Required
563+ // +kubebuilder:validation:Enum=NOERROR
564+ // +kubebuilder:default=NOERROR
565+ // +required
566+ Rcode ResponseCode `json:"rcode"`
567+ }
568+
470569// DNSStatus defines the observed status of the DNS.
471570type DNSStatus struct {
472571 // clusterIP is the service IP through which this DNS is made available.
0 commit comments