From 0c13ee70f4b9d0dee5061b7e79ca0025d08696b0 Mon Sep 17 00:00:00 2001 From: Praveen Kumar Date: Tue, 19 Dec 2023 14:29:33 +0530 Subject: [PATCH] dns: Don't use dnsmasq service as container This PR is going to use systemd dnsmasq service instead running it as part of container and then consuming it. It should work with current bundles and also updated bundle which doesn't have dnsmasq container cached. We are doing it because in future we want to use OVN-Kubernetes as network plugin for OCP/OKD and with our current solution it is not able to resolve the IP of the dnsmasq container so everything around dns is broken which this PR fixes. ``` === using openshift-sdn === $ oc rsh busybox-sleep-pod sh-5.1# ping 10.88.0.8 PING 10.88.0.8 (10.88.0.8) 56(84) bytes of data. 64 bytes from 10.88.0.8: icmp_seq=1 ttl=63 time=0.878 ms 64 bytes from 10.88.0.8: icmp_seq=2 ttl=63 time=0.068 ms === using ovn-k === sh-5.1# ping 10.88.0.8 PING 10.88.0.8 (10.88.0.8) 56(84) bytes of data. ^C --- 10.88.0.8 ping statistics --- 15 packets transmitted, 0 received, 100% packet loss, time 14368ms ``` --- pkg/crc/services/dns/dns.go | 11 +++++------ pkg/crc/services/dns/template.go | 7 ++----- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/pkg/crc/services/dns/dns.go b/pkg/crc/services/dns/dns.go index a8c79608d8..fd1fb739ec 100644 --- a/pkg/crc/services/dns/dns.go +++ b/pkg/crc/services/dns/dns.go @@ -20,9 +20,8 @@ import ( const ( dnsServicePort = 53 - dnsContainerIP = "10.88.0.8" publicDNSQueryURI = "quay.io" - crcDnsmasqService = "crc-dnsmasq.service" + dnsmasqService = "dnsmasq.service" ) func init() { @@ -54,12 +53,12 @@ func setupDnsmasq(serviceConfig services.ServicePostStartConfig) error { return err } sd := systemd.NewInstanceSystemdCommander(serviceConfig.SSHRunner) - if state, err := sd.Status(crcDnsmasqService); err != nil || state != states.Running { - if err := sd.Enable(crcDnsmasqService); err != nil { + if state, err := sd.Status(dnsmasqService); err != nil || state != states.Running { + if err := sd.Enable(dnsmasqService); err != nil { return err } } - return sd.Start(crcDnsmasqService) + return sd.Start(dnsmasqService) } func getResolvFileValues(serviceConfig services.ServicePostStartConfig) (network.ResolvFileValues, error) { @@ -89,7 +88,7 @@ func dnsServers(serviceConfig services.ServicePostStartConfig) ([]network.NameSe if err != nil { return nil, err } - return append([]network.NameServer{{IPAddress: dnsContainerIP}}, orgResolvValues.NameServers...), nil + return append([]network.NameServer{{IPAddress: serviceConfig.IP}}, orgResolvValues.NameServers...), nil } func CheckCRCLocalDNSReachable(ctx context.Context, serviceConfig services.ServicePostStartConfig) (string, error) { diff --git a/pkg/crc/services/dns/template.go b/pkg/crc/services/dns/template.go index 95e6181a82..8db3824fd6 100644 --- a/pkg/crc/services/dns/template.go +++ b/pkg/crc/services/dns/template.go @@ -8,9 +8,7 @@ import ( ) const ( - dnsmasqConfTemplate = `user=root -port= {{ .Port }} -bind-interfaces + dnsmasqConfTemplate = `listen-address={{ .IP }} expand-hosts log-queries local=/{{ .ClusterName}}.{{ .BaseDomain }}/ @@ -38,7 +36,6 @@ func createDnsmasqDNSConfig(serviceConfig services.ServicePostStartConfig) error dnsmasqConfFileValues := dnsmasqConfFileValues{ BaseDomain: domain, Hostname: serviceConfig.BundleMetadata.Nodes[0].Hostname, - Port: dnsServicePort, AppsDomain: serviceConfig.BundleMetadata.ClusterInfo.AppsDomain, ClusterName: serviceConfig.BundleMetadata.ClusterInfo.ClusterName, IP: serviceConfig.IP, @@ -50,7 +47,7 @@ func createDnsmasqDNSConfig(serviceConfig services.ServicePostStartConfig) error return err } - return serviceConfig.SSHRunner.CopyDataPrivileged([]byte(dnsConfig), "/var/srv/dnsmasq.conf", 0644) + return serviceConfig.SSHRunner.CopyDataPrivileged([]byte(dnsConfig), "/etc/dnsmasq.d/crc-dnsmasq.conf", 0644) } func createDNSConfigFile(values dnsmasqConfFileValues, tmpl string) (string, error) {