1
0
mirror of https://github.com/ubuntu/microk8s.git synced 2021-05-23 02:23:41 +03:00

Add resolv.conf to forward list in coredns (#1625)

This commit is contained in:
Riya John
2020-12-08 22:44:07 +05:30
committed by GitHub
parent bcc4607ac3
commit fa61b2272f
4 changed files with 101 additions and 45 deletions

View File

@@ -32,7 +32,7 @@ data:
fallthrough in-addr.arpa ip6.arpa
}
prometheus :9153
forward . 8.8.8.8 8.8.4.4
forward . $NAMESERVERS
cache 30
loop
reload

View File

@@ -3,10 +3,40 @@
set -e
source $SNAP/actions/common/utils.sh
KUBECTL="$SNAP/kubectl --kubeconfig=${SNAP_DATA}/credentials/client.config"
# Apply the dns yaml
# We do not need to see dns pods running at this point just give some slack
echo "Enabling DNS"
read -ra ARGUMENTS <<< "$1"
if [[ ! -z "${ARGUMENTS[@]}" ]]
then
nameservers="${ARGUMENTS[@]}"
else
nameservers="8.8.8.8,8.8.4.4"
fi
# if none passed use resolv.conf
if [[ $nameservers == "/etc/resolv.conf" ]]
then
nameserver_str="/etc/resolv.conf"
else
REGEX_IP_ADDR='^[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$'
# get ip addresses separated by , as a list
nameservers_list=(${nameservers//,/ })
nameserver_str=""
for nameserver in "${nameservers_list[@]}"
do
if [[ $nameserver =~ $REGEX_IP_ADDR ]]
then
nameserver_str="${nameserver_str}${nameserver} "
else
echo "Your input value ($nameserver) is not a valid IP address"
exit 1
fi
done
fi
echo "Applying manifest"
ALLOWESCALATION="false"
if grep -e ubuntu /proc/version | grep 16.04 &> /dev/null
@@ -15,6 +45,7 @@ then
fi
declare -A map
map[\$ALLOWESCALATION]="$ALLOWESCALATION"
map[\$NAMESERVERS]="$nameserver_str"
use_manifest coredns apply "$(declare -p map)"
sleep 5

View File

@@ -1,42 +1,42 @@
import pytest
import os
import platform
from subprocess import PIPE, STDOUT, CalledProcessError, check_call, run
import pytest
import sh
import yaml
from utils import (
microk8s_disable,
microk8s_enable,
microk8s_reset,
wait_for_namespace_termination,
wait_for_pod_state,
)
from validators import (
validate_ambassador,
validate_cilium,
validate_dns_dashboard,
validate_fluentd,
validate_forward,
validate_gpu,
validate_storage,
validate_ingress,
validate_ambassador,
validate_gpu,
validate_istio,
validate_knative,
validate_registry,
validate_forward,
validate_metrics_server,
validate_fluentd,
validate_jaeger,
validate_keda,
validate_knative,
validate_kubeflow,
validate_linkerd,
validate_metallb_config,
validate_metrics_server,
validate_multus,
validate_portainer,
validate_prometheus,
validate_rbac,
validate_registry,
validate_storage,
validate_cilium,
validate_multus,
validate_kubeflow,
validate_metallb_config,
validate_prometheus,
validate_traefik,
validate_coredns_config,
validate_portainer,
)
from utils import (
microk8s_enable,
wait_for_pod_state,
wait_for_namespace_termination,
microk8s_disable,
microk8s_reset,
)
from subprocess import PIPE, STDOUT, CalledProcessError, check_call, run
class TestAddons(object):
@@ -335,15 +335,19 @@ class TestAddons(object):
print("Disabling Portainer")
microk8s_disable("portainer")
def test_backup_restore(self):
"""
Test backup and restore commands.
"""
print('Checking dbctl backup and restore')
if os.path.exists('backupfile.tar.gz'):
os.remove('backupfile.tar.gz')
check_call("/snap/bin/microk8s.dbctl --debug backup -o backupfile".split())
check_call("/snap/bin/microk8s.dbctl --debug restore backupfile.tar.gz".split())
@pytest.mark.skipif(
os.environ.get('UNDER_TIME_PRESSURE') == 'True',
reason="Skipping dns tests as we are under time pressure",
)
def test_dns_addon(self):
ip_ranges = "8.8.8.8,1.1.1.1"
print("Enabling DNS")
microk8s_enable("{}:{}".format("dns", ip_ranges), timeout_insec=500)
wait_for_pod_state("", "kube-system", "running", label="k8s-app=kube-dns")
print("Validating DNS config")
validate_coredns_config(ip_ranges)
print("Disabling DNS")
microk8s_disable("dns")
def test_traefik(self):
"""
@@ -374,6 +378,16 @@ class TestAddons(object):
print("Disabling keda")
microk8s_disable("keda")
def test_backup_restore(self):
"""
Test backup and restore commands.
"""
print('Checking dbctl backup and restore')
if os.path.exists('backupfile.tar.gz'):
os.remove('backupfile.tar.gz')
check_call("/snap/bin/microk8s.dbctl --debug backup -o backupfile".split())
check_call("/snap/bin/microk8s.dbctl --debug restore backupfile.tar.gz".split())
@pytest.mark.addon_args
def test_invalid_addon():

View File

@@ -490,18 +490,15 @@ def validate_metallb_config(ip_ranges="192.168.0.105"):
assert ip_range in out
def validate_traefik():
def validate_coredns_config(ip_ranges="8.8.8.8,1.1.1.1"):
"""
Validate traefik
Validate dns
"""
wait_for_pod_state("", "traefik", "running", label="name=traefik-ingress-lb")
def validate_portainer():
"""
Validate portainer
"""
wait_for_pod_state("", "portainer", "running", label="app.kubernetes.io/name=portainer")
out = kubectl("get configmap coredns -n kube-system -o jsonpath='{.data.Corefile}'")
expected_forward_val = "forward ."
for ip_range in ip_ranges.split(","):
expected_forward_val = expected_forward_val + " " + ip_range
assert expected_forward_val in out
def validate_keda():
@@ -517,3 +514,17 @@ def validate_keda():
scaledObject = kubectl("-n gonuts get scaledobject.keda.sh")
assert "stan-scaledobject" in scaledObject
kubectl("delete -f {}".format(manifest))
def validate_traefik():
"""
Validate traefik
"""
wait_for_pod_state("", "traefik", "running", label="name=traefik-ingress-lb")
def validate_portainer():
"""
Validate portainer
"""
wait_for_pod_state("", "portainer", "running", label="app.kubernetes.io/name=portainer")