Skip to content

Commit

Permalink
fix(tests): update tests cert-manager, external-dns and argocd
Browse files Browse the repository at this point in the history
  • Loading branch information
jpeedroza committed May 11, 2022
1 parent a74d00d commit 783d5ca
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 166 deletions.
9 changes: 9 additions & 0 deletions vkpr-test/argocd/argocd.bats
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ setup_file() {
fi
}

@test "Create a session using the generated password" {
argo_password=$($VKPR_KUBECTL get secret/argocd-initial-admin-secret -o=jsonpath="{.data.password}" -n argocd | base64 -d)
curl -H "Host: argocd.localhost" http://127.0.0.1:8000/api/v1/session \
-d '{"username":"admin","password":"$argo_password"}'

refute_line --partial "null"
assert_success
}

@test "Use vkpr.yaml to merge values in argocd with helmArgs" {
testValue="argocd-test"
useVKPRfile changeYAMLfile ".argocd.helmArgs.fullnameOverride = \"${testValue}\" |
Expand Down
111 changes: 47 additions & 64 deletions vkpr-test/cert-manager/cert-manager.bats
Original file line number Diff line number Diff line change
@@ -1,76 +1,59 @@
VKPR_HOME=~/.vkpr
setup() {
load $VKPR_HOME/bats/bats-support/load.bash
load $VKPR_HOME/bats/bats-assert/load.bash
}

setup_file() {
#load 'common-setup'
#_common_setup
if [ "$VKPR_TEST_SKIP_SETUP" == "true" ]; then
echo "setup: skipping setup due to VKPR_TEST_SKIP_SETUP=true" >&3
else
echo "setup: starting private ACME server..." >&3
DOCKER0_IP=$(ifconfig docker0 | grep "inet " | awk '{printf $2}'0)
docker run --rm -d --name step -v step:/home/step \
-p 9000:9000 \
--add-host "host.k3d.internal:$DOCKER0_IP" \
-e "DOCKER_STEPCA_INIT_NAME=Smallstep" \
-e "DOCKER_STEPCA_INIT_DNS_NAMES=host.k3d.internal,localhost,step,$(hostname -f)" \
smallstep/step-ca sleep 1000
docker exec step step ca provisioner add acme --type ACME
docker exec kill -s 1 step

#docker logs -f step

echo "setup: copying root_ca.crt from ACME server..." >&3
docker cp step:/home/step/certs/root_ca.crt /tmp/
chmod +r /tmp/root_ca.crt

echo "setup: initialising infra. Cluster running on port 80 , 443 is manadatory for this test." >&3
rit vkpr infra start --http_port 80 --https_port 443 --default
$VKPR_KUBECTL wait --all-namespaces --for=condition=ready --timeout=20m pod --all
sleep 2

echo "setup: Copying root_ca.crt to cert-manager namespace.." >&3
$VKPR_HOME/bin/kubectl create namespace cert-manager
$VKPR_HOME/bin/kubectl create secret generic custom-ca-secret --namespace cert-manager \
--from-file=ca-certificates.crt=/tmp/root_ca.crt
load '../.bats/common.bats.bash'
_common_setup

if [ "$VKPR_TEST_SKIP_PROVISIONING" == "true" ]; then
echo "setup: skipping provisionig due to VKPR_TEST_SKIP_PROVISIONING=true" >&3
else
echo "setup: installing cert-manager..." >&3
rit vkpr cert-manager install digitalocean --issuer="staging" --issuer_solver="HTTP01" --default
fi
}

echo "setup: installing cert-manager...." >&3
rit vkpr cert-manager install custom-acme --email [email protected]
$VKPR_HOME/bin/kubectl wait --all-namespaces --for=condition=ready --timeout=5m pod --all
sleep 2
@test "Create a certificates to issue with applications" {
rit vkpr whoami install --domain="vkpr-test.com" --secure
sleep 10
$VKPR_KUBECTL get challenge -n vkpr | grep -q whoami-cert
assert_success
}

echo "setup: instaling ingress..." >&3
rit vkpr ingress install
$VKPR_HOME/bin/kubectl wait --all-namespaces --for=condition=ready --timeout=5m pod --all
sleep 2
@test "Use vkpr.yaml to merge values in cert-manager with helmArgs" {
testValue="cert-manager"
useVKPRfile changeYAMLfile ".cert-manager.helmArgs.fullnameOverride = \"${testValue}\""
sleep 10

echo "setup: installing whoami to create a certificate...." >&3
rit vkpr whoami install --domain "host.k3d.internal"
$VKPR_HOME/bin/kubectl wait --all-namespaces --for=condition=ready --timeout=5m pod --all
sleep 1m
fi
run $VKPR_HELM get values cert-manager -n cert-manager
assert_line --partial "fullnameOverride: cert-manager"
assert_success
}

setup() {
load $VKPR_HOME/bats/bats-support/load.bash
load $VKPR_HOME/bats/bats-assert/load.bash
}
teardown_file() {
if [ "$VKPR_TEST_SKIP_TEARDOWN" == "true" ]; then
echo "teardown: skipping uninstall due to VKPR_TEST_SKIP_TEARDOWN=true" >&3
else
echo "teardown: uninstalling cert-manager..." >&3
rit vkpr cert-manager remove
fi

@test "curl to https://host.k3d.internal must return a Smallstep certificate" {
run "$(curl -vvv -k --resolve host.k3d.internal:443:127.0.0.1 https://host.k3d.internal 2>&1 | awk 'BEGIN { cert=0 } /^\* Server certificate:/ { cert=1 } /^\*/ { if (cert) print }')"
actual="${lines[4]}"
trim "$actual"
actual="$TRIMMED"
expected="* issuer: O=Smallstep; CN=Smallstep Intermediate CA"
assert_equal "$actual" "$expected"

_common_teardown
}

useVKPRfile() {
cp vkpr.yaml vkpr.yaml.tmp
"$@"
mv vkpr.yaml.tmp vkpr.yaml
}

trim() {
local var="$*"
# remove leading whitespace characters
var="${var#"${var%%[![:space:]]*}"}"
# remove trailing whitespace characters
var="${var%"${var##*[![:space:]]}"}"
TRIMMED="$var"
#PARAMETERS:
# $1 - YQ_VALUES
# $2 - FORMULA_FLAGS (Optional)
changeYAMLfile() {
$VKPR_YQ eval -i "del(.cert-manager)" vkpr.yaml
$VKPR_YQ eval "${1}" vkpr.yaml > vkpr.yaml
rit vkpr cert-manager install digitalocean "$2" --issuer="staging" --issuer_solver="HTTP01" --default
}
124 changes: 48 additions & 76 deletions vkpr-test/external-dns/external-dns.bats
Original file line number Diff line number Diff line change
@@ -1,92 +1,64 @@
#
# External-DNS Tests
#
# We are starting a local PowerDNS authoritative server and creating a new "example.com" domain during setup.
# Mora bout this in https://doc.powerdns.com/authoritative/PowerDNS-Authoritative.pdf.
#
VKPR_HOME=~/.vkpr
setup() {
load $VKPR_HOME/bats/bats-support/load.bash
load $VKPR_HOME/bats/bats-assert/load.bash
}

setup_file() {
load 'common-setup'
_common_setup
if [ "$VKPR_TEST_SKIP_SETUP" == "true" ]; then
echo "setup: skipping setup due to VKPR_TEST_SKIP_SETUP=true" >&3
else
echo "setup: starting powerdns..." >&3
startPowerDNS
echo "setup: installing externaldns...." >&3
rit vkpr external-dns install --provider="powerDNS" --pdns_apiurl="http://host.k3d.internal"
echo "setup: creating and exposing annotated service...." >&3
$VKPR_HOME/bin/kubectl apply -f $BATS_TEST_DIRNAME/exposed-service.yml
fi
}
load '../.bats/common.bats.bash'
_common_setup

setup() {
load $VKPR_HOME/bats/bats-support/load.bash
load $VKPR_HOME/bats/bats-assert/load.bash
if [ "$VKPR_TEST_SKIP_PROVISIONING" == "true" ]; then
echo "setup: skipping provisionig due to VKPR_TEST_SKIP_PROVISIONING=true" >&3
else
echo "setup: installing external-dns..." >&3
rit vkpr external-dns install digitalocean
fi
}

@test "tests name resolution of k3d host internal alias (host.k3d.internal)" {
run getHostIP
}
@test "Use vkpr.yaml to merge values in external-dns with helmArgs" {
testValue="external-dns-test"
useVKPRfile changeYAMLfile ".external-dns.helmArgs.fullnameOverride = \"${testValue}\""
sleep 10

@test "dig test of powerdns container 'local.example.com'" {
# ensures powerdns has been initialized correctly
run digLocal
assert_output "127.0.0.1"
run $VKPR_HELM get values external-dns -n vkpr
assert_line --partial "fullnameOverride: external-dns-test"
assert_success
}

@test "testing if external-dns dealt with exposed annotated service" {
external_ip="$($VKPR_HOME/bin/kubectl get svc nginx -o jsonpath="{.status.loadBalancer.ingress[1].ip}")
$($VKPR_HOME/bin/kubectl get svc nginx -o jsonpath="{.status.loadBalancer.ingress[0].ip}")"
refute [ -z "$external_ip" ]
run digExposedService
assert_output "$external_ip"
}
@test "Use vkpr.yaml to change values in external-dns with globals" {
useVKPRfile changeYAMLfile ".global.namespace = \"vtg\" |
.external-dns.namespace = \"vkpr\"
"
sleep 10

getHostIP() {
$VKPR_HOME/bin/kubectl run --rm=true -i busybox --image=busybox --restart=Never \
--command -- ping -c1 -n host.k3d.internal | head -n1 | sed 's/.*(\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\)).*/\1/g'
}
run $VKPR_HELM ls -A -o=json | $VKPR_JQ -r '.[] | select(.name | contains("external-dns"))'

digLocal(){
dig @localhost -4 -p 8553 local.example.com +short
refute_line --partial "\"namespace\":\"vtg\""
assert_success
}

digExposedService(){
dig @localhost -4 -p 8553 nginx.example.com +short
teardown_file() {
if [ "$VKPR_TEST_SKIP_TEARDOWN" == "true" ]; then
echo "teardown: skipping uninstall due to VKPR_TEST_SKIP_TEARDOWN=true" >&3
else
echo "teardown: uninstalling external-dns..." >&3
rit vkpr external-dns remove
fi

_common_teardown
}

startPowerDNS() {
# creates rit powerdns credential
rit set credential --provider='powerdns' --fields="apikey" --values="mykey"
# define log/cache cfg (IMPORTANTE zerar os tempos de cache)
cp $BATS_TEST_DIRNAME/dnslog.j2 /tmp/dnslog.j2
# start powerdns
docker run -d --name pdns \
-p 8553:53/tcp -p 8553:53/udp -p 8081:8081 \
-e PDNS_AUTH_API_KEY=mykey \
-e TEMPLATE_FILES="dnslog" \
-v /tmp/dnslog.j2:/etc/powerdns/templates.d/dnslog.j2:ro \
powerdns/pdns-auth-45
# creates dns zone
docker exec pdns pdnsutil create-zone example.com
docker exec pdns pdnsutil set-kind example.com native
docker exec pdns pdnsutil set-meta example.com SOA-EDIT INCEPTION-INCREMENT
docker exec pdns pdnsutil increase-serial example.com
docker exec pdns pdnsutil add-record example.com local A 60 "127.0.0.1"
useVKPRfile() {
cp vkpr.yaml vkpr.yaml.tmp
"$@"
mv vkpr.yaml.tmp vkpr.yaml
}

teardown_file() {
if [ "$VKPR_TEST_SKIP_TEARDOWN" == "true" ]; then
echo "teardown: skipping teardown due to VKPR_TEST_SKIP_TEARDOWN=true" >&3
else
echo "teardown: removing annotated service...." >&3
$VKPR_HOME/bin/kubectl delete --ignore-not-found=true -f $BATS_TEST_DIRNAME/exposed-service.yml
echo "teardown: stopping power-dns...." >&3
docker rm -f pdns
echo "teardown: uninstalling external-dns...." >&3
rit vkpr external-dns remove
fi
_common_teardown
}
#PARAMETERS:
# $1 - YQ_VALUES
# $2 - FORMULA_FLAGS (Optional)
changeYAMLfile() {
$VKPR_YQ eval -i "del(.external-dns)" vkpr.yaml
$VKPR_YQ eval "${1}" vkpr.yaml > vkpr.yaml
rit vkpr external-dns install digitalocean "$2"
}
19 changes: 7 additions & 12 deletions vkpr/external-dns/install/aws/src/unix/formula/formula.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ runFormula() {
checkGlobalConfig "false" "false" "external-dns.metrics" "EXTERNAL_DNS_METRICS"

local VKPR_EXTERNAL_DNS_VALUES; VKPR_EXTERNAL_DNS_VALUES="$(dirname "$0")"/utils/external-dns.yaml
local RIT_CREDENTIALS_PATH=~/.rit/credentials/default

startInfos
addRepoExternalDNS
Expand All @@ -27,18 +26,14 @@ addRepoExternalDNS() {
}

installExternalDNS() {
if [[ ! -f $RIT_CREDENTIALS_PATH/$PROVIDER ]]; then
echoColor "red" "Doesn't exists credential $PROVIDER to use in formula, create her or use the provider flag."
else
echoColor "bold" "$(echoColor "green" "Installing External-DNS AWS...")"
local YQ_VALUES=".rbac.create = true"
settingExternalDNS
echoColor "bold" "$(echoColor "green" "Installing External-DNS AWS...")"
local YQ_VALUES=".rbac.create = true"
settingExternalDNS

$VKPR_YQ eval "$YQ_VALUES" "$VKPR_EXTERNAL_DNS_VALUES" \
| $VKPR_HELM upgrade -i --version "$VKPR_EXTERNAL_DNS_VERSION" \
--namespace "$VKPR_ENV_EXTERNAL_DNS_NAMESPACE" --create-namespace \
--wait -f - external-dns bitnami/external-dns
fi
$VKPR_YQ eval "$YQ_VALUES" "$VKPR_EXTERNAL_DNS_VALUES" \
| $VKPR_HELM upgrade -i --version "$VKPR_EXTERNAL_DNS_VERSION" \
--namespace "$VKPR_ENV_EXTERNAL_DNS_NAMESPACE" --create-namespace \
--wait -f - external-dns bitnami/external-dns
}


Expand Down
21 changes: 8 additions & 13 deletions vkpr/external-dns/install/digitalocean/src/unix/formula/formula.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ runFormula() {
checkGlobalConfig "false" "false" "external-dns.metrics" "EXTERNAL_DNS_METRICS"

local VKPR_EXTERNAL_DNS_VALUES; VKPR_EXTERNAL_DNS_VALUES="$(dirname "$0")"/utils/external-dns.yaml
local RIT_CREDENTIALS_PATH=~/.rit/credentials/default

startInfos
addRepoExternalDNS
Expand All @@ -27,18 +26,14 @@ addRepoExternalDNS() {
}

installExternalDNS() {
if [[ ! -f $RIT_CREDENTIALS_PATH/$PROVIDER ]]; then
echoColor "red" "Doesn't exists credential $PROVIDER to use in formula, create her or use the provider flag."
else
echoColor "bold" "$(echoColor "green" "Installing External-DNS Digital Ocean...")"
local YQ_VALUES=".rbac.create = true"
settingExternalDNS

$VKPR_YQ eval "$YQ_VALUES" "$VKPR_EXTERNAL_DNS_VALUES" \
| $VKPR_HELM upgrade -i --version "$VKPR_EXTERNAL_DNS_VERSION" \
--namespace "$VKPR_ENV_EXTERNAL_DNS_NAMESPACE" --create-namespace \
--wait -f - external-dns bitnami/external-dns
fi
echoColor "bold" "$(echoColor "green" "Installing External-DNS Digital Ocean...")"
local YQ_VALUES=".rbac.create = true"
settingExternalDNS

$VKPR_YQ eval "$YQ_VALUES" "$VKPR_EXTERNAL_DNS_VALUES" \
| $VKPR_HELM upgrade -i --version "$VKPR_EXTERNAL_DNS_VERSION" \
--namespace "$VKPR_ENV_EXTERNAL_DNS_NAMESPACE" --create-namespace \
--wait -f - external-dns bitnami/external-dns
}


Expand Down
3 changes: 2 additions & 1 deletion vkpr/whoami/install/src/unix/formula/formula.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ installWhoami() {
local HELM_NAMESPACE="--create-namespace --namespace=$VKPR_ENV_WHOAMI_NAMESPACE"
settingWhoami

# shellcheck disable=SC2086
$VKPR_YQ eval "$YQ_VALUES" "$VKPR_WHOAMI_VALUES" \
| $VKPR_HELM upgrade -i --version "$VKPR_WHOAMI_VERSION" "$HELM_NAMESPACE" \
| $VKPR_HELM upgrade -i --version "$VKPR_WHOAMI_VERSION" $HELM_NAMESPACE \
--wait -f - whoami cowboysysop/whoami
}

Expand Down

0 comments on commit 783d5ca

Please sign in to comment.