Skip to content

Commit

Permalink
dns: Don't use dnsmasq service as container
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
praveenkumar committed Dec 19, 2023
1 parent a51ff98 commit 0c13ee7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
11 changes: 5 additions & 6 deletions pkg/crc/services/dns/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
7 changes: 2 additions & 5 deletions pkg/crc/services/dns/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import (
)

const (
dnsmasqConfTemplate = `user=root
port= {{ .Port }}
bind-interfaces
dnsmasqConfTemplate = `listen-address={{ .IP }}
expand-hosts
log-queries
local=/{{ .ClusterName}}.{{ .BaseDomain }}/
Expand Down Expand Up @@ -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,
Expand All @@ -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) {
Expand Down

0 comments on commit 0c13ee7

Please sign in to comment.