|
1 | 1 | #!/bin/bash
|
| 2 | +set -euo pipefail |
2 | 3 |
|
3 |
| -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) |
| 4 | +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) |
4 | 5 |
|
5 | 6 | if [[ $(uname -s) = "Darwin" ]]; then
|
6 |
| - VERSION="$(grep ^appVersion "${SCRIPT_DIR}/../Chart.yaml" | sed 's/appVersion: //g')" |
| 7 | + VERSION="$(grep ^appVersion "${SCRIPT_DIR}/../Chart.yaml" | sed 's/appVersion: //g')" |
7 | 8 | else
|
8 |
| - VERSION="$(grep ^appVersion "${SCRIPT_DIR}/../Chart.yaml" | sed 's/appVersion:\s//g')" |
| 9 | + VERSION="$(grep ^appVersion "${SCRIPT_DIR}/../Chart.yaml" | sed 's/appVersion:\s//g')" |
9 | 10 | fi
|
10 | 11 |
|
11 |
| -FILES=( |
12 |
| - "crd-alertmanagerconfigs.yaml : monitoring.coreos.com_alertmanagerconfigs.yaml" |
13 |
| - "crd-alertmanagers.yaml : monitoring.coreos.com_alertmanagers.yaml" |
14 |
| - "crd-podmonitors.yaml : monitoring.coreos.com_podmonitors.yaml" |
15 |
| - "crd-probes.yaml : monitoring.coreos.com_probes.yaml" |
16 |
| - "crd-prometheusagents.yaml : monitoring.coreos.com_prometheusagents.yaml" |
17 |
| - "crd-prometheuses.yaml : monitoring.coreos.com_prometheuses.yaml" |
18 |
| - "crd-prometheusrules.yaml : monitoring.coreos.com_prometheusrules.yaml" |
19 |
| - "crd-scrapeconfigs.yaml : monitoring.coreos.com_scrapeconfigs.yaml" |
20 |
| - "crd-servicemonitors.yaml : monitoring.coreos.com_servicemonitors.yaml" |
21 |
| - "crd-thanosrulers.yaml : monitoring.coreos.com_thanosrulers.yaml" |
| 12 | +CRDS=( |
| 13 | + "alertmanagerconfigs : monitoring.coreos.com_alertmanagerconfigs.yaml" |
| 14 | + "alertmanagers : monitoring.coreos.com_alertmanagers.yaml" |
| 15 | + "podmonitors : monitoring.coreos.com_podmonitors.yaml" |
| 16 | + "probes : monitoring.coreos.com_probes.yaml" |
| 17 | + "prometheusagents : monitoring.coreos.com_prometheusagents.yaml" |
| 18 | + "prometheuses : monitoring.coreos.com_prometheuses.yaml" |
| 19 | + "prometheusrules : monitoring.coreos.com_prometheusrules.yaml" |
| 20 | + "scrapeconfigs : monitoring.coreos.com_scrapeconfigs.yaml" |
| 21 | + "servicemonitors : monitoring.coreos.com_servicemonitors.yaml" |
| 22 | + "thanosrulers : monitoring.coreos.com_thanosrulers.yaml" |
22 | 23 | )
|
23 | 24 |
|
24 |
| -for line in "${FILES[@]}"; do |
25 |
| - DESTINATION=$(echo "${line%%:*}" | xargs) |
26 |
| - SOURCE=$(echo "${line##*:}" | xargs) |
| 25 | +for line in "${CRDS[@]}"; do |
| 26 | + CRD=$(echo "${line%%:*}" | xargs) |
| 27 | + SOURCE=$(echo "${line##*:}" | xargs) |
| 28 | + DESTINATION="crd-${CRD}".yaml |
27 | 29 |
|
28 |
| - URL="https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/$VERSION/example/prometheus-operator-crd/$SOURCE" |
| 30 | + URL="https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/$VERSION/example/prometheus-operator-crd/$SOURCE" |
29 | 31 |
|
30 |
| - echo -e "Downloading Prometheus Operator CRD with Version ${VERSION}:\n${URL}\n" |
| 32 | + echo -e "Downloading Prometheus Operator CRD with Version ${VERSION}:\n${URL}\n" |
31 | 33 |
|
32 |
| - echo "# ${URL}" > "${SCRIPT_DIR}/../charts/crds/templates/${DESTINATION}" |
| 34 | + echo "# ${URL}" >"${SCRIPT_DIR}/../charts/crds/templates/${DESTINATION}" |
33 | 35 |
|
34 |
| - if ! curl --silent --retry-all-errors --fail --location "${URL}" >> "${SCRIPT_DIR}/../charts/crds/templates/${DESTINATION}"; then |
35 |
| - echo -e "Failed to download ${URL}!" |
36 |
| - exit 1 |
37 |
| - fi |
| 36 | + if ! curl --silent --retry-all-errors --fail --location "${URL}" >>"${SCRIPT_DIR}/../charts/crds/templates/${DESTINATION}"; then |
| 37 | + echo -e "Failed to download ${URL}!" |
| 38 | + exit 1 |
| 39 | + fi |
38 | 40 |
|
39 |
| - # Update or insert annotations block |
40 |
| - if yq -e '.metadata.annotations' "${SCRIPT_DIR}/../charts/crds/templates/${DESTINATION}" >/dev/null; then |
41 |
| - sed -i '/^ annotations:$/a {{- with .Values.annotations }}\n{{- toYaml . | nindent 4 }}\n{{- end }}' "${SCRIPT_DIR}/../charts/crds/templates/${DESTINATION}" |
42 |
| - else |
43 |
| - sed -i '/^metadata:$/a {{- with .Values.annotations }}\n annotations:\n{{- toYaml . | nindent 4 }}\n{{- end }}' "${SCRIPT_DIR}/../charts/crds/templates/${DESTINATION}" |
44 |
| - fi |
| 41 | + # Update or insert annotations block |
| 42 | + if yq -e '.metadata.annotations' "${SCRIPT_DIR}/../charts/crds/templates/${DESTINATION}" >/dev/null; then |
| 43 | + sed -i '/^ annotations:$/a {{- with .Values.annotations }}\n{{- toYaml . | nindent 4 }}\n{{- end }}' "${SCRIPT_DIR}/../charts/crds/templates/${DESTINATION}" |
| 44 | + else |
| 45 | + sed -i '/^metadata:$/a {{- with .Values.annotations }}\n annotations:\n{{- toYaml . | nindent 4 }}\n{{- end }}' "${SCRIPT_DIR}/../charts/crds/templates/${DESTINATION}" |
| 46 | + fi |
| 47 | + |
| 48 | + # Insert enable option |
| 49 | + sed -i "1i\{{- if .Values.${CRD}.enabled -}}" "${SCRIPT_DIR}/../charts/crds/templates/${DESTINATION}" |
| 50 | + echo "{{- end -}}" >>"${SCRIPT_DIR}/../charts/crds/templates/${DESTINATION}" |
45 | 51 | done
|
0 commit comments