From d17c7e7fc01d5346fda17145e26fea0b4ca330a1 Mon Sep 17 00:00:00 2001 From: Amir Zarrinkafsh Date: Tue, 2 Feb 2021 09:53:44 +1100 Subject: [PATCH] refactor(suites): simplify kubernetes suite (#1680) This PR achieves the following goals: * Utilise upstream version of kind instead of a patched version which allows binding to networks other than the default "kind" * Utilises the registry cache which is setup one level above the kind cluster The former point was required to successfully run our integration tests in a Kubernetes environment, however this is now possible without running a patched version of kind. The second point is because DockerHub has introduced rate limiting for container downloads. If there are a large number of CI jobs nodes may occasionally be rejected due to the Kubernetes suite not pulling down from the registry cache. --- internal/suites/example/compose/kind/Dockerfile | 4 ++-- internal/suites/example/compose/kind/config.yml | 8 +++++--- internal/suites/example/compose/kind/docker-compose.yml | 4 ++++ internal/suites/example/compose/kind/patch-kubeconfig.sh | 3 +-- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/internal/suites/example/compose/kind/Dockerfile b/internal/suites/example/compose/kind/Dockerfile index 26de50bb..df179cca 100644 --- a/internal/suites/example/compose/kind/Dockerfile +++ b/internal/suites/example/compose/kind/Dockerfile @@ -3,8 +3,8 @@ FROM alpine:3.13.1 WORKDIR /kind RUN apk add --no-cache bash curl docker && \ - curl -Lo kind https://github.com/clems4ever/kind/releases/download/docker-network/kind && chmod +x kind && \ - curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/v1.13.0/bin/linux/amd64/kubectl && chmod +x kubectl + curl -Lo kind https://github.com/kubernetes-sigs/kind/releases/download/v0.10.0/kind-linux-amd64 && chmod +x kind && \ + curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/v1.20.2/bin/linux/amd64/kubectl && chmod +x kubectl ADD entrypoint.sh entrypoint.sh ADD patch-kubeconfig.sh patch-kubeconfig.sh diff --git a/internal/suites/example/compose/kind/config.yml b/internal/suites/example/compose/kind/config.yml index cbd5b9d6..a29dbac8 100644 --- a/internal/suites/example/compose/kind/config.yml +++ b/internal/suites/example/compose/kind/config.yml @@ -1,4 +1,6 @@ kind: Cluster -apiVersion: kind.sigs.k8s.io/v1alpha3 -networking: - dockerNetwork: authelia_authelianet \ No newline at end of file +apiVersion: kind.x-k8s.io/v1alpha4 +containerdConfigPatches: + - |- + [plugins."io.containerd.grpc.v1.cri".registry.mirrors."registrycache.internal:5000"] + endpoint = ["http://registrycache.internal:5000"] \ No newline at end of file diff --git a/internal/suites/example/compose/kind/docker-compose.yml b/internal/suites/example/compose/kind/docker-compose.yml index aa8f0570..7870c490 100644 --- a/internal/suites/example/compose/kind/docker-compose.yml +++ b/internal/suites/example/compose/kind/docker-compose.yml @@ -9,6 +9,8 @@ services: - './example/kube:/authelia' - './example/compose/kind/config.yml:/etc/kind/config.yml' command: 'kubectl port-forward --address 0.0.0.0 -n authelia service/nginx-ingress-controller-service 8080:443' + environment: + - KIND_EXPERIMENTAL_DOCKER_NETWORK=authelia_authelianet networks: authelianet: aliases: @@ -28,6 +30,8 @@ services: - 'kind-volume:/kind/config' - './example/compose/kind/entrypoint-dashboard.sh:/entrypoint-dashboard.sh' command: '/entrypoint-dashboard.sh' + environment: + - KIND_EXPERIMENTAL_DOCKER_NETWORK=authelia_authelianet networks: authelianet: aliases: diff --git a/internal/suites/example/compose/kind/patch-kubeconfig.sh b/internal/suites/example/compose/kind/patch-kubeconfig.sh index 4dcbfa59..e103a5b7 100755 --- a/internal/suites/example/compose/kind/patch-kubeconfig.sh +++ b/internal/suites/example/compose/kind/patch-kubeconfig.sh @@ -3,5 +3,4 @@ # This script patches the kubeconfig generated by Kind in order to access the cluster container via this container echo "Patching Kubeconfig to target Kube container without link" -CONTROL_PLANE_IP=`docker inspect -f '{{(index .NetworkSettings.Networks "authelia_authelianet").IPAddress}}' kind-control-plane` -sed -i "s/127.0.0.1:.*/$CONTROL_PLANE_IP:6443/" `kind get kubeconfig-path --name="kind"` \ No newline at end of file +sed -i "s/127.0.0.1:.*/$(docker inspect -f '{{(index .NetworkSettings.Networks "authelia_authelianet").IPAddress}}' kind-control-plane):6443/" ${KUBECONFIG} \ No newline at end of file