From 72e719b5d57541602e098b416672e35960d93f6c Mon Sep 17 00:00:00 2001 From: Leonard Du Date: Fri, 26 Jun 2026 09:03:40 +1000 Subject: [PATCH 1/2] Add InstallKubePrometheusStack lib step --- kcl/lib/steps/k8s/install_prometheus.k | 36 ++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 kcl/lib/steps/k8s/install_prometheus.k diff --git a/kcl/lib/steps/k8s/install_prometheus.k b/kcl/lib/steps/k8s/install_prometheus.k new file mode 100644 index 0000000000..e4fe883f1b --- /dev/null +++ b/kcl/lib/steps/k8s/install_prometheus.k @@ -0,0 +1,36 @@ +import azure_pipelines.ap.steps +import lib.steps.azure + +# Install kube-prometheus-stack via Helm. Caller must run azure.GetCredentials first and check in a values.yaml. +InstallKubePrometheusStack = lambda serviceConnection: str, valuesFile: str, namespace: str = "monitoring", releaseName: str = "prometheus", chartVersion: str = "", waitTimeout: str = "10m" -> steps.Step { + script = """ +set -euo pipefail + +# Install Helm v3 if missing +if ! command -v helm >/dev/null 2>&1; then + echo "==> helm not found; installing" + curl -fsSL https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash +fi +helm version --short + +# Add / refresh prometheus-community repo (idempotent) +helm repo add prometheus-community https://prometheus-community.github.io/helm-charts >/dev/null 2>&1 || true +helm repo update prometheus-community + +VERSION_FLAG="" +if [ -n "${chartVersion}" ]; then + VERSION_FLAG="--version ${chartVersion}" +fi + +helm upgrade --install "${releaseName}" prometheus-community/kube-prometheus-stack \\ + --namespace "${namespace}" --create-namespace \\ + --values "$(Pipeline.Workspace)/s/${valuesFile}" \\ + --wait --atomic --timeout "${waitTimeout}" \\ + \${VERSION_FLAG} + +echo "==> kube-prometheus-stack release '${releaseName}' is ready in namespace '${namespace}'" +# Prometheus web service is svc/-kube-prometheus-prometheus on port 9090. +echo "==> Prometheus web service: svc/${releaseName}-kube-prometheus-prometheus in ${namespace} (port 9090)" +""" + azure.AzCli(serviceConnection, "Install kube-prometheus-stack", script) +} From a42fb6ee23c042c4fa8aaa86a7961ea73875c1a8 Mon Sep 17 00:00:00 2001 From: Leonard Du Date: Tue, 30 Jun 2026 11:57:55 +1000 Subject: [PATCH 2/2] Add InstallHelm and rename to InstallPrometheus --- kcl/lib/steps/k8s/install_helm.k | 14 ++++++++++++++ kcl/lib/steps/k8s/install_prometheus.k | 18 ++++-------------- 2 files changed, 18 insertions(+), 14 deletions(-) create mode 100644 kcl/lib/steps/k8s/install_helm.k diff --git a/kcl/lib/steps/k8s/install_helm.k b/kcl/lib/steps/k8s/install_helm.k new file mode 100644 index 0000000000..10e7b009fa --- /dev/null +++ b/kcl/lib/steps/k8s/install_helm.k @@ -0,0 +1,14 @@ +import azure_pipelines.ap.steps + +# Install Helm v3 on the pipeline agent. +InstallHelm = lambda -> steps.Step { + steps.Bash { + bash = """\ +set -euo pipefail +if ! command -v helm >/dev/null 2>&1; then + curl -fsSL https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash +fi +helm version --short""" + displayName = "Install Helm" + } +} diff --git a/kcl/lib/steps/k8s/install_prometheus.k b/kcl/lib/steps/k8s/install_prometheus.k index e4fe883f1b..4fddcf70d5 100644 --- a/kcl/lib/steps/k8s/install_prometheus.k +++ b/kcl/lib/steps/k8s/install_prometheus.k @@ -1,19 +1,11 @@ import azure_pipelines.ap.steps import lib.steps.azure -# Install kube-prometheus-stack via Helm. Caller must run azure.GetCredentials first and check in a values.yaml. -InstallKubePrometheusStack = lambda serviceConnection: str, valuesFile: str, namespace: str = "monitoring", releaseName: str = "prometheus", chartVersion: str = "", waitTimeout: str = "10m" -> steps.Step { +# Install kube-prometheus-stack via Helm. Caller must run InstallHelm and azure.GetCredentials first, and check in a values.yaml. +InstallPrometheus = lambda serviceConnection: str, valuesFile: str, namespace: str = "monitoring", releaseName: str = "prometheus", chartVersion: str = "", waitTimeout: str = "10m" -> steps.Step { script = """ set -euo pipefail -# Install Helm v3 if missing -if ! command -v helm >/dev/null 2>&1; then - echo "==> helm not found; installing" - curl -fsSL https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash -fi -helm version --short - -# Add / refresh prometheus-community repo (idempotent) helm repo add prometheus-community https://prometheus-community.github.io/helm-charts >/dev/null 2>&1 || true helm repo update prometheus-community @@ -28,9 +20,7 @@ helm upgrade --install "${releaseName}" prometheus-community/kube-prometheus-sta --wait --atomic --timeout "${waitTimeout}" \\ \${VERSION_FLAG} -echo "==> kube-prometheus-stack release '${releaseName}' is ready in namespace '${namespace}'" -# Prometheus web service is svc/-kube-prometheus-prometheus on port 9090. -echo "==> Prometheus web service: svc/${releaseName}-kube-prometheus-prometheus in ${namespace} (port 9090)" +echo "==> Prometheus release '${releaseName}' is ready in namespace '${namespace}'" """ - azure.AzCli(serviceConnection, "Install kube-prometheus-stack", script) + azure.AzCli(serviceConnection, "Install Prometheus", script) }