Skip to content

Commit 6a46e9e

Browse files
authored
Make the DNS view customizable by the user (#83)
1 parent 7665637 commit 6a46e9e

15 files changed

+180
-70
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ spec:
5757
disableTLSVerification: true # disable TLSVerification
5858
customCAPath: "/some/path/ca.crt" # path to a file which contians list of custom Certificate Authorities that can be used to verify SSL certifcates if 'disableTLSVerification' is set to 'false'. Host's default authorities will be used if not specified.
5959
defaultNetworkView: "some-view" # default network view
60+
defaultDNSView: "some-dns-view" # default DNS view
6061
wapiVersion: "2.12" # Web API Version of the Infoblox server
6162
```
6263
@@ -74,6 +75,7 @@ spec:
7475
instance:
7576
name: "production" # name of the InfobloxInstance
7677
networkView: "datacenter-network" # Infoblox network view that will be used
78+
dnsView: "some-dns-view" # DNS view for this pool (optional)
7779
subnets: # list of the subnets in the network view we want to get IP addresses from
7880
- cidr: "10.0.0.0/24" # subnet CIDR
7981
gateway: "10.0.0.1" # gateway that should ba assigned to the IP Address claim
@@ -98,7 +100,14 @@ We've currently only implemented one strategy for identifying the hostname of a
98100

99101
Our strategy uses the name of the CAPI `Machine` as the hostname. To determine the Machine name the provider follows the owner chain from the `IPAddressClaim` via the infrastructure provider resources to the `Machine`. This is used by searching through the owner references up to a depth of five.
100102

101-
To enable setting DNS entries, set the `spec.dnsZone` parameter on the `InfobloxIPPool` to your desired zone. The resulting DNS entries will then be `<machine name>.<dnsZone>`. The DNS view will be set to `default.<dnsZone>`.
103+
To enable setting DNS entries, set the `spec.dnsZone` parameter on the `InfobloxIPPool` to your desired zone. The resulting DNS entries will then be `<machine name>.<dnsZone>`.
104+
105+
The DNS view is determined in the following priority order:
106+
1. **Pool.spec.dnsView** - if explicitly set on the pool
107+
2. **Instance.spec.defaultDNSView** - if not set on pool but set on the instance
108+
3. **Derived from networkView** - if neither is set, follows the pattern:
109+
- If `networkView` is `"default"` or empty → DNS view is `"default"`
110+
- Otherwise → DNS view is `"default.<networkView>"` (e.g., `networkView: "production"` → DNS view `"default.production"`)
102111
103112
## Running Tests
104113

api/v1alpha1/condition_consts.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ const (
2121
AuthenticationFailedReason = "AuthenticationFailed"
2222
// NetworkViewNotFoundReason indicates that the specified network view could not be found on the Infoblox instance.
2323
NetworkViewNotFoundReason = "NetworkViewNotFound"
24+
// DNSViewNotFoundReason indicates that the specified DNS view could not be found on the Infoblox instance.
25+
DNSViewNotFoundReason = "DNSViewNotFound"
2426
// NetworkNotFoundReason indicates that the specified network could not be found on the Infoblox instance.
2527
NetworkNotFoundReason = "NetworkNotFound"
2628
)

api/v1alpha1/infobloxinstance_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ type InfobloxInstanceSpec struct {
4040
// InfobloxIPPools will inherit this value when not explicitly specifying a network view.
4141
// +optional
4242
DefaultNetworkView string `json:"defaultNetworkView,omitempty"`
43+
// DefaultDNSView is the default DNS view used when interacting with Infoblox.
44+
// InfobloxIPPools will inherit this value when not explicitly specifying a DNS view.
45+
// +optional
46+
DefaultDNSView string `json:"defaultDNSView,omitempty"`
4347
// DisableTLSVerification if set 'true', certificates for SSL commuunication with Infoblox instance will be not verified
4448
DisableTLSVerification bool `json:"disableTLSVerification,omitempty"`
4549
// CustomCAPath can be used to point Infoblox client to a file with a list of accepted certificate authorities. Only used if DisableTLSVerification is set to 'false'.

api/v1alpha1/infobloxippool_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ type InfobloxIPPoolSpec struct {
1616
// NetworkView defines Infoblox netwok view to be used with pool.
1717
// +optional
1818
NetworkView string `json:"networkView,omitempty"`
19+
// DNSView defines Infoblox DNS view to be used with pool.
20+
// +optional
21+
DNSView string `json:"dnsView,omitempty"`
1922
// DNSZone is the DNS zone within which hostnames will be allocated.
2023
// +optional
2124
DNSZone string `json:"dnsZone,omitempty"`

config/crd/bases/ipam.cluster.x-k8s.io_infobloxinstances.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ spec:
7373
a file with a list of accepted certificate authorities. Only used
7474
if DisableTLSVerification is set to 'false'.
7575
type: string
76+
defaultDNSView:
77+
description: |-
78+
DefaultDNSView is the default DNS view used when interacting with Infoblox.
79+
InfobloxIPPools will inherit this value when not explicitly specifying a DNS view.
80+
type: string
7681
defaultNetworkView:
7782
description: |-
7883
DefaultNetworkView is the default network view used when interacting with Infoblox.

config/crd/bases/ipam.cluster.x-k8s.io_infobloxippools.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ spec:
4848
spec:
4949
description: InfobloxIPPoolSpec defines the desired state of InfobloxIPPool.
5050
properties:
51+
dnsView:
52+
description: DNSView defines Infoblox DNS view to be used with pool.
53+
type: string
5154
dnsZone:
5255
description: DNSZone is the DNS zone within which hostnames will be
5356
allocated.

config/samples/infobloxippool.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ spec:
1010
- cidr: "10.0.0.0/24"
1111
gateway: "10.0.0.1"
1212
networkView: "some-view"
13+
dnsView: "some-dns-view"
1314
dnsZone: ""

internal/controllers/infobloxinstance.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ func (r *InfobloxInstanceReconciler) reconcile(ctx context.Context, instance *v1
112112
DisableTLSVerification: instance.Spec.DisableTLSVerification,
113113
CustomCAPath: instance.Spec.CustomCAPath,
114114
DefaultNetworkView: instance.Spec.DefaultNetworkView,
115+
DefaultDNSView: instance.Spec.DefaultDNSView,
115116
}
116117

117118
ibcl, err := r.NewInfobloxClientFunc(infoblox.Config{HostConfig: hc, AuthConfig: authConfig})
@@ -135,6 +136,19 @@ func (r *InfobloxInstanceReconciler) reconcile(ctx context.Context, instance *v1
135136
return ctrl.Result{}, nil
136137
}
137138

139+
// Check DNS view if specified
140+
if instance.Spec.DefaultDNSView != "" {
141+
if ok, err := ibcl.CheckDNSViewExists(instance.Spec.DefaultDNSView); err != nil || !ok {
142+
logger.Error(err, "could not find default DNS view", "dnsView", instance.Spec.DefaultDNSView)
143+
conditions.MarkFalse(instance,
144+
clusterv1.ReadyCondition,
145+
v1alpha1.DNSViewNotFoundReason,
146+
clusterv1.ConditionSeverityError,
147+
"could not find default DNS view: %s", err)
148+
return ctrl.Result{}, nil
149+
}
150+
}
151+
138152
conditions.MarkTrue(instance,
139153
clusterv1.ReadyCondition)
140154

internal/controllers/infobloxippool.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ func (r *InfobloxIPPoolReconciler) reconcile(ctx context.Context, pool *v1alpha1
137137
pool.Spec.NetworkView = ibclient.GetHostConfig().DefaultNetworkView
138138
}
139139

140+
dnsView := determineDNSView(pool.Spec.DNSView, ibclient.GetHostConfig().DefaultDNSView, pool.Spec.NetworkView)
141+
140142
// TODO: handle this in a better way
141143
if ok, err := ibclient.CheckNetworkViewExists(pool.Spec.NetworkView); err != nil || !ok {
142144
logger.Error(err, "could not find network view", "networkView", pool.Spec.NetworkView)
@@ -148,6 +150,19 @@ func (r *InfobloxIPPoolReconciler) reconcile(ctx context.Context, pool *v1alpha1
148150
return nil
149151
}
150152

153+
// Check DNS view if specified
154+
if dnsView != "" {
155+
if ok, err := ibclient.CheckDNSViewExists(dnsView); err != nil || !ok {
156+
logger.Error(err, "could not find DNS view", "dnsView", dnsView)
157+
conditions.MarkFalse(pool,
158+
clusterv1.ReadyCondition,
159+
v1alpha1.DNSViewNotFoundReason,
160+
clusterv1.ConditionSeverityError,
161+
"could not find DNS view: %s", err)
162+
return nil
163+
}
164+
}
165+
151166
for _, sub := range pool.Spec.Subnets {
152167
subnet, err := netip.ParsePrefix(sub.CIDR)
153168
if err != nil {
@@ -169,3 +184,21 @@ func (r *InfobloxIPPoolReconciler) reconcile(ctx context.Context, pool *v1alpha1
169184

170185
return nil
171186
}
187+
188+
// determineDNSView determines the DNS view to use based on the priority order:
189+
// 1. Pool.spec.dnsView (if set)
190+
// 2. Instance.spec.defaultDnsView (if not set on pool but set on instance)
191+
// 3. Derived from networkView (if neither is set)
192+
func determineDNSView(poolDNSView, instanceDefaultDNSView, networkView string) string {
193+
if poolDNSView != "" {
194+
return poolDNSView
195+
}
196+
if instanceDefaultDNSView != "" {
197+
return instanceDefaultDNSView
198+
}
199+
// fallback to old behavior: derive DNS view from networkView
200+
if networkView == "" || networkView == "default" {
201+
return "default"
202+
}
203+
return "default." + networkView
204+
}

internal/controllers/ipaddressclaim.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ func (h *InfobloxClaimHandler) EnsureAddress(ctx context.Context, address *ipamv
178178
}
179179

180180
var ipaddr netip.Addr
181-
ipaddr, err = h.ibclient.GetOrAllocateAddress(h.pool.Spec.NetworkView, subnet, hostName, h.pool.Spec.DNSZone, logger)
181+
dnsView := determineDNSView(h.pool.Spec.DNSView, h.ibclient.GetHostConfig().DefaultDNSView, h.pool.Spec.NetworkView)
182+
ipaddr, err = h.ibclient.GetOrAllocateAddress(h.pool.Spec.NetworkView, dnsView, subnet, hostName, h.pool.Spec.DNSZone, logger)
182183
if err != nil {
183184
continue
184185
}
@@ -233,7 +234,8 @@ func (h *InfobloxClaimHandler) ReleaseAddress(ctx context.Context) (*ctrl.Result
233234
continue
234235
}
235236

236-
err = h.ibclient.ReleaseAddress(h.pool.Spec.NetworkView, subnet, hostName, logger)
237+
dnsView := determineDNSView(h.pool.Spec.DNSView, h.ibclient.GetHostConfig().DefaultDNSView, h.pool.Spec.NetworkView)
238+
err = h.ibclient.ReleaseAddress(h.pool.Spec.NetworkView, dnsView, subnet, hostName, logger)
237239
if err != nil {
238240
// since ibclient.NotFoundError has a pointer receiver on it's Error() method, we can't use errors.As() here.
239241
if _, ok := err.(*ibclient.NotFoundError); !ok {

0 commit comments

Comments
 (0)