-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(tests): update tests cert-manager, external-dns and argocd
- Loading branch information
Showing
6 changed files
with
121 additions
and
166 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 |
---|---|---|
@@ -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 | ||
} |
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 |
---|---|---|
@@ -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" | ||
} |
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