Skip to content

Commit

Permalink
All is working except the random numbers in the tests
Browse files Browse the repository at this point in the history
Signed-off-by: Pete Wall <[email protected]>
  • Loading branch information
petewall committed Dec 4, 2024
1 parent d4b2c2d commit a54ddf7
Show file tree
Hide file tree
Showing 14 changed files with 70 additions and 67 deletions.
13 changes: 7 additions & 6 deletions charts/k8s-monitoring/tests/platform/gke-autopilot/.envrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
export GCP_SERVICE_ACCOUNT=$(op --account grafana.1password.com read "op://Kubernetes Monitoring/GCP k8s-monitoring-helm-cluster-creator/username")
op --account grafana.1password.com read "op://Kubernetes Monitoring/GCP k8s-monitoring-helm-cluster-creator/credential" > sak.json
export GCP_SERVICE_ACCOUNT=$(op --account grafana.1password.com read "op://Kubernetes Monitoring/GCP k8s-monitoring-helm-cluster-creator/username")
op --account grafana.1password.com read --out-file sak.json "op://Kubernetes Monitoring/GCP k8s-monitoring-helm-cluster-creator/credential"
gcloud auth activate-service-account "${GCP_SERVICE_ACCOUNT}" --key-file=sak.json
rm sak.json

export GRAFANA_CLOUD_METRICS_USERNAME=$(op --account grafana.1password.com read "op://Kubernetes Monitoring/helmchart Prometheus/username")
export GRAFANA_CLOUD_LOGS_USERNAME=$(op --account grafana.1password.com read "op://Kubernetes Monitoring/helmchart Loki/username")
export GRAFANA_CLOUD_TRACES_USERNAME=$(op --account grafana.1password.com read "op://Kubernetes Monitoring/helmchart Tempo/username")
export GRAFANA_CLOUD_RW_POLICY_TOKEN=$(op --account grafana.1password.com read "op://Kubernetes Monitoring/helmchart Prometheus/password")
export GRAFANA_CLOUD_METRICS_QUERY_URL=https://prometheus-prod-13-prod-us-east-0.grafana.net/api/prom/push
export GRAFANA_CLOUD_METRICS_USERNAME=$(op --account grafana.1password.com read "op://Kubernetes Monitoring/helmchart Prometheus/username")
export GRAFANA_CLOUD_LOGS_QUERY_URL=https://logs-prod-006.grafana.net/loki/api/v1/query
export GRAFANA_CLOUD_LOGS_USERNAME=$(op --account grafana.1password.com read "op://Kubernetes Monitoring/helmchart Loki/username")
export GRAFANA_CLOUD_RW_POLICY_TOKEN=$(op --account grafana.1password.com read "op://Kubernetes Monitoring/helmchart Prometheus/password")
export RANDOM_NUMBER=$(shuf -i 100000-999999 -n 1)
2 changes: 2 additions & 0 deletions charts/k8s-monitoring/tests/platform/gke-autopilot/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
deployments/grafana-cloud-credentials.yaml
deployments/test-variables.yaml
19 changes: 19 additions & 0 deletions charts/k8s-monitoring/tests/platform/gke-autopilot/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
all: deployments/test-variables.yaml deployments/grafana-cloud-credentials.yaml
clean:
rm -f deployments/test-variables.yaml deployments/grafana-cloud-credentials.yaml

deployments/test-variables.yaml:
kubectl create configmap test-variables \
--from-literal=CLUSTER="$(shell yq eval '.cluster.name' values.yaml)-$$RANDOM_NUMBER" \
--from-literal=RANDOM_NUMBER="$$RANDOM_NUMBER" \
-o yaml --dry-run=client > $@

deployments/grafana-cloud-credentials.yaml:
kubectl create secret generic grafana-cloud-credentials \
--from-literal=PROMETHEUS_URL="$$GRAFANA_CLOUD_METRICS_QUERY_URL" \
--from-literal=PROMETHEUS_USER="$$GRAFANA_CLOUD_METRICS_USERNAME" \
--from-literal=PROMETHEUS_PASS="$$GRAFANA_CLOUD_RW_POLICY_TOKEN" \
--from-literal=LOKI_URL="$$GRAFANA_CLOUD_LOGS_QUERY_URL" \
--from-literal=LOKI_USER="$$GRAFANA_CLOUD_LOGS_USERNAME" \
--from-literal=LOKI_PASS="$$GRAFANA_CLOUD_RW_POLICY_TOKEN" \
-o yaml --dry-run=client > $@

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ spec:
interval: 1m
values:
tests:
- env:
PROMETHEUS_URL: https://prometheus-prod-13-prod-us-east-0.grafana.net/api/prom/api/v1/query
LOKI_URL: https://logs-prod-006.grafana.net/loki/api/v1/query
envFrom:
- envFrom:
- secretRef: {name: grafana-cloud-credentials}

Check failure on line 31 in charts/k8s-monitoring/tests/platform/gke-autopilot/deployments/query-test.yaml

View workflow job for this annotation

GitHub Actions / runner / yamllint

[yamllint] reported by reviewdog 🐶 [error] too many spaces after colon (colons) Raw Output: ./charts/k8s-monitoring/tests/platform/gke-autopilot/deployments/query-test.yaml:31:26: [error] too many spaces after colon (colons)
- configMapRef: {name: test-variables}
queries:
Expand Down

This file was deleted.

4 changes: 2 additions & 2 deletions charts/k8s-monitoring/tests/platform/remote-config/.envrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export GRAFANA_CLOUD_FLEET_MGMT_USER=$(op --account grafana.1password.com read "op://Kubernetes Monitoring/helmchart Fleet Management/username")
export GRAFANA_CLOUD_FLEET_MGMT_TOKEN=$(op --account grafana.1password.com read "op://Kubernetes Monitoring/helmchart Fleet Management/password")
export GRAFANA_CLOUD_METRICS_QUERY_URL=https://prometheus-prod-13-prod-us-east-0.grafana.net/api/prom/push
export GRAFANA_CLOUD_METRICS_USERNAME=$(op --account grafana.1password.com read "op://Kubernetes Monitoring/helmchart Prometheus/username")
export GRAFANA_CLOUD_LOGS_USERNAME=$(op --account grafana.1password.com read "op://Kubernetes Monitoring/helmchart Loki/username")
export GRAFANA_CLOUD_RW_POLICY_TOKEN=$(op --account grafana.1password.com read "op://Kubernetes Monitoring/helmchart Loki/password")
export GRAFANA_CLOUD_RW_POLICY_TOKEN=$(op --account grafana.1password.com read "op://Kubernetes Monitoring/helmchart Prometheus/password")
export RANDOM_NUMBER=$(shuf -i 100000-999999 -n 1)
2 changes: 2 additions & 0 deletions charts/k8s-monitoring/tests/platform/remote-config/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
deployments/grafana-cloud-credentials.yaml
deployments/test-variables.yaml
18 changes: 18 additions & 0 deletions charts/k8s-monitoring/tests/platform/remote-config/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
all: deployments/test-variables.yaml deployments/grafana-cloud-credentials.yaml
clean:
rm -f deployments/test-variables.yaml deployments/grafana-cloud-credentials.yaml

deployments/test-variables.yaml:
kubectl create configmap test-variables \
--from-literal=CLUSTER="$(shell yq eval '.cluster.name' values.yaml)-$$RANDOM_NUMBER" \
--from-literal=RANDOM_NUMBER="$$RANDOM_NUMBER" \
-o yaml --dry-run=client > $@

deployments/grafana-cloud-credentials.yaml:
kubectl create secret generic grafana-cloud-credentials \
--from-literal=GRAFANA_CLOUD_FLEET_MGMT_USER="$$GRAFANA_CLOUD_FLEET_MGMT_USER" \
--from-literal=GRAFANA_CLOUD_FLEET_MGMT_TOKEN="$$GRAFANA_CLOUD_FLEET_MGMT_TOKEN" \
--from-literal=PROMETHEUS_URL="$$GRAFANA_CLOUD_METRICS_QUERY_URL" \
--from-literal=PROMETHEUS_USER="$$GRAFANA_CLOUD_METRICS_USERNAME" \
--from-literal=PROMETHEUS_PASS="$$GRAFANA_CLOUD_RW_POLICY_TOKEN" \
-o yaml --dry-run=client > $@

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ apiVersion: source.toolkit.fluxcd.io/v1
kind: GitRepository
metadata:
name: k8s-monitoring-test
namespace: flux-system
spec:
interval: 1m
url: https://github.com/grafana/k8s-monitoring-helm
Expand All @@ -29,10 +28,8 @@ spec:
values:
tests:
- envFrom:
- secretRef:
name: grafana-cloud-credentials
- configMapRef:
name: test-variables
- secretRef: {name: grafana-cloud-credentials}

Check failure on line 31 in charts/k8s-monitoring/tests/platform/remote-config/deployments/query-test.yaml

View workflow job for this annotation

GitHub Actions / runner / yamllint

[yamllint] reported by reviewdog 🐶 [error] too many spaces after colon (colons) Raw Output: ./charts/k8s-monitoring/tests/platform/remote-config/deployments/query-test.yaml:31:26: [error] too many spaces after colon (colons)
- configMapRef: {name: test-variables}
queries:
- query: alloy_build_info{cluster="remote-config-platform-test", random="$RANDOM_NUMBER"}
- query: alloy_build_info{cluster="$CLUSTER"}
type: promql

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
cluster:
name: remote-config-platform-test
name: remote-config-test

alloy-metrics:
enabled: true
Expand Down
23 changes: 15 additions & 8 deletions scripts/run-cluster-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,21 @@ if [ -z "${TEST_DIRECTORY}" ]; then
usage
exit 1
fi
if [ ! -f "${TEST_DIRECTORY}/values.yaml" ]; then
echo "Values file (${TEST_DIRECTORY}/values.yaml) not found! This is a required file."
usage
exit 1
fi

set -eo pipefail # Exit immediately if a command fails.

clusterName=$(yq eval '.cluster.name' "${TEST_DIRECTORY}/values.yaml")
if [ -n "${RANDOM_NUMBER}" ]; then clusterName="${clusterName}-${RANDOM_NUMBER}"; fi

#
# Cluster creation
#
if [ "${CREATE_CLUSTER}" == "true" ]; then
clusterName=$(yq eval '.cluster.name' "${TEST_DIRECTORY}/values.yaml")
if [ -n "${RANDOM_NUMBER}" ]; then clusterName="${clusterName}-${RANDOM_NUMBER}"; fi
if [ -f "${TEST_DIRECTORY}/kind-cluster-config.yaml" ]; then
createKindCluster "${clusterName}" "${TEST_DIRECTORY}/kind-cluster-config.yaml"
elif [ -f "${TEST_DIRECTORY}/gke-cluster-config.yaml" ]; then
Expand All @@ -51,8 +57,6 @@ if [ "${CREATE_CLUSTER}" == "true" ]; then
fi

deleteCluster() {
clusterName=$(yq eval '.cluster.name' "${TEST_DIRECTORY}/values.yaml")
if [ -n "${RANDOM_NUMBER}" ]; then clusterName="${clusterName}-${RANDOM_NUMBER}"; fi
if [ -f "${TEST_DIRECTORY}/kind-cluster-config.yaml" ]; then
deleteKindCluster "${clusterName}" "${TEST_DIRECTORY}/kind-cluster-config.yaml"
elif [ -f "${TEST_DIRECTORY}/gke-cluster-config.yaml" ]; then
Expand All @@ -74,12 +78,15 @@ else
helm upgrade --install --namespace flux-system --create-namespace flux oci://ghcr.io/fluxcd-community/charts/flux2 --wait
fi

# Deploy prerequisites
kubectl apply -f ${TEST_DIRECTORY}/deployments
# Apply the deployments directory
if [ -f "${TEST_DIRECTORY}/Makefile" ]; then
make -C "${TEST_DIRECTORY}" clean all
fi
if [ -d "${TEST_DIRECTORY}/deployments" ]; then
kubectl apply -f ${TEST_DIRECTORY}/deployments
fi

# Deploy k8s-monitoring
clusterName=$(yq eval '.cluster.name' "${TEST_DIRECTORY}/values.yaml")
if [ -n "${RANDOM_NUMBER}" ]; then clusterName="${clusterName}-${RANDOM_NUMBER}"; fi
echo helm upgrade --install k8smon ${PARENT_DIR}/charts/k8s-monitoring -f ${TEST_DIRECTORY}/values.yaml --set "cluster.name=${clusterName}" --wait
helm upgrade --install k8smon ${PARENT_DIR}/charts/k8s-monitoring -f ${TEST_DIRECTORY}/values.yaml --set "cluster.name=${clusterName}" --wait

Expand Down

0 comments on commit a54ddf7

Please sign in to comment.