From fb405a5843c4d1c2e1a87caa010340f25580b14e Mon Sep 17 00:00:00 2001 From: Pete Wall Date: Thu, 9 Jan 2025 14:31:48 -0600 Subject: [PATCH] WIP: Working example, just need to get the credentials figured out Signed-off-by: Pete Wall --- .../k8s-monitoring/tests/platform/aks/.envrc | 2 ++ .../tests/platform/aks/Makefile | 3 +++ .../platform/aks/aks-cluster-config.yaml | 6 ++++++ .../platform/aks/deployments/query-test.yaml | 6 +++--- .../tests/platform/aks/values.yaml | 19 ------------------ scripts/includes/cluster/aks.sh | 20 ++++++++++++------- scripts/run-cluster-test.sh | 6 +++--- 7 files changed, 30 insertions(+), 32 deletions(-) diff --git a/charts/k8s-monitoring/tests/platform/aks/.envrc b/charts/k8s-monitoring/tests/platform/aks/.envrc index ffc079f0c..9385a70a3 100644 --- a/charts/k8s-monitoring/tests/platform/aks/.envrc +++ b/charts/k8s-monitoring/tests/platform/aks/.envrc @@ -1,6 +1,8 @@ export AZURE_SUBSCRIPTION_ID=$(op --account grafana.1password.com read "op://Kubernetes Monitoring/Azure/subscription id") export AZURE_TENANT_ID=$(op --account grafana.1password.com read "op://Kubernetes Monitoring/Azure/tenant id") export AZURE_CLIENT_ID=$(op --account grafana.1password.com read "op://Kubernetes Monitoring/Azure/client id") +export AZURE_DEFAULT_GROUP=$(op --account grafana.1password.com read "op://Kubernetes Monitoring/Azure/resource group") +az config set defaults.group="$AZURE_DEFAULT_GROUP" 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") diff --git a/charts/k8s-monitoring/tests/platform/aks/Makefile b/charts/k8s-monitoring/tests/platform/aks/Makefile index 20ca9c2ea..d49a35f6e 100644 --- a/charts/k8s-monitoring/tests/platform/aks/Makefile +++ b/charts/k8s-monitoring/tests/platform/aks/Makefile @@ -17,3 +17,6 @@ deployments/grafana-cloud-credentials.yaml: --from-literal=LOKI_USER="$$GRAFANA_CLOUD_LOGS_USERNAME" \ --from-literal=LOKI_PASS="$$GRAFANA_CLOUD_RW_POLICY_TOKEN" \ -o yaml --dry-run=client >> $@ + +run-test: + ../../../../../scripts/run-cluster-test.sh . diff --git a/charts/k8s-monitoring/tests/platform/aks/aks-cluster-config.yaml b/charts/k8s-monitoring/tests/platform/aks/aks-cluster-config.yaml index e69de29bb..f66b87b99 100644 --- a/charts/k8s-monitoring/tests/platform/aks/aks-cluster-config.yaml +++ b/charts/k8s-monitoring/tests/platform/aks/aks-cluster-config.yaml @@ -0,0 +1,6 @@ +--- +args: + node-count: 1 + tier: free + enable-managed-identity: + generate-ssh-keys: diff --git a/charts/k8s-monitoring/tests/platform/aks/deployments/query-test.yaml b/charts/k8s-monitoring/tests/platform/aks/deployments/query-test.yaml index cb0f77c71..5614c6980 100644 --- a/charts/k8s-monitoring/tests/platform/aks/deployments/query-test.yaml +++ b/charts/k8s-monitoring/tests/platform/aks/deployments/query-test.yaml @@ -34,6 +34,6 @@ spec: - secretRef: {name: grafana-cloud-credentials} - configMapRef: {name: test-variables} queries: - # Metrics are being delivered - - query: alloy_build_info{cluster="$CLUSTER"} - type: promql + # Cluster events + - query: count_over_time({cluster="$CLUSTER", job="integrations/kubernetes/eventhandler"}[1h]) + type: logql diff --git a/charts/k8s-monitoring/tests/platform/aks/values.yaml b/charts/k8s-monitoring/tests/platform/aks/values.yaml index 6a7a538af..4e7518114 100644 --- a/charts/k8s-monitoring/tests/platform/aks/values.yaml +++ b/charts/k8s-monitoring/tests/platform/aks/values.yaml @@ -26,27 +26,8 @@ destinations: name: grafana-cloud-credentials namespace: default -clusterMetrics: - enabled: true - clusterEvents: enabled: true -podLogs: - enabled: true - -integrations: - alloy: - instances: - - name: alloy-metrics - - name: alloy-singleton - - name: alloy-logs - -selfReporting: {scrapeInterval: 1m} # Force self-report to be generated within test time - -alloy-metrics: - enabled: true alloy-singleton: enabled: true -alloy-logs: - enabled: true diff --git a/scripts/includes/cluster/aks.sh b/scripts/includes/cluster/aks.sh index cf825474c..56f23aae7 100644 --- a/scripts/includes/cluster/aks.sh +++ b/scripts/includes/cluster/aks.sh @@ -4,16 +4,22 @@ createAKSCluster() { local clusterName=$1 local clusterConfig=$2 - if ! az does cluster exist; then - echo az create cluster "${clusterName}" --config "${clusterConfig}"... - az create cluster "${clusterName}" --config "${clusterConfig}"... + if ! az aks list --query '[].name' | grep -q "${clusterName}"; then + args=$(yq eval -r -o=json '[.args | to_entries | .[] | select(.value != null)] | map("--" + .key + "=" + (.value | tostring)) | join(" ")' "${clusterConfig}") + args=$(yq eval -r -o=json '[.args | to_entries | .[] | select(.value == null)] | map("--" + .key) | join(" ")' "${clusterConfig}") + bashCommand="az aks create --yes --name \"${clusterName}\" ${args}" + echo "${bashCommand}" + eval "${bashCommand}" fi } deleteAKSCluster() { local clusterName=$1 - if az does cluster exist; then - echo az delete cluster "${clusterName}" ... - az delete cluster "${clusterName}" ... + local clusterConfig=$2 + + if az aks list --query '[].name' | grep -q "${clusterName}"; then + bashCommand="az aks delete --yes --name \"${clusterName}\"" + echo "${bashCommand}" + eval "${bashCommand}" fi -} +} \ No newline at end of file diff --git a/scripts/run-cluster-test.sh b/scripts/run-cluster-test.sh index 08e0e4e84..55ad74c35 100755 --- a/scripts/run-cluster-test.sh +++ b/scripts/run-cluster-test.sh @@ -3,7 +3,7 @@ PARENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" source "${PARENT_DIR}/scripts/includes/utils.sh" source "${PARENT_DIR}/scripts/includes/logging.sh" -#source "${PARENT_DIR}/scripts/includes/cluster/aks.sh" +source "${PARENT_DIR}/scripts/includes/cluster/aks.sh" source "${PARENT_DIR}/scripts/includes/cluster/eks.sh" source "${PARENT_DIR}/scripts/includes/cluster/gke.sh" source "${PARENT_DIR}/scripts/includes/cluster/kind.sh" @@ -51,7 +51,7 @@ if [ "${CREATE_CLUSTER}" == "true" ]; then if [ -f "${TEST_DIRECTORY}/kind-cluster-config.yaml" ]; then createKindCluster "${clusterName}" "${TEST_DIRECTORY}/kind-cluster-config.yaml" elif [ -f "${TEST_DIRECTORY}/aks-cluster-config.yaml" ]; then - createAKSCluster "${clusterName}" "${TEST_DIRECTORY}/eks-cluster-config.yaml" + createAKSCluster "${clusterName}" "${TEST_DIRECTORY}/aks-cluster-config.yaml" elif [ -f "${TEST_DIRECTORY}/eks-cluster-config.yaml" ]; then createEKSCluster "${clusterName}" "${TEST_DIRECTORY}/eks-cluster-config.yaml" elif [ -f "${TEST_DIRECTORY}/gke-cluster-config.yaml" ]; then @@ -67,7 +67,7 @@ deleteCluster() { if [ -f "${TEST_DIRECTORY}/kind-cluster-config.yaml" ]; then deleteKindCluster "${clusterName}" "${TEST_DIRECTORY}/kind-cluster-config.yaml" elif [ -f "${TEST_DIRECTORY}/aks-cluster-config.yaml" ]; then - deleteAKSCluster "${clusterName}" "${TEST_DIRECTORY}/eks-cluster-config.yaml" + deleteAKSCluster "${clusterName}" "${TEST_DIRECTORY}/aks-cluster-config.yaml" elif [ -f "${TEST_DIRECTORY}/eks-cluster-config.yaml" ]; then deleteEKSCluster "${clusterName}" "${TEST_DIRECTORY}/eks-cluster-config.yaml" elif [ -f "${TEST_DIRECTORY}/gke-cluster-config.yaml" ]; then