From 1fa6758b66ef3bc215581f6fe12a0ef67c2a0da3 Mon Sep 17 00:00:00 2001 From: bom Date: Wed, 10 Nov 2021 12:18:17 +0100 Subject: [PATCH] use custom-kubectl-context for k3d setup, connect to correct health endpoint --- .../resources/local-integration-test/README.md | 6 ------ .../local-integration-test/certificate.yaml | 2 +- .../resources/local-integration-test/kubectl.sh | 17 +++++++++++++++++ .../setup-local-s3-on-k3d.sh | 8 +++++--- .../local-integration-test/start-k3d.sh | 2 +- 5 files changed, 24 insertions(+), 11 deletions(-) create mode 100755 src/test/resources/local-integration-test/kubectl.sh diff --git a/src/test/resources/local-integration-test/README.md b/src/test/resources/local-integration-test/README.md index fc5d376..8bfd0c7 100644 --- a/src/test/resources/local-integration-test/README.md +++ b/src/test/resources/local-integration-test/README.md @@ -1,9 +1,3 @@ -# Requirements - -* Restic (install with: `sudo apt install restic` ) -* (optional) AWS-CLI - - # Usage `setup-local-s3.sh [BUCKET_NAME]`: diff --git a/src/test/resources/local-integration-test/certificate.yaml b/src/test/resources/local-integration-test/certificate.yaml index 28437c8..4c39759 100644 --- a/src/test/resources/local-integration-test/certificate.yaml +++ b/src/test/resources/local-integration-test/certificate.yaml @@ -1,4 +1,4 @@ -apiVersion: cert-manager.io/v1alpha2 +apiVersion: cert-manager.io/v1 kind: Certificate metadata: name: localstack-cert diff --git a/src/test/resources/local-integration-test/kubectl.sh b/src/test/resources/local-integration-test/kubectl.sh new file mode 100755 index 0000000..bb1311f --- /dev/null +++ b/src/test/resources/local-integration-test/kubectl.sh @@ -0,0 +1,17 @@ +# Set the default kube context if present +DEFAULT_KUBE_CONTEXTS="$HOME/.kube/config" +if test -f "${DEFAULT_KUBE_CONTEXTS}" +then + export KUBECONFIG="$DEFAULT_KUBE_CONTEXTS" +fi + +# Additional contexts should be in ~/.kube/custom-contexts/ +CUSTOM_KUBE_CONTEXTS="$HOME/.kube/custom-contexts" +mkdir -p "${CUSTOM_KUBE_CONTEXTS}" +OIFS="$IFS" +IFS=$'\n' +for contextFile in `find "${CUSTOM_KUBE_CONTEXTS}" -type f -name "*.yml"` +do + export KUBECONFIG="$contextFile:$KUBECONFIG" +done +IFS="$OIFS" diff --git a/src/test/resources/local-integration-test/setup-local-s3-on-k3d.sh b/src/test/resources/local-integration-test/setup-local-s3-on-k3d.sh index b445528..f9a7e40 100755 --- a/src/test/resources/local-integration-test/setup-local-s3-on-k3d.sh +++ b/src/test/resources/local-integration-test/setup-local-s3-on-k3d.sh @@ -4,6 +4,9 @@ function main() ./start-k3d.sh + source kubectl.sh + kubectl config use-context k3d-nextcloud + kubectl apply -f https://github.com/jetstack/cert-manager/releases/download/v1.5.4/cert-manager.yaml kubectl apply -f localstack.yaml @@ -17,15 +20,14 @@ function main() echo echo "[INFO] Waiting for localstack health endpoint" - until curl --connect-timeout 3 -s -f -o /dev/null "k3stesthost/health" + until curl --connect-timeout 3 -s -f -o /dev/null --insecure "https://k3stesthost/health" do - sleep 5 + sleep 1 done echo kubectl get secret localstack-secret -o jsonpath="{.data.ca\.crt}" | base64 --decode > ca.crt - #aws --endpoint-url=http://localhost s3 mb s3://$bucket_name export RESTIC_PASSWORD="test-password" restic init --cacert ca.crt -r s3://k3stesthost/$bucket_name diff --git a/src/test/resources/local-integration-test/start-k3d.sh b/src/test/resources/local-integration-test/start-k3d.sh index 0fd99ff..463dee3 100755 --- a/src/test/resources/local-integration-test/start-k3d.sh +++ b/src/test/resources/local-integration-test/start-k3d.sh @@ -1 +1 @@ -k3d cluster create nextcloud --k3s-arg '--tls-san cloudhost@loadbalancer' --port 8080:80@loadbalancer --port 8443:443@loadbalancer --api-port 6443 \ No newline at end of file +KUBECONFIG=~/.kube/custom-contexts/k3d-config.yml k3d cluster create nextcloud --k3s-arg '--tls-san cloudhost@loadbalancer' --port 80:80@loadbalancer --port 443:443@loadbalancer --api-port 6443 --kubeconfig-update-default \ No newline at end of file