From f5b0ce3013d45517f3269a8dc113e1c18f0598b4 Mon Sep 17 00:00:00 2001 From: Michael Thamm Date: Wed, 25 Sep 2024 16:09:28 -0400 Subject: [PATCH] Chore: add checks and cleanup --- goss/goss_pebble_checks.yaml | 23 ++++++++++++++--------- goss/scripts/compare-dashboard-uids.sh | 2 +- goss/scripts/test-internal-routing.sh | 2 +- goss/scripts/test-k8s-probes.sh | 12 ++++++++++++ 4 files changed, 28 insertions(+), 11 deletions(-) create mode 100644 goss/scripts/test-k8s-probes.sh diff --git a/goss/goss_pebble_checks.yaml b/goss/goss_pebble_checks.yaml index 5b46ef6..2e05dca 100644 --- a/goss/goss_pebble_checks.yaml +++ b/goss/goss_pebble_checks.yaml @@ -1,17 +1,22 @@ # Charm Pebble health checks command: -{{ if .Vars.enable_pebble_tests }} + {{ if .Vars.enable_pebble_tests }} # $root is required to access the root context of the current template, # which refers to the entire data structure being passed into the template. # This provides access to .Vars and .Env in loops like the one below. {{- $root := . -}} {{range $app := .Vars.apps.k8s}} - pebble-{{$app.name}}: - exec: juju ssh -m {{ $root.Vars.model_name }} {{$app.name}}/0 /charm/bin/pebble health - exit-status: 0 - stdout: - have-patterns: - - healthy - stderr: "" + pebble-{{$app.name}}: + exec: juju ssh -m {{ $root.Vars.model_name }} {{$app.name}}/0 /charm/bin/pebble health + exit-status: 0 + stdout: + have-patterns: + - healthy + stderr: "" {{end}} -{{end}} \ No newline at end of file + k8s-charms: + exec: bash goss/scripts/test-k8s-probes.sh + exit-status: 0 + stdout: "" + stderr: "" + {{end}} \ No newline at end of file diff --git a/goss/scripts/compare-dashboard-uids.sh b/goss/scripts/compare-dashboard-uids.sh index f0e5044..685ac6d 100644 --- a/goss/scripts/compare-dashboard-uids.sh +++ b/goss/scripts/compare-dashboard-uids.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # Collect the UID from the charm dashboard and check if it is a subset of Grafana dashboard UIDs diff --git a/goss/scripts/test-internal-routing.sh b/goss/scripts/test-internal-routing.sh index 887c07f..4d81455 100644 --- a/goss/scripts/test-internal-routing.sh +++ b/goss/scripts/test-internal-routing.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # Obtain the alertmanager_url from Loki's loki-local-config.yaml and test routability from Loki's charm container diff --git a/goss/scripts/test-k8s-probes.sh b/goss/scripts/test-k8s-probes.sh new file mode 100644 index 0000000..707fa73 --- /dev/null +++ b/goss/scripts/test-k8s-probes.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +pod_ips=$(kubectl get pods -n cos-model -o jsonpath='{.items[*].status.podIP}' | tr ' ' '\n') + +# Loop over each IP address +echo "$pod_ips" | while IFS= read -r ip; do + + health=$(curl -sL http://$ip:38812/v1/health | jq -r '.result.healthy') + if [ "$health" != "true" ]; then + echo "Curl failed for $ip" + fi +done \ No newline at end of file