Skip to content

Commit 990a6a6

Browse files
authored
Registry reachable in cluster (#71)
* Enable CoreDNS fallthrough for cluster.local DNS resolution Pods inside a bink cluster cannot resolve bink-managed DNS names like registry.cluster.local because CoreDNS's kubernetes plugin handles the cluster.local zone but only resolves Kubernetes services/pods/endpoints. After kubeadm deploys CoreDNS, patch the Corefile to change "fallthrough in-addr.arpa ip6.arpa" to just "fallthrough". This removes the zone restriction so all unresolved cluster.local queries (not just reverse DNS) fall through to the forward plugin, which reaches the bink dnsmasq container via the node's /etc/resolv.conf. Fixes: #70 Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Alice Frosi <afrosi@redhat.com> * Add integration test for registry.cluster.local DNS resolution from pods Runs nslookup from the busybox pod to verify CoreDNS fallthrough resolves bink-managed DNS names inside the cluster. Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Alice Frosi <afrosi@redhat.com> --------- Signed-off-by: Alice Frosi <afrosi@redhat.com>
1 parent 67c26a5 commit 990a6a6

3 files changed

Lines changed: 43 additions & 0 deletions

File tree

internal/cluster/init.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,14 @@ func (c *Cluster) Init(ctx context.Context, opts InitOptions) error {
135135
return fmt.Errorf("failed to install CoreDNS: %w", err)
136136
}
137137

138+
// Enable fallthrough in CoreDNS so that non-Kubernetes cluster.local names
139+
// (e.g. registry.cluster.local) are forwarded to the bink DNS container.
140+
c.logger.Info("")
141+
c.logger.Info("=== Patching CoreDNS for cluster.local fallthrough ===")
142+
if err := kubeClient.EnableCoreDNSFallthrough(ctx); err != nil {
143+
return fmt.Errorf("failed to enable CoreDNS fallthrough: %w", err)
144+
}
145+
138146
// Patch CoreDNS to run as root - CRI-O doesn't set ambient capabilities
139147
// for non-root users, so NET_BIND_SERVICE doesn't take effect for UID 65532
140148
c.logger.Info("")

internal/kube/resources.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"context"
88
"encoding/json"
99
"fmt"
10+
"strings"
1011
"time"
1112

1213
policyv1 "k8s.io/api/policy/v1"
@@ -127,6 +128,34 @@ func (c *Client) DeleteNode(ctx context.Context, nodeName string) error {
127128
return nil
128129
}
129130

131+
// EnableCoreDNSFallthrough patches the CoreDNS ConfigMap so that unresolved
132+
// cluster.local queries fall through to the forward plugin (which reaches the
133+
// bink dnsmasq container via the node's /etc/resolv.conf).
134+
func (c *Client) EnableCoreDNSFallthrough(ctx context.Context) error {
135+
cm, err := c.clientset.CoreV1().ConfigMaps("kube-system").Get(ctx, "coredns", metav1.GetOptions{})
136+
if err != nil {
137+
return fmt.Errorf("getting coredns ConfigMap: %w", err)
138+
}
139+
140+
corefile, ok := cm.Data["Corefile"]
141+
if !ok {
142+
return fmt.Errorf("Corefile key not found in coredns ConfigMap")
143+
}
144+
145+
updated := strings.Replace(corefile, "fallthrough in-addr.arpa ip6.arpa", "fallthrough", 1)
146+
if updated == corefile {
147+
return nil
148+
}
149+
150+
cm.Data["Corefile"] = updated
151+
_, err = c.clientset.CoreV1().ConfigMaps("kube-system").Update(ctx, cm, metav1.UpdateOptions{})
152+
if err != nil {
153+
return fmt.Errorf("updating coredns ConfigMap: %w", err)
154+
}
155+
156+
return nil
157+
}
158+
130159
// LabelNode adds the given labels to a node, overwriting any that already exist.
131160
func (c *Client) LabelNode(ctx context.Context, nodeName string, labels map[string]string) error {
132161
patch := map[string]interface{}{

test/integration/cluster_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@ var _ = Describe("Cluster Lifecycle", func() {
143143
Expect(err).ToNot(HaveOccurred())
144144
Expect(pod.Status.Phase).To(Equal(corev1.PodRunning))
145145

146+
By("Verifying pod can resolve registry.cluster.local via CoreDNS")
147+
nslookupOutput, err := helpers.PodExec(kubeconfigPath, "default", "busybox-test",
148+
[]string{"nslookup", "registry.cluster.local"})
149+
Expect(err).ToNot(HaveOccurred(), "nslookup registry.cluster.local should succeed from pod")
150+
Expect(nslookupOutput).To(ContainSubstring(config.RegistryStaticIP))
151+
146152
By("Cleaning up the busybox pod")
147153
helpers.DeletePod(kubeClient, "default", "busybox-test")
148154

0 commit comments

Comments
 (0)