Skip to content

Commit

Permalink
ensure tests run helm uninstall in teardown
Browse files Browse the repository at this point in the history
Signed-off-by: ryanohnemus <[email protected]>
  • Loading branch information
ryanohnemus committed Jan 13, 2024
1 parent 4ae1006 commit 5f7bd35
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 20 deletions.
9 changes: 4 additions & 5 deletions tests/chunk-rollover/basic.bats
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ setup_file() {

teardown_file() {
if [[ "${SKIP_TEARDOWN:-no}" != "yes" ]]; then
helm uninstall -n $TEST_NAMESPACE fluent-bit
run kubectl delete namespace "$TEST_NAMESPACE"
rm -f ${HELM_VALUES_EXTRA_FILE}
fi
Expand Down Expand Up @@ -58,10 +59,9 @@ DETIK_CLIENT_NAMESPACE="${TEST_NAMESPACE}"


# replace the namespace for svc FQDN
sed -i "s/payload-receiver-service.test.svc.cluster.local/payload-receiver-service.$TEST_NAMESPACE.svc.cluster.local/g" "${BATS_TEST_DIRNAME}/resources/helm/fluentbit-basic.yaml"
helm upgrade --install --debug --create-namespace --namespace "$TEST_NAMESPACE" fluent-bit fluent/fluent-bit \
--values ${BATS_TEST_DIRNAME}/resources/helm/fluentbit-basic.yaml \
--set image.repository=${FLUENTBIT_IMAGE_REPOSITORY},image.tag=${FLUENTBIT_IMAGE_TAG} \
--set image.repository=${FLUENTBIT_IMAGE_REPOSITORY},image.tag=${FLUENTBIT_IMAGE_TAG},env[0].name=TEST_NAMESPACE,env[0].value=${TEST_NAMESPACE} \
--values "$HELM_VALUES_EXTRA_FILE" \
--timeout "${HELM_FB_TIMEOUT:-5m0s}" \
--wait
Expand All @@ -75,9 +75,8 @@ DETIK_CLIENT_NAMESPACE="${TEST_NAMESPACE}"
fi

# replace the namespace for crb
sed -i "s/namespace: test/namespace: $TEST_NAMESPACE/g" "${BATS_TEST_DIRNAME}/resources/manifests/rbac/cluster-role-binding.yaml"
kubectl create -f ${BATS_TEST_DIRNAME}/resources/manifests/rbac/cluster-role-binding.yaml --dry-run=client -o yaml | kubectl apply -f -

sed "s/namespace: test/namespace: $TEST_NAMESPACE/g" "${BATS_TEST_DIRNAME}/resources/manifests/rbac/cluster-role-binding.yaml" | kubectl apply -f -

# Time interval in seconds to check the pods status
INTERVAL=10

Expand Down
8 changes: 4 additions & 4 deletions tests/chunk-rollover/resources/helm/fluentbit-basic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ config:
[OUTPUT]
name http
match *
host payload-receiver-service.test.svc.cluster.local
host payload-receiver-service.${TEST_NAMESPACE}.svc.cluster.local
port 8088
retry_limit 3
storage.total_limit_size 300M
Expand All @@ -58,7 +58,7 @@ config:
[OUTPUT]
name http
match *
host payload-receiver-service.test.svc.cluster.local
host payload-receiver-service.${TEST_NAMESPACE}.svc.cluster.local
port 8088
retry_limit 3
storage.total_limit_size 300M
Expand All @@ -68,7 +68,7 @@ config:
[OUTPUT]
name http
match *
host payload-receiver-service.test.svc.cluster.local
host payload-receiver-service.${TEST_NAMESPACE}.svc.cluster.local
port 8088
retry_limit 3
storage.total_limit_size 300M
Expand All @@ -78,7 +78,7 @@ config:
[OUTPUT]
name http
match *
host payload-receiver-service.test.svc.cluster.local
host payload-receiver-service.${TEST_NAMESPACE}.svc.cluster.local
port 8088
retry_limit 3
storage.total_limit_size 300M
Expand Down
2 changes: 2 additions & 0 deletions tests/elasticsearch/basic.bats
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ setup_file() {

teardown_file() {
if [[ "${SKIP_TEARDOWN:-no}" != "yes" ]]; then
helm uninstall -n $TEST_NAMESPACE elasticsearch
helm uninstall -n $TEST_NAMESPACE fluent-bit
run kubectl delete namespace "$TEST_NAMESPACE"
rm -f ${HELM_VALUES_EXTRA_FILE}
fi
Expand Down
2 changes: 2 additions & 0 deletions tests/elasticsearch/compress.bats
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ setup_file() {

teardown_file() {
if [[ "${SKIP_TEARDOWN:-no}" != "yes" ]]; then
helm uninstall -n $TEST_NAMESPACE elasticsearch
helm uninstall -n $TEST_NAMESPACE fluent-bit
run kubectl delete namespace "$TEST_NAMESPACE"
rm -f ${HELM_VALUES_EXTRA_FILE}
fi
Expand Down
33 changes: 25 additions & 8 deletions tests/kubernetes-plugins/basic.bats
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ setup() {

teardown() {
if [[ "${SKIP_TEARDOWN:-no}" != "yes" ]]; then
helm uninstall fluent-bit -n $TEST_NAMESPACE
run kubectl delete namespace "$TEST_NAMESPACE"
rm -f ${HELM_VALUES_EXTRA_FILE}
fi
Expand All @@ -39,7 +40,7 @@ DETIK_CLIENT_NAME="kubectl -n $TEST_NAMESPACE"
DETIK_CLIENT_NAMESPACE="${TEST_NAMESPACE}"


@test "test fluent-bit reads k8s labels" {
function deploy_fluent_bit() {
helm repo add fluent https://fluent.github.io/helm-charts/ || helm repo add fluent https://fluent.github.io/helm-charts
helm repo update --fail-on-repo-update-fail

Expand All @@ -50,9 +51,27 @@ DETIK_CLIENT_NAMESPACE="${TEST_NAMESPACE}"
--timeout "${HELM_FB_TIMEOUT:-5m0s}" \
--wait

try "at most 15 times every 2s " \
"to find 1 pods named 'fluent-bit' " \
"with 'status' being 'running'"
kubectl wait pods -n "$TEST_NAMESPACE" -l "app.kubernetes.io/name=fluent-bit" --for condition=Ready --timeout=60s

# Now we wait until the nodeName is shown in the k8s spec, which surprisingly can take a second to update even after condition=Ready
attempts=0
while true; do
run kubectl get pods -l "app.kubernetes.io/name=fluent-bit" -o jsonpath='{.items[0].spec}'
if [[ "$output" != *"nodeName"* ]]; then
if [ "$attempt" -lt 5 ]; then
attempt=$(( attempt + 1 ))
sleep 5
else
fail "did not find fluent-bit nodeName after $attempt attempts"
fi
else
break
fi
done
}

@test "test fluent-bit adds k8s labels to records" {
deploy_fluent_bit

# The hello-world-1 container MUST be on the same node as the fluentbit worker, so we use a nodeSelector to specify the same node name
run kubectl get pods -l "app.kubernetes.io/name=fluent-bit" -o jsonpath='{.items[0].spec.nodeName}'
Expand All @@ -64,10 +83,8 @@ DETIK_CLIENT_NAMESPACE="${TEST_NAMESPACE}"
--overrides="{\"apiVersion\":\"v1\",\"spec\":{\"nodeSelector\":{\"kubernetes.io/hostname\":\"$node_name\"}}}" \
--command -- sh -c 'while true; do echo "hello world"; sleep 1; done'

try "at most 15 times every 5s " \
"to find 1 pods named 'hello-world-1' " \
"with 'status' being 'Running'"

kubectl wait pod/hello-world-1 -n "$TEST_NAMESPACE" --for condition=Ready --timeout=30s

# We are sleeping here specifically for the Fluent-Bit's tail input's
# configured Refresh_Interval to have enough time to detect the new pod's log file
# and to have processed part of it.
Expand Down
1 change: 1 addition & 0 deletions tests/kubernetes-plugins/resources/fluentbit-basic.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
kind: Deployment
fullnameOverride: fluent-bit-k8s-test
replicaCount: 1
rbac:
create: true
Expand Down
2 changes: 2 additions & 0 deletions tests/opensearch/basic.bats
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ function setup_file() {

function teardown_file() {
if [[ "${SKIP_TEARDOWN:-no}" != "yes" ]]; then
helm uninstall -n $TEST_NAMESPACE opensearch
helm uninstall -n $TEST_NAMESPACE fluent-bit
run kubectl delete namespace "$TEST_NAMESPACE"
rm -f ${HELM_VALUES_EXTRA_FILE}
fi
Expand Down
14 changes: 11 additions & 3 deletions tests/opensearch/hosted.bats
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ setup_file() {

teardown_file() {
if [[ "${SKIP_TEARDOWN:-no}" != "yes" ]]; then
run kubectl delete namespace "$TEST_NAMESPACE"
rm -f ${HELM_VALUES_EXTRA_FILE}
rm -f ${BATS_TEST_DIRNAME}/resources/helm/fluentbit-hosted.yaml
if [[ $HOSTED_OPENSEARCH_HOST != "localhost" ]]; then
helm uninstall -n $TEST_NAMESPACE fluent-bit
run kubectl delete namespace "$TEST_NAMESPACE"
rm -f ${HELM_VALUES_EXTRA_FILE}
rm -f ${BATS_TEST_DIRNAME}/resources/helm/fluentbit-hosted.yaml
fi
fi
}

Expand All @@ -47,6 +50,11 @@ DETIK_CLIENT_NAMESPACE="${TEST_NAMESPACE}"


@test "test fluent-bit forwards logs to AWS OpenSearch hosted service default index" {
if [[ $HOSTED_OPENSEARCH_HOST == "localhost" ]]; then
# then we aren't actually using a hosted opensearch
return
fi

envsubst < "${BATS_TEST_DIRNAME}/resources/helm/fluentbit-hosted.yaml.tpl" > "${BATS_TEST_DIRNAME}/resources/helm/fluentbit-hosted.yaml"

helm upgrade --install --debug --create-namespace --namespace "$TEST_NAMESPACE" fluent-bit fluent/fluent-bit \
Expand Down

0 comments on commit 5f7bd35

Please sign in to comment.