Skip to content
This repository was archived by the owner on Apr 24, 2024. It is now read-only.

Commit 9b893a2

Browse files
committed
Bugfixes
1 parent 0fec8ac commit 9b893a2

File tree

4 files changed

+33
-6
lines changed

4 files changed

+33
-6
lines changed

config/rbac/role.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,21 @@ rules:
5252
- ipmaps/finalizers
5353
verbs:
5454
- update
55+
- apiGroups:
56+
- networking.k8s.io
57+
resources:
58+
- networkpolicies
59+
verbs:
60+
- create
61+
- delete
62+
- get
63+
- list
64+
- patch
65+
- update
66+
- watch
67+
- apiGroups:
68+
- networking.k8s.io
69+
resources:
70+
- networkpolicies/finalizers
71+
verbs:
72+
- update

internal/controller/dnsresolver_controller.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ func init() {
112112
//+kubebuilder:rbac:groups=dns.k8s.delta10.nl,resources=dnsresolvers/finalizers,verbs=update
113113
//+kubebuilder:rbac:groups=dns.k8s.delta10.nl,resources=ipmaps,verbs=get;list;watch;create;update;patch;delete
114114
//+kubebuilder:rbac:groups=dns.k8s.delta10.nl,resources=ipmaps/finalizers,verbs=update
115+
//+kubebuilder:rbac:groups=networking.k8s.io,resources=networkpolicies,verbs=get;list;watch;create;update;patch;delete
116+
//+kubebuilder:rbac:groups=networking.k8s.io,resources=networkpolicies/finalizers,verbs=update
115117
//+kubebuilder:rbac:groups="",resources=endpoints,verbs=get;list;watch
116118

117119
// Reconcile makes sure that each DNSResolver has an associated IPMap.
@@ -169,7 +171,7 @@ func (r *DNSResolverReconciler) Reconcile(ctx context.Context, req ctrl.Request)
169171
get_err := r.Get(ctx, req.NamespacedName, ip_map)
170172
ip_map.ObjectMeta.Labels = resolver.ObjectMeta.Labels
171173

172-
// Make sure the ownerRef on `resolver` is set to the IPMap we are working on
174+
// Make sure the ownerRef on to the IPMap we are working on is set to resolver
173175
// This will fail if IPMap is already owned by another resource
174176
if err := controllerutil.SetControllerReference(&resolver, ip_map, r.Scheme); err != nil {
175177
return default_result_obj, err

internal/controller/ipmap.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func closeConns(conns []*dns.Conn) (err error) {
5050

5151
// Look up IPv4 and IPv6 addresses, return as an IP slice and return smallest TTL received
5252
func lookupDomain(domain string, conns []*dns.Conn) (ips []net.IP, ttl uint32, err error) {
53+
debug := ctrl.Log.V(1)
5354
ttl = uint32(Config.MaxRequeueTime)
5455
ips = make([]net.IP, 0, 10)
5556

@@ -69,6 +70,9 @@ func lookupDomain(domain string, conns []*dns.Conn) (ips []net.IP, ttl uint32, e
6970
ttl = min(ttl, rec.Hdr.Ttl)
7071
}
7172
}
73+
} else if err == nil && res.Rcode == dns.RcodeNameError {
74+
success = true
75+
debug.Info("No records received for domain %v", domain)
7276
}
7377
}
7478
if !success {
@@ -174,17 +178,18 @@ func ipmapUpdate(
174178
}
175179

176180
// Remove domains that are no longer requested
181+
doms := &ip_map.Data.Domains
177182
OUTER:
178-
for i, old_domain := range ip_map.Data.Domains {
183+
for i := len(*doms)-1; i >= 0; i-- {
179184
for _, domain := range domainList {
180-
if domain == old_domain.Domain {
185+
if domain == (*doms)[i].Domain {
181186
continue OUTER
182187
}
183188
}
184189
// not found in requested domains
185-
newlen := len(ip_map.Data.Domains) - 1
186-
ip_map.Data.Domains[i] = ip_map.Data.Domains[newlen]
187-
ip_map.Data.Domains = ip_map.Data.Domains[:newlen]
190+
newlen := len(*doms) - 1
191+
(*doms)[i] = (*doms)[newlen]
192+
(*doms) = (*doms)[:newlen]
188193
updated = true
189194
}
190195

internal/controller/networkpolicy.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ func NPGenerate(ip_map *dnsv1alpha1.IPMap) (np *networking.NetworkPolicy) {
3030
Name: ip_map.Name,
3131
Namespace: ip_map.Namespace,
3232
Labels: ip_map.Labels,
33+
OwnerReferences: ip_map.OwnerReferences,
3334
},
3435
Spec: networking.NetworkPolicySpec{
3536
Egress: []networking.NetworkPolicyEgressRule{
3637
{To: tolist},
3738
},
3839
},
3940
}
41+
4042
return
4143
}
4244

0 commit comments

Comments
 (0)