Skip to content

Commit

Permalink
Simplify the checks and include an iface check
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelThamm committed Oct 3, 2024
1 parent 65637cb commit 060d743
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 24 deletions.
12 changes: 5 additions & 7 deletions goss/goss.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
# Import other goss.yaml files
gossfile:
goss_az_checks.yaml: {}
goss_k8s_checks.yaml: {}
goss_model_checks.yaml: {}
goss_network_checks.yaml: {}
goss_pebble_checks.yaml: {}
goss_complex_checks.yaml: {}
# goss_k8s_checks.yaml: {}
# goss_model_checks.yaml: {}
# goss_network_checks.yaml: {}
# goss_pebble_checks.yaml: {}

command:
# Grafana post-relation checks
{{ if .Vars.enable_post_relation_tests }}
grafana-related-dashboards:
exec: bash goss/scripts/compare-dashboard-uids.sh {{ .Vars.model_name }} {{ .Vars.apps.k8s.grafana.name }} {{ .Vars.apps.k8s.alertmanager.name }}
exit-status: 0
stdout:
have-patterns:
- "Match found."
stderr: ""
{{ end }}
12 changes: 10 additions & 2 deletions goss/goss_az_checks.yaml → goss/goss_complex_checks.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Availability Zone checks
command:
{{ if .Vars.enable_az_tests }}
{{ if .Vars.enable_machine_tests }}
app-az-distribution:
exec: juju status --format=json -m {{ .Vars.model_name }}
exit-status: 0
Expand All @@ -11,4 +11,12 @@ command:
- "0"
- "1"
- "2"
{{ end }}
{{ end }}

relations-over-grafana-dashboard-interface:
exec: bash goss/scripts/test-relation-if-interface.sh cos-model grafana grafana-dashboard grafana_dashboard
exit-status: 0
stdout:
- "INFO"
- "!ERROR"
stderr: ""
2 changes: 0 additions & 2 deletions goss/goss_k8s_checks.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Kubernetes-type checks
command:
{{ if .Vars.enable_k8s_tests }}
pod-status-healthy:
exec: kubectl get pods -n {{ .Vars.model_name }} --output=json
exit-status: 0
Expand All @@ -20,4 +19,3 @@ command:
not:
- "false"
stderr: ""
{{ end }}
2 changes: 0 additions & 2 deletions goss/goss_model_checks.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Deployment relation checks
command:
{{ if .Vars.enable_model_tests }}
validate-model-configuration:
exec: juju status --format=json -m {{ .Vars.model_name }} | jq -r '.applications'
exit-status: 0
Expand All @@ -18,4 +17,3 @@ command:
and:
- {have-key: {{ .Vars.apps.k8s.alertmanager.name }}}
stderr: ""
{{ end }}
2 changes: 0 additions & 2 deletions goss/goss_network_checks.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Networking checks
command:
{{ if .Vars.enable_network_tests }}
loki-reachable-via-ingress-url:
exec: curl -s $(juju ssh -m {{ .Vars.model_name }} --container loki {{ .Vars.apps.k8s.loki.name }}/0 cat /etc/loki/loki-local-config.yaml | yq -r '.ruler.external_url')/ready
exit-status: 0
Expand All @@ -15,4 +14,3 @@ command:
have-patterns:
- 'Status code: 200'
stderr: ""
{{ end }}
4 changes: 1 addition & 3 deletions goss/goss_pebble_checks.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Charm Pebble health checks
command:
{{ 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.
Expand All @@ -18,5 +17,4 @@ command:
exec: bash goss/scripts/test-k8s-probes.sh
exit-status: 0
stdout: ""
stderr: ""
{{end}}
stderr: ""
29 changes: 29 additions & 0 deletions goss/scripts/test-relation-if-interface.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/sh

# For all charms in $model_name that have the $expected_relation:$expected_interface, check if they are related to the $expected_related_charm

model_name="$1"
expected_related_charm="$2"
expected_relation="$3"
expected_interface="$4"

for charm in $(juju status -m "$model_name" --format=json | jq -r '.applications | keys[]'); do
metadata_yaml=$(juju ssh -m "$model_name" ${charm}/0 "cat agents/unit-${charm}-0/charm/metadata.yaml")

# Extract interface information
interface_requires=$(echo "$metadata_yaml" | yq '.requires | .'$expected_relation'.interface')
interface_provides=$(echo "$metadata_yaml" | yq '.provides | .'$expected_relation'.interface')

# Check if interfaces match the expected one
if [[ "$interface_requires" == "$expected_interface" || "$interface_provides" == "$expected_interface" ]]; then
is_charm_related=$(juju status -m "$model_name" --format=json | jq -r '[.applications.'$expected_related_charm'.relations[] | map(select(.["related-application"] == "'$charm'"))] | add | length > 0')
if [[ "$is_charm_related" == "true" ]]; then
echo "INFO: $charm is related to $expected_related_charm via interface: $expected_relation:$expected_interface"
else
echo "ERROR: $charm is NOT related to $expected_related_charm"
fi
else
echo "INFO: $charm does not have the expected interface: $expected_relation:$expected_interface"
fi
done

8 changes: 2 additions & 6 deletions goss/vars.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
enable_machine_tests: false

model_name: cos-model

apps:
Expand All @@ -19,9 +21,3 @@ apps:
prometheus_openstack_exporter:
name: prometheus-openstack-exporter

enable_az_tests: false # Only useful for machine charm deployments
enable_k8s_tests: true
enable_model_tests: true
enable_network_tests: true
enable_pebble_tests: false
enable_post_relation_tests: true

0 comments on commit 060d743

Please sign in to comment.