Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(kps): Bump to 56.13.1, clean up manifests #1492

Merged
merged 11 commits into from
Feb 28, 2024
2 changes: 2 additions & 0 deletions staging/kube-prometheus-stack/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ charts/*
!charts/crds/**
Chart.lock
hack/*.git
hack/tmp/
hack/pyvenv.cfg
6 changes: 3 additions & 3 deletions staging/kube-prometheus-stack/Chart.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ dependencies:
version: 4.30.3
- name: grafana
repository: https://grafana.github.io/helm-charts
version: 7.3.2
version: 7.3.3
- name: prometheus-windows-exporter
repository: https://prometheus-community.github.io/helm-charts
version: 0.3.1
digest: sha256:1fc7c8ee6d89db4aa657018ef32a9799daa73f648265087be9b4398ddb943e88
generated: "2024-02-23T19:09:13.645185-08:00"
digest: sha256:e852aaa5f048db7c2f8ee5c4da63dc7abf0cbd8da11e135e5a5c72f769956252
generated: "2024-02-27T18:42:53.115741-08:00"
2 changes: 1 addition & 1 deletion staging/kube-prometheus-stack/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ name: kube-prometheus-stack
sources:
- https://github.com/prometheus-community/helm-charts
- https://github.com/prometheus-operator/kube-prometheus
version: 56.9.0
version: 56.13.1
appVersion: v0.71.2
kubeVersion: ">=1.19.0-0"
home: https://github.com/prometheus-operator/kube-prometheus
Expand Down
75 changes: 41 additions & 34 deletions staging/kube-prometheus-stack/ci/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,44 @@

set -euo pipefail

SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)

cd "${SCRIPT_DIR}/../"

./hack/update_crds.sh
if ! git diff --exit-code; then
echo "Please run ./hack/update_crds.sh"
exit 1
fi

python3 -m venv venv
# shellcheck disable=SC1091
source venv/bin/activate
pip3 install -r hack/requirements.txt

go install -a github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb@latest
PATH="$(go env GOPATH)/bin:$PATH"
export PATH

./hack/sync_prometheus_rules.py
if ! git diff --exit-code; then
echo "Changes inside rules are not supported!"
echo "Please run ./hack/sync_prometheus_rules.py"
exit 1
fi

./hack/sync_grafana_dashboards.py
if ! git diff --exit-code; then
echo "Changes inside dashboards are not supported!"
echo "Please run ./hack/sync_grafana_dashboards.py"
exit 1
fi

rm -rf ./venv ./*.git
{
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)

cd "${SCRIPT_DIR}/../"

./hack/update_crds.sh
if ! git diff "$GITHUB_SHA" --color=always --exit-code; then
echo "Please run ./hack/update_crds.sh"
exit 1
fi

cd hack

export PIP_DISABLE_PIP_VERSION_CHECK=1

python3 -m venv venv
# shellcheck disable=SC1091
source venv/bin/activate

pip3 install -r requirements.txt

go install -a github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb@latest
PATH="$(go env GOPATH)/bin:$PATH"
export PATH

./sync_prometheus_rules.py
if ! git diff "$GITHUB_SHA" --color=always --exit-code; then
echo "Changes inside rules are not supported!"
echo "Please go into the ./hack/ directory and run ./sync_prometheus_rules.py"
exit 1
fi

./sync_grafana_dashboards.py
if ! git diff "$GITHUB_SHA" --color=always --exit-code; then
echo "Changes inside dashboards are not supported!"
echo "Please go into the ./hack/ directory and run ./sync_grafana_dashboards.py"
exit 1
fi

rm -rf ./venv ./*.git
} 2>&1
26 changes: 19 additions & 7 deletions staging/kube-prometheus-stack/hack/sync_grafana_dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,27 @@ def new_representer(dumper, data):
return new_representer


refs = {
# https://github.com/prometheus-operator/kube-prometheus
'ref.kube-prometheus': 'a8ba97a150c75be42010c75d10b720c55e182f1a',
# https://github.com/kubernetes-monitoring/kubernetes-mixin
'ref.kubernetes-mixin': '883f294bc636e2cd019a64328a1dbfa53edbc985',
# https://github.com/etcd-io/etcd
'ref.etcd': '786da8731e6ebc61d3482048fdfa64e505da1f8f',
}

# Source files list
charts = [
{
'source': 'https://raw.githubusercontent.com/prometheus-operator/kube-prometheus/main/manifests/grafana-dashboardDefinitions.yaml',
'source': 'https://raw.githubusercontent.com/prometheus-operator/kube-prometheus/%s/manifests/grafana-dashboardDefinitions.yaml' % (refs['ref.kube-prometheus'],),
'destination': '../templates/grafana/dashboards-1.14',
'type': 'yaml',
'min_kubernetes': '1.14.0-0',
'multicluster_key': '.Values.grafana.sidecar.dashboards.multicluster.global.enabled',
},
{
'git': 'https://github.com/kubernetes-monitoring/kubernetes-mixin.git',
'branch': 'master',
'branch': refs['ref.kubernetes-mixin'],
'content': "(import 'dashboards/windows.libsonnet') + (import 'config.libsonnet') + { _config+:: { windowsExporterSelector: 'job=\"windows-exporter\"', }}",
'cwd': '.',
'destination': '../templates/grafana/dashboards-1.14',
Expand All @@ -49,7 +58,7 @@ def new_representer(dumper, data):
},
{
'git': 'https://github.com/etcd-io/etcd.git',
'branch': 'main',
'branch': refs['ref.etcd'],
'source': 'mixin.libsonnet',
'cwd': 'contrib/mixin',
'destination': '../templates/grafana/dashboards-1.14',
Expand Down Expand Up @@ -83,13 +92,13 @@ def new_representer(dumper, data):

replacement_map = {
'var-namespace=$__cell_1': {
'replacement': 'var-namespace=${__data.fields.namespace}',
'replacement': 'var-namespace=`}}{{ if .Values.grafana.sidecar.dashboards.enableNewTablePanelSyntax }}${__data.fields.namespace}{{ else }}$__cell_1{{ end }}{{`',
},
'var-type=$__cell_2': {
'replacement': 'var-type=${__data.fields.workload_type}',
'replacement': 'var-type=`}}{{ if .Values.grafana.sidecar.dashboards.enableNewTablePanelSyntax }}${__data.fields.workload_type}{{ else }}$__cell_2{{ end }}{{`',
},
'=$__cell': {
'replacement': '=${__value.text}',
'replacement': '=`}}{{ if .Values.grafana.sidecar.dashboards.enableNewTablePanelSyntax }}${__value.text}{{ else }}$__cell{{ end }}{{`',
},
}

Expand Down Expand Up @@ -247,7 +256,10 @@ def main():
if 'branch' in chart:
branch = chart['branch']

subprocess.run(["git", "clone", chart['git'], "--branch", branch, "--single-branch", "--depth", "1", checkout_dir])
subprocess.run(["git", "init", "--initial-branch", "main", checkout_dir, "--quiet"])
subprocess.run(["git", "-C", checkout_dir, "remote", "add", "origin", chart['git']])
subprocess.run(["git", "-C", checkout_dir, "fetch", "--depth", "1", "origin", branch, "--quiet"])
subprocess.run(["git", "-c", "advice.detachedHead=false", "-C", checkout_dir, "checkout", "FETCH_HEAD", "--quiet"])
print("Generating rules from %s" % chart['source'])

mixin_file = chart['source']
Expand Down
31 changes: 22 additions & 9 deletions staging/kube-prometheus-stack/hack/sync_prometheus_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,46 +27,55 @@ def new_representer(dumper, data):
return new_representer


refs = {
# https://github.com/prometheus-operator/kube-prometheus
'ref.kube-prometheus': 'a8ba97a150c75be42010c75d10b720c55e182f1a',
# https://github.com/kubernetes-monitoring/kubernetes-mixin
'ref.kubernetes-mixin': '883f294bc636e2cd019a64328a1dbfa53edbc985',
# https://github.com/etcd-io/etcd
'ref.etcd': '786da8731e6ebc61d3482048fdfa64e505da1f8f',
}

# Source files list
charts = [
{
'source': 'https://raw.githubusercontent.com/prometheus-operator/kube-prometheus/main/manifests/alertmanager-prometheusRule.yaml',
'source': 'https://raw.githubusercontent.com/prometheus-operator/kube-prometheus/%s/manifests/alertmanager-prometheusRule.yaml' % (refs['ref.kube-prometheus'],),
'destination': '../templates/prometheus/rules-1.14',
'min_kubernetes': '1.14.0-0'
},
{
'source': 'https://raw.githubusercontent.com/prometheus-operator/kube-prometheus/main/manifests/kubePrometheus-prometheusRule.yaml',
'source': 'https://raw.githubusercontent.com/prometheus-operator/kube-prometheus/%s/manifests/kubePrometheus-prometheusRule.yaml'% (refs['ref.kube-prometheus'],),
'destination': '../templates/prometheus/rules-1.14',
'min_kubernetes': '1.14.0-0'
},
{
'source': 'https://raw.githubusercontent.com/prometheus-operator/kube-prometheus/main/manifests/kubernetesControlPlane-prometheusRule.yaml',
'source': 'https://raw.githubusercontent.com/prometheus-operator/kube-prometheus/%s/manifests/kubernetesControlPlane-prometheusRule.yaml'% (refs['ref.kube-prometheus'],),
'destination': '../templates/prometheus/rules-1.14',
'min_kubernetes': '1.14.0-0'
},
{
'source': 'https://raw.githubusercontent.com/prometheus-operator/kube-prometheus/main/manifests/kubeStateMetrics-prometheusRule.yaml',
'source': 'https://raw.githubusercontent.com/prometheus-operator/kube-prometheus/%s/manifests/kubeStateMetrics-prometheusRule.yaml'% (refs['ref.kube-prometheus'],),
'destination': '../templates/prometheus/rules-1.14',
'min_kubernetes': '1.14.0-0'
},
{
'source': 'https://raw.githubusercontent.com/prometheus-operator/kube-prometheus/main/manifests/nodeExporter-prometheusRule.yaml',
'source': 'https://raw.githubusercontent.com/prometheus-operator/kube-prometheus/%s/manifests/nodeExporter-prometheusRule.yaml'% (refs['ref.kube-prometheus'],),
'destination': '../templates/prometheus/rules-1.14',
'min_kubernetes': '1.14.0-0'
},
{
'source': 'https://raw.githubusercontent.com/prometheus-operator/kube-prometheus/main/manifests/prometheus-prometheusRule.yaml',
'source': 'https://raw.githubusercontent.com/prometheus-operator/kube-prometheus/%s/manifests/prometheus-prometheusRule.yaml'% (refs['ref.kube-prometheus'],),
'destination': '../templates/prometheus/rules-1.14',
'min_kubernetes': '1.14.0-0'
},
{
'source': 'https://raw.githubusercontent.com/prometheus-operator/kube-prometheus/main/manifests/prometheusOperator-prometheusRule.yaml',
'source': 'https://raw.githubusercontent.com/prometheus-operator/kube-prometheus/%s/manifests/prometheusOperator-prometheusRule.yaml'% (refs['ref.kube-prometheus'],),
'destination': '../templates/prometheus/rules-1.14',
'min_kubernetes': '1.14.0-0'
},
{
'git': 'https://github.com/kubernetes-monitoring/kubernetes-mixin.git',
'branch': 'master',
'branch': refs['ref.kubernetes-mixin'],
'source': 'windows.libsonnet',
'cwd': 'rules',
'destination': '../templates/prometheus/rules-1.14',
Expand All @@ -80,6 +89,7 @@ def new_representer(dumper, data):
},
{
'git': 'https://github.com/etcd-io/etcd.git',
'branch': refs['ref.etcd'],
'source': 'mixin.libsonnet',
'cwd': 'contrib/mixin',
'destination': '../templates/prometheus/rules-1.14',
Expand Down Expand Up @@ -546,7 +556,10 @@ def main():
if 'branch' in chart:
branch = chart['branch']

subprocess.run(["git", "clone", chart['git'], "--branch", branch, "--single-branch", "--depth", "1", checkout_dir])
subprocess.run(["git", "init", "--initial-branch", "main", checkout_dir, "--quiet"])
subprocess.run(["git", "-C", checkout_dir, "remote", "add", "origin", chart['git']])
subprocess.run(["git", "-C", checkout_dir, "fetch", "--depth", "1", "origin", branch, "--quiet"])
subprocess.run(["git", "-c", "advice.detachedHead=false", "-C", checkout_dir, "checkout", "FETCH_HEAD", "--quiet"])

if chart.get('is_mixin'):
cwd = os.getcwd()
Expand Down
33 changes: 33 additions & 0 deletions staging/kube-prometheus-stack/hack/update_mixins.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash

set -euo pipefail

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

trap 'rm -rf "${SCRIPT_DIR}/tmp"' EXIT

rm -rf "${SCRIPT_DIR}/tmp"
mkdir "${SCRIPT_DIR}/tmp"

git clone --depth 1 --quiet https://github.com/prometheus-operator/kube-prometheus.git "${SCRIPT_DIR}/tmp/kube-prometheus"
git clone --depth 1 --quiet https://github.com/kubernetes-monitoring/kubernetes-mixin.git "${SCRIPT_DIR}/tmp/kubernetes-mixin"
git clone --depth 1 --quiet https://github.com/etcd-io/etcd.git "${SCRIPT_DIR}/tmp/etcd"

for REPO_PATH in "${SCRIPT_DIR}/tmp/"*; do
SHA=$(git -C "$REPO_PATH" log -1 --pretty=format:"%H")
REPO_NAME=$(basename "$REPO_PATH")
echo "Updating $REPO_NAME to $SHA"
sed -i '' -e "s/'ref.$REPO_NAME'.*:.*'.*'/'ref.$REPO_NAME': '$SHA'/" "${SCRIPT_DIR}/sync_grafana_dashboards.py"
sed -i '' -e "s/'ref.$REPO_NAME'.*:.*'.*'/'ref.$REPO_NAME': '$SHA'/" "${SCRIPT_DIR}/sync_prometheus_rules.py"
done

export PIP_DISABLE_PIP_VERSION_CHECK=1

python3 -m venv "${SCRIPT_DIR}/tmp/venv"
# shellcheck disable=SC1091
source "${SCRIPT_DIR}/tmp/venv/bin/activate"

pip3 install -r "${SCRIPT_DIR}/requirements.txt"

"${SCRIPT_DIR}/sync_grafana_dashboards.py"
"${SCRIPT_DIR}/sync_prometheus_rules.py"

This file was deleted.

Loading
Loading