Skip to content

Commit 08b5a3a

Browse files
committed
Dynamic ZoneDelegations
Signed-off-by: Dinar Valeev <k0da@opensuse.org>
1 parent dedc185 commit 08b5a3a

24 files changed

+684
-78
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ mocks:
473473
mockgen -package=mocks -destination=controllers/mocks/refresolver_mock.go -source=controllers/refresolver/refresolver.go GslbRefResolver
474474
mockgen -package=mocks -destination=controllers/mocks/provider_mock.go -source=controllers/providers/dns/dns.go Provider
475475
mockgen -package=mocks -destination=controllers/mocks/geotags_mock.go -source=controllers/geotags/geotags.go GeoTags
476+
mockgen -package=mocks -destination=controllers/mocks/zone_service_mock.go -source=controllers/zones/zone_service.go ZoneService
476477
$(call golic)
477478

478479
# remove clusters and redeploy

api/v1beta1/dynamiczone_types.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package v1beta1
2+
3+
/*
4+
Copyright 2021-2025 The k8gb Contributors.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
18+
Generated by GoLic, for more details see: https://github.com/AbsaOSS/golic
19+
*/
20+
21+
import (
22+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23+
)
24+
25+
// ZoneDelegationSpec defines the desired state of ZoneDelegation
26+
27+
type ZoneDelegationSpec struct {
28+
// LoadBalancedZone is the DNS zone managed by this ZoneDelegation
29+
LoadBalancedZone string `json:"loadBalancedZone"`
30+
31+
// ParentZone is the zone under which this load-balanced zone is delegated
32+
ParentZone string `json:"parentZone"`
33+
34+
// DNSZoneNegTTL specifies the negative TTL for the DNS zone (in seconds)
35+
DNSZoneNegTTL int `json:"dnsZoneNegTTL"`
36+
}
37+
38+
// ZoneDelegationStatus defines the observed state of ZoneDelegation
39+
type ZoneDelegationStatus struct {
40+
// DNSServers lists the authoritative DNS servers for the delegated zone
41+
DNSServers []DNSServer `json:"dnsServers,omitempty"`
42+
}
43+
44+
// DNSServer represents a single DNS server for a zone delegation
45+
type DNSServer struct {
46+
// Name of the DNS server (FQDN)
47+
Name string `json:"name"`
48+
49+
// Address of the DNS server (IPv4 or IPv6)
50+
Address string `json:"address"`
51+
}
52+
53+
// ZoneDelegation is the Schema for the zonedelegations API
54+
// +kubebuilder:object:root=true
55+
// +kubebuilder:subresource:status
56+
// +kubebuilder:resource:scope=Cluster,shortName=zd
57+
// +kubebuilder:printcolumn:name="LoadBalancedZone",type=string,JSONPath=`.spec.loadBalancedZone`
58+
// +kubebuilder:printcolumn:name="ParentZone",type=string,JSONPath=`.spec.parentZone`
59+
// +kubebuilder:printcolumn:name="NegTTL",type=integer,JSONPath=`.spec.dnsZoneNegTTL`
60+
type ZoneDelegation struct {
61+
metav1.TypeMeta `json:",inline"`
62+
metav1.ObjectMeta `json:"metadata,omitempty"`
63+
64+
Spec ZoneDelegationSpec `json:"spec,omitempty"`
65+
Status ZoneDelegationStatus `json:"status,omitempty"`
66+
}
67+
68+
// +kubebuilder:object:root=true
69+
70+
// ZoneDelegationList contains a list of ZoneDelegation
71+
type ZoneDelegationList struct {
72+
metav1.TypeMeta `json:",inline"`
73+
metav1.ListMeta `json:"metadata,omitempty"`
74+
Items []ZoneDelegation `json:"items"`
75+
}

api/v1beta1/gslb_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,5 +138,5 @@ func (h HealthStatus) String() string {
138138
}
139139

140140
func init() {
141-
SchemeBuilder.Register(&Gslb{}, &GslbList{})
141+
SchemeBuilder.Register(&Gslb{}, &GslbList{}, &ZoneDelegation{}, &ZoneDelegationList{})
142142
}

api/v1beta1/zz_generated.deepcopy.go

Lines changed: 109 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

chart/k8gb/crd/k8gb.absa.oss_gslbs.yaml

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
33
kind: CustomResourceDefinition
44
metadata:
55
annotations:
6-
controller-gen.kubebuilder.io/version: v0.18.0
6+
controller-gen.kubebuilder.io/version: v0.19.0
77
name: gslbs.k8gb.absa.oss
88
spec:
99
group: k8gb.absa.oss
@@ -492,3 +492,98 @@ spec:
492492
storage: true
493493
subresources:
494494
status: {}
495+
---
496+
apiVersion: apiextensions.k8s.io/v1
497+
kind: CustomResourceDefinition
498+
metadata:
499+
annotations:
500+
controller-gen.kubebuilder.io/version: v0.19.0
501+
name: zonedelegations.k8gb.absa.oss
502+
spec:
503+
group: k8gb.absa.oss
504+
names:
505+
kind: ZoneDelegation
506+
listKind: ZoneDelegationList
507+
plural: zonedelegations
508+
shortNames:
509+
- zd
510+
singular: zonedelegation
511+
scope: Cluster
512+
versions:
513+
- additionalPrinterColumns:
514+
- jsonPath: .spec.loadBalancedZone
515+
name: LoadBalancedZone
516+
type: string
517+
- jsonPath: .spec.parentZone
518+
name: ParentZone
519+
type: string
520+
- jsonPath: .spec.dnsZoneNegTTL
521+
name: NegTTL
522+
type: integer
523+
name: v1beta1
524+
schema:
525+
openAPIV3Schema:
526+
description: ZoneDelegation is the Schema for the zonedelegations API
527+
properties:
528+
apiVersion:
529+
description: |-
530+
APIVersion defines the versioned schema of this representation of an object.
531+
Servers should convert recognized schemas to the latest internal value, and
532+
may reject unrecognized values.
533+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
534+
type: string
535+
kind:
536+
description: |-
537+
Kind is a string value representing the REST resource this object represents.
538+
Servers may infer this from the endpoint the client submits requests to.
539+
Cannot be updated.
540+
In CamelCase.
541+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
542+
type: string
543+
metadata:
544+
type: object
545+
spec:
546+
properties:
547+
dnsZoneNegTTL:
548+
description: DNSZoneNegTTL specifies the negative TTL for the DNS
549+
zone (in seconds)
550+
type: integer
551+
loadBalancedZone:
552+
description: LoadBalancedZone is the DNS zone managed by this ZoneDelegation
553+
type: string
554+
parentZone:
555+
description: ParentZone is the zone under which this load-balanced
556+
zone is delegated
557+
type: string
558+
required:
559+
- dnsZoneNegTTL
560+
- loadBalancedZone
561+
- parentZone
562+
type: object
563+
status:
564+
description: ZoneDelegationStatus defines the observed state of ZoneDelegation
565+
properties:
566+
dnsServers:
567+
description: DNSServers lists the authoritative DNS servers for the
568+
delegated zone
569+
items:
570+
description: DNSServer represents a single DNS server for a zone
571+
delegation
572+
properties:
573+
address:
574+
description: Address of the DNS server (IPv4 or IPv6)
575+
type: string
576+
name:
577+
description: Name of the DNS server (FQDN)
578+
type: string
579+
required:
580+
- address
581+
- name
582+
type: object
583+
type: array
584+
type: object
585+
type: object
586+
served: true
587+
storage: true
588+
subresources:
589+
status: {}

chart/k8gb/templates/coredns/cm.yaml

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,12 @@ metadata:
88
{{ include "chart.labels" . | indent 4 }}
99
data:
1010
Corefile: |-
11-
{{- range .Values.k8gb.dnsZones }}
12-
{{ .loadBalancedZone }}:5353 {
11+
(k8gbplugins) {
1312
errors
1413
health
1514
{{- if $.Values.coredns.corefile.reload.enabled }}
1615
reload {{ $.Values.coredns.corefile.reload.interval }} {{ $.Values.coredns.corefile.reload.jitter }}
1716
{{- end }}
18-
{{- if .extraPlugins }}
19-
{{- range .extraPlugins }}
20-
{{ . | nindent 8 }}
21-
{{- end }}
22-
{{- end }}
2317
ready
2418
prometheus 0.0.0.0:9153
2519
forward . /etc/resolv.conf
@@ -35,8 +29,29 @@ data:
3529
{{- end }}
3630
}
3731
}
32+
{{- range .Values.k8gb.dnsZones }}
33+
{{ .loadBalancedZone }}:5353 {
34+
import k8gbplugins
35+
{{- if .extraPlugins }}
36+
{{- range .extraPlugins }}
37+
{{ . | nindent 8 }}
38+
{{- end }}
39+
{{- end }}
40+
}
41+
{{- end }}
42+
{{- with .extraServerBlocks -}}
43+
{{- tpl . $ | nindent 4 }}
44+
{{- end }}
45+
{{- if .Values.k8gb.feature.dynamicZones }}
46+
import ../dynamic/*.conf
3847
{{- end }}
39-
{{- with .extraServerBlocks -}}
40-
{{- tpl . $ | nindent 4 }}
41-
{{- end }}
48+
{{- end }}
49+
---
50+
{{- if .Values.k8gb.feature.dynamicZones }}
51+
apiVersion: v1
52+
kind: ConfigMap
53+
metadata:
54+
name: coredns-dynamic
55+
namespace: {{ .Release.Namespace }}
56+
data: {}
4257
{{- end }}

chart/k8gb/templates/deployment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ spec:
142142
value: "true"
143143
- name: METRICS_ADDRESS
144144
value: {{ .Values.k8gb.metricsAddress }}
145+
- name: FEATURE_DYNAMIC_ZONES
146+
value: {{ .Values.k8gb.feature.dynamicZones | quote }}
145147
{{- if .Values.tracing.enabled }}
146148
- image: {{ .Values.tracing.sidecarImage.repository }}:{{ .Values.tracing.sidecarImage.tag }}
147149
name: otel-collector

0 commit comments

Comments
 (0)