Skip to content

Commit

Permalink
MGMT-7115: When running test_parallel, VIPs DNS cannot be resolved fr…
Browse files Browse the repository at this point in the history
…om host (#928)

- Created DNS forwarding file(s) in /etc/NetworkManager/dnsmasq.d by using terraform.
  • Loading branch information
ori-amizur authored Jun 29, 2021
1 parent c9fb951 commit 51d5d1c
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 4 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ _test: $(REPORTS) _test_setup
test_parallel:
$(MAKE) start_load_balancer START_LOAD_BALANCER=true
skipper make $(SKIPPER_PARAMS) _test_parallel
scripts/assisted_deployment.sh set_all_vips_dns

_test_setup:
rm -rf /tmp/assisted_test_infra_logs
Expand Down
17 changes: 17 additions & 0 deletions discovery-infra/test_infra/helper_classes/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import time
from collections import Counter
from typing import List, Union, Optional
from textwrap import dedent

import requests
import waiting
Expand Down Expand Up @@ -621,6 +622,21 @@ def wait_for_install(self, timeout=consts.CLUSTER_INSTALLATION_TIMEOUT):
timeout=timeout,
)

def _set_dns(self):
cluster = self.api_client.cluster_get(self.id)
cluster_name = cluster.name
base_domain = cluster.base_dns_domain
main_cidr = self.nodes.controller.get_machine_cidr()
nameserver_ip = str(IPNetwork(main_cidr).ip + 1)
fname = f"/etc/NetworkManager/dnsmasq.d/openshift-{cluster_name}.conf"
contents = dedent(f"""
server=/api.{cluster_name}.{base_domain}/{nameserver_ip}
server=/.apps.{cluster_name}.{base_domain}/{nameserver_ip}
""")
self.nodes.controller.tf.change_variables(
{"dns_forwarding_file": contents, "dns_forwarding_file_name": fname}
)

@JunitTestCase()
def prepare_for_installation(self, static_network_config=None, **kwargs):
self.update_config(**kwargs)
Expand Down Expand Up @@ -655,6 +671,7 @@ def prepare_for_installation(self, static_network_config=None, **kwargs):

if self._config.platform == consts.Platforms.NONE:
self._configure_load_balancer()
self._set_dns()

def download_kubeconfig_no_ingress(self, kubeconfig_path: str = None):
self.api_client.download_kubeconfig_no_ingress(self.id, kubeconfig_path or self._config.kubeconfig_path)
Expand Down
20 changes: 16 additions & 4 deletions scripts/assisted_deployment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ function destroy_all() {
make destroy
}

function update_conf_file() {
FILE="/etc/NetworkManager/conf.d/dnsmasq.conf"
if ! [ -f "${FILE}" ]; then
echo -e "[main]\ndns=dnsmasq" | sudo tee $FILE
fi
}

function set_dns() {
NAMESPACE_INDEX=${1:-0}
if [ "${BASE_DNS_DOMAINS}" != '""' ]; then
Expand All @@ -19,10 +26,7 @@ function set_dns() {
exit 1
fi

FILE="/etc/NetworkManager/conf.d/dnsmasq.conf"
if ! [ -f "${FILE}" ]; then
echo -e "[main]\ndns=dnsmasq" | sudo tee $FILE
fi
update_conf_file
sudo truncate -s0 /etc/NetworkManager/dnsmasq.d/openshift-${CLUSTER_NAME}.conf
echo "server=/api.${CLUSTER_NAME}-${NAMESPACE}.${BASE_DOMAIN}/${NAMESERVER_IP}" | sudo tee -a /etc/NetworkManager/dnsmasq.d/openshift-${CLUSTER_NAME}.conf
echo "server=/.apps.${CLUSTER_NAME}-${NAMESPACE}.${BASE_DOMAIN}/${NAMESERVER_IP}" | sudo tee -a /etc/NetworkManager/dnsmasq.d/openshift-${CLUSTER_NAME}.conf
Expand All @@ -32,6 +36,14 @@ function set_dns() {
echo "Finished setting dns"
}

function set_all_vips_dns() {
update_conf_file

sudo systemctl reload NetworkManager

echo "Finished setting all vips dns"
}

# Delete after pushing fix to dev-scripts
function wait_for_cluster() {
echo "Nothing to do"
Expand Down
3 changes: 3 additions & 0 deletions skipper.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ volumes:
- /tmp:/tmp/
- /dev/:/dev
- /run/udev:/run/udev

# Network manager dnsmasq. Mounted to allow the container to write dnsmasq config files to HOST Network Manager
- /etc/NetworkManager/dnsmasq.d:/etc/NetworkManager/dnsmasq.d
env_file:
- skipper.env

6 changes: 6 additions & 0 deletions terraform_files/baremetal/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,9 @@ data "libvirt_network_dns_host_template" "assisted_service" {
ip = var.bootstrap_in_place ? var.single_node_ip : var.ingress_vip
hostname = "assisted-service-assisted-installer.apps.${var.cluster_name}.${var.cluster_domain}"
}

resource "local_file" "dns_forwarding_config" {
count = var.dns_forwarding_file != "" && var.dns_forwarding_file_name != "" ? 1 : 0
content = var.dns_forwarding_file
filename = var.dns_forwarding_file_name
}
13 changes: 13 additions & 0 deletions terraform_files/baremetal/variables-libvirt.tf
Original file line number Diff line number Diff line change
Expand Up @@ -237,3 +237,16 @@ variable "libvirt_dns_records" {
description = "DNS records to be added to the libvirt network"
default = {}
}

variable "dns_forwarding_file" {
type = string
description = "Contents of dns forwarding file"
default = ""
}


variable "dns_forwarding_file_name" {
type = string
description = "The file name of dns forwarding file"
default = ""
}
6 changes: 6 additions & 0 deletions terraform_files/none/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ resource "local_file" "load_balancer_config" {
filename = format("/etc/nginx/conf.d/stream_%s.conf", replace(var.load_balancer_ip,"/[:.]/" , "_"))
}

resource "local_file" "dns_forwarding_config" {
count = var.dns_forwarding_file != "" && var.dns_forwarding_file_name != "" ? 1 : 0
content = var.dns_forwarding_file
filename = var.dns_forwarding_file_name
}

resource "libvirt_domain" "master" {
count = 2

Expand Down
15 changes: 15 additions & 0 deletions terraform_files/none/variables-libvirt.tf
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,18 @@ variable "load_balancer_config_file" {
description = "Contents of load balancer configuration file"
default = ""
}

variable "dns_forwarding_file" {
type = string
description = "Contents of dns forwarding file"
default = ""
}


variable "dns_forwarding_file_name" {
type = string
description = "The file name of dns forwarding file"
default = ""
}


0 comments on commit 51d5d1c

Please sign in to comment.