-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated acceptance tests to run rancher HA on k3s. GNUMakefile and sc…
…ripts
- Loading branch information
Showing
9 changed files
with
268 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FROM golang:1.12.16-alpine3.11 | ||
RUN apk -U add bash git gcc musl-dev make docker-cli curl ca-certificates | ||
WORKDIR /go/src/github.com/terraform-providers/terraform-provider-rancher2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
echo "==> Running dockerized acceptance testing..." | ||
|
||
# Setting docker | ||
DOCKER_NAME=docker | ||
DOCKER_URL="https://download.docker.com/linux/static/stable/x86_64/docker-17.03.2-ce.tgz" | ||
DOCKER_BIN=$(which ${DOCKER_NAME} || echo none) | ||
if [ "${DOCKER_BIN}" == "none" ] ; then | ||
export DOCKER_BIN=${TESTACC_TEMP_DIR}/${DOCKER_NAME} | ||
curl -sL ${DOCKER_URL} | tar -xzf - | ||
mv docker/docker ${DOCKER_BIN} && rm -rf docker | ||
chmod 755 ${DOCKER_BIN} | ||
fi | ||
|
||
BUILDER_TAG=${BUILDER_TAG:-"terraform-provider-rancher2_builder"} | ||
|
||
${DOCKER_BIN} build -t ${BUILDER_TAG} -f $(dirname $0)/Dockerfile.builder . | ||
|
||
${DOCKER_BIN} run -i --rm \ | ||
-v /var/run/docker.sock:/var/run/docker.sock \ | ||
-v $PWD:/go/src/github.com/terraform-providers/terraform-provider-rancher2 \ | ||
${BUILDER_TAG} make testacc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
# Setting temporary directory | ||
export TEMP_DIR=${TEMP_DIR:-$(dirname $0)"/tmp"} | ||
## Converting to absolute path if needed | ||
case $TEMP_DIR in | ||
/*) ;; | ||
*) TEMP_DIR=$(pwd)/${TEMP_DIR} ;; | ||
esac | ||
|
||
if [ ! -d ${TEMP_DIR} ]; then | ||
mkdir ${TEMP_DIR} | ||
fi | ||
|
||
EXPOSE_HOST_PORTS=${EXPOSE_HOST_PORTS:-"false"} | ||
|
||
# Setting required software | ||
DOCKER_NAME=docker | ||
DOCKER_URL="https://download.docker.com/linux/static/stable/x86_64/docker-17.03.2-ce.tgz" | ||
DOCKER_BIN=$(which ${DOCKER_NAME} || echo none) | ||
if [ "${DOCKER_BIN}" == "none" ] ; then | ||
export DOCKER_BIN=${TEMP_DIR}/${DOCKER_NAME} | ||
curl -sL ${DOCKER_URL} | tar -xzf - | ||
mv docker/docker ${DOCKER_BIN} && rm -rf docker | ||
chmod 755 ${DOCKER_BIN} | ||
fi | ||
DOCKER_LIST_NAME=${DOCKER_LIST_NAME:-"docker_ids"} | ||
DOCKER_LIST=${TEMP_DIR}"/"${DOCKER_LIST_NAME} | ||
## curl | ||
CURL_BIN="${DOCKER_BIN} run -i --rm curlimages/curl" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -x | ||
|
||
source $(dirname $0)/gotestacc_vars.sh | ||
|
||
# Setting default vars | ||
## k3s | ||
K3S_DOCKER_IMAGE=${K3S_DOCKER_IMAGE:-"rancher/k3s"} | ||
K3S_KUBECONFIG_NAME=${K3S_KUBECONFIG_NAME:-"k3s_kubeconfig.yaml"} | ||
K3S_KUBECONFIG=${TEMP_DIR}"/"${K3S_KUBECONFIG_NAME} | ||
K3S_PORT=${K3S_PORT:-6443} | ||
K3S_INGRESS_PORT=${K3S_INGRESS_PORT:-8080} | ||
K3S_INGRESS_PORT_TLS=${K3S_INGRESS_PORT_TLS:-8443} | ||
K3S_SECRET=${K3S_SECRET:-"somethingtotallyrandom"} | ||
K3S_VERSION=${K3S_VERSION:-"v1.18.2-rc2-k3s1"} | ||
|
||
# Setting exposed ports | ||
if [ "${EXPOSE_HOST_PORTS}" == "true" ]; then | ||
k3s_exposed_port="-p ${K3S_PORT}:${K3S_PORT}" | ||
k3s_ingress_port="-p ${K3S_INGRESS_PORT}:80 -p ${K3S_INGRESS_PORT_TLS}:443" | ||
fi | ||
|
||
# Starting k3s | ||
## server | ||
K3S_SERVER=$(${DOCKER_BIN} run -d \ | ||
${k3s_exposed_port} \ | ||
${k3s_ingress_port} \ | ||
--privileged \ | ||
--tmpfs /run \ | ||
--tmpfs /var/run \ | ||
-e K3S_CLUSTER_SECRET=${K3S_SECRET} \ | ||
-e K3S_KUBECONFIG_OUTPUT=/tmp/${K3S_KUBECONFIG_NAME} \ | ||
-e K3S_KUBECONFIG_MODE=666 \ | ||
${K3S_DOCKER_IMAGE}:${K3S_VERSION} server --https-listen-port ${K3S_PORT}) | ||
echo ${K3S_SERVER} >> ${DOCKER_LIST} | ||
K3S_SERVER_IP=$(${DOCKER_BIN} inspect ${K3S_SERVER} -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}') | ||
K3S_URL="https://${K3S_SERVER_IP}:${K3S_PORT}" | ||
|
||
## agent | ||
k3s_node=$(${DOCKER_BIN} run -d \ | ||
--privileged \ | ||
--tmpfs /run \ | ||
--tmpfs /var/run \ | ||
-e K3S_URL=${K3S_URL} \ | ||
-e K3S_CLUSTER_SECRET=${K3S_SECRET} \ | ||
${K3S_DOCKER_IMAGE}:${K3S_VERSION} agent) | ||
echo ${k3s_node} >> ${DOCKER_LIST} | ||
k3s_node_ip=$(${DOCKER_BIN} inspect ${k3s_node} -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}') | ||
|
||
## Waiting for start | ||
while [ "${k3s_ready}" != "pong" ]; do | ||
sleep 5 | ||
k3s_ready=$(${CURL_BIN} -sk ${K3S_URL}/ping || echo starting rancher k3s cluster) | ||
done | ||
sleep 2 | ||
|
||
${DOCKER_BIN} cp ${K3S_SERVER}:/tmp/${K3S_KUBECONFIG_NAME} ${K3S_KUBECONFIG} | ||
|
||
export K3S_SERVER=${K3S_SERVER} | ||
export K3S_SERVER_IP=${K3S_SERVER_IP} | ||
export K3S_VERSION=${K3S_VERSION} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -x | ||
|
||
source $(dirname $0)/gotestacc_vars.sh | ||
|
||
# Setting vars | ||
K3S_SERVER=${K3S_SERVER:-""} | ||
if [ ${K3S_SERVER} == "" ]; then | ||
echo "[ERROR] K3S_SERVER env var should be provided" | ||
exit 1 | ||
fi | ||
K3S_SERVER_IP=${K3S_SERVER_IP:-"$(${DOCKER_BIN} inspect ${K3S_SERVER} -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}')"} | ||
K3S_INGRESS_PORT_TLS=${K3S_INGRESS_PORT_TLS:-8443} | ||
KUBECTL_BIN=${KUBECTL_BIN:-"${DOCKER_BIN} exec -i ${K3S_SERVER} kubectl"} | ||
|
||
## cert-manager | ||
CERTMANAGER_VERSION=${CERTMANAGER_VERSION:-"v0.14.3"} | ||
CERTMANAGER_CRD=${CERTMANAGER_CRD:-"https://github.com/jetstack/cert-manager/releases/download/${CERTMANAGER_VERSION}/cert-manager.crds.yaml"} | ||
CERTMANAGER_NS=${CERTMANAGER_NS:-"cert-manager"} | ||
|
||
## rancher | ||
RANCHER_VERSION=${RANCHER_VERSION:-"v2.4.2"} | ||
RANCHER_NS=${RANCHER_NS:-"cattle-system"} | ||
RANCHER_HOSTNAME="rancher.${K3S_SERVER_IP}.xip.io" | ||
|
||
# Installing helm charts | ||
## cert-manager | ||
cat << EOF > ${TEMP_DIR}"/cert-manager.yaml" | ||
--- | ||
kind: Namespace | ||
apiVersion: v1 | ||
metadata: | ||
name: ${CERTMANAGER_NS} | ||
labels: | ||
app: ${CERTMANAGER_NS} | ||
--- | ||
apiVersion: helm.cattle.io/v1 | ||
kind: HelmChart | ||
metadata: | ||
name: cert-manager | ||
namespace: kube-system | ||
spec: | ||
chart: cert-manager | ||
repo: https://charts.jetstack.io | ||
targetNamespace: ${CERTMANAGER_NS} | ||
version: ${CERTMANAGER_VERSION} | ||
EOF | ||
|
||
${KUBECTL_BIN} apply -f ${CERTMANAGER_CRD} | ||
${DOCKER_BIN} cp ${TEMP_DIR}"/cert-manager.yaml" ${K3S_SERVER}:/var/lib/rancher/k3s/server/manifests/ | ||
## waiting for HelmChart cert-manager | ||
while [[ $(${KUBECTL_BIN} -n kube-system get helmchart cert-manager -o 'jsonpath={..spec.version}') != ${CERTMANAGER_VERSION} ]] ; | ||
do echo "Waiting for HelmChart rancher" && sleep 2; | ||
done | ||
## waiting for helm-install-cert-manager | ||
helm_job=$(${KUBECTL_BIN} -n kube-system get helmchart cert-manager -o 'jsonpath={..status.jobName}') | ||
while [[ $(${KUBECTL_BIN} -n kube-system get jobs ${helm_job} -o 'jsonpath={..status.conditions[?(@.type=="Complete")].status}') != "True" ]] ; | ||
do echo "waiting for ${helm_job} job" && sleep 10; | ||
done | ||
## waiting for cert-manager | ||
while [[ $(for i in $(${KUBECTL_BIN} -n ${CERTMANAGER_NS} get pods -l app.kubernetes.io/instance=cert-manager -o 'jsonpath={..status.conditions[?(@.type=="Ready")].status}'); do if [ $i != "True" ]; then break; fi; done && echo $i) != "True" ]] ; | ||
do echo "waiting for cert-manager pods" && sleep 10; | ||
done | ||
|
||
## rancher | ||
cat << EOF > ${TEMP_DIR}"/rancher.yaml" | ||
--- | ||
kind: Namespace | ||
apiVersion: v1 | ||
metadata: | ||
name: ${RANCHER_NS} | ||
--- | ||
apiVersion: helm.cattle.io/v1 | ||
kind: HelmChart | ||
metadata: | ||
name: rancher | ||
namespace: kube-system | ||
spec: | ||
chart: rancher | ||
repo: https://releases.rancher.com/server-charts/latest | ||
targetNamespace: ${RANCHER_NS} | ||
version: ${RANCHER_VERSION} | ||
set: | ||
hostname: ${RANCHER_HOSTNAME} | ||
certmanager.version: ${CERTMANAGER_VERSION} | ||
replicas: 1 | ||
EOF | ||
|
||
${DOCKER_BIN} cp ${TEMP_DIR}"/rancher.yaml" ${K3S_SERVER}:/var/lib/rancher/k3s/server/manifests/ | ||
## waiting for HelmChart rancher | ||
while [[ $(${KUBECTL_BIN} -n kube-system get helmchart rancher -o 'jsonpath={..spec.version}') != ${RANCHER_VERSION} ]] ; | ||
do echo "Waiting for HelmChart rancher" && sleep 2; | ||
done | ||
## waiting for helm-install-rancher | ||
helm_job=$(${KUBECTL_BIN} -n kube-system get helmchart rancher -o 'jsonpath={..status.jobName}') | ||
while [[ $(${KUBECTL_BIN} -n kube-system get jobs ${helm_job} -o 'jsonpath={..status.conditions[?(@.type=="Complete")].status}') != "True" ]] ; | ||
do echo "waiting for ${helm_job} job" && sleep 10; | ||
done | ||
## waiting for rancher | ||
while [[ $(for i in $(${KUBECTL_BIN} -n ${RANCHER_NS} get pods -l app=rancher -o 'jsonpath={..status.conditions[?(@.type=="Ready")].status}'); do if [ $i != "True" ]; then break; fi; done && echo $i) != "True" ]] ; | ||
do echo "waiting for rancher pods" && sleep 10; | ||
done | ||
## Waiting for rancher server start | ||
while [ "$(${CURL_BIN} -sk https://${RANCHER_HOSTNAME}/ping || echo starting)" != "pong" ]; | ||
do echo "waiting for rancher service" && sleep 5; | ||
done | ||
|
||
export RANCHER_INSECURE=true | ||
export RANCHER_URL="https://${RANCHER_HOSTNAME}" | ||
export RANCHER_VERSION=${RANCHER_VERSION} | ||
if [ ${EXPOSE_HOST_PORTS} == "true" ]; then | ||
export RANCHER_EXPOSED_URL="https://rancher.127.0.0.1.xip.io:${K3S_INGRESS_PORT_TLS}" | ||
fi | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters