Skip to content

Commit e91d8c4

Browse files
authored
Define node selector and tolerations for prometheus (#625)
Prometheus spec allows for setting node selectors and tolerations https://github.com/prometheus-community/helm-charts/blob/main/charts/kube-prometheus-stack/values.yaml, but we couldn't override those as the operator spec didn't configure it. - Added spec and new variables in prometheus-cloud.values.yaml - Kept default values for the values-cloud.yaml empty - Corresponding replaces in the cloud/prometheus-operator.yaml Changed the yaml replace structure to accomodate iterating over interface objects, open to suggestions for more robustness. --------- Signed-off-by: Dharini Dutia <dharinidutia@intrinsic.ai>
1 parent 7bd3637 commit e91d8c4

3 files changed

Lines changed: 30 additions & 1 deletion

File tree

src/app_charts/prometheus/cloud/prometheus-operator.yaml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,28 @@
55
# prometheus deployment. How could we let them override prometheus-cloud.values.yaml?
66
# NOTE: The order here is important. The domain and project might be part of other values and
77
# need to be replaced last.
8-
{{ .Files.Get "files/prometheus-operator-chart.cloud.yaml" | replace "${CR_GF_SERVER_DOMAIN}" .Values.gf_server_domain | replace "${CR_GF_SERVER_ROOT_URL}" .Values.gf_server_root_url | replace "${CR_GF_CSRF_TRUSTED_ORIGINS}" .Values.gf_csrf_trusted_origins | replace "${CR_GF_SMTP_ENABLED}" .Values.gf_smtp_enabled | replace "${CR_GF_SMTP_HOST}" .Values.gf_smtp_host | replace "${CR_GF_SMTP_USER}" .Values.gf_smtp_user | replace "${CR_GF_SMTP_PASSWORD}" .Values.gf_smtp_password | replace "${CR_GF_SMTP_FROM_ADDRESS}" .Values.gf_smtp_from_address | replace "${CR_GF_SMTP_FROM_NAME}" .Values.gf_smtp_from_name | replace "${CR_GF_SMTP_SKIP_VERIFY}" .Values.gf_smtp_skip_verify | replace "${CR_GF_INGRESS_AUTH_URL}" .Values.gf_ingress_auth_url | replace "${CR_GF_INGRESS_AUTH_SIGNIN}" .Values.gf_ingress_auth_signin | replace "${CR_GF_INGRESS_ERROR_PAGE_403}" .Values.gf_ingress_error_page_403 | replace "${CR_PROM_INGRESS_AUTH_URL}" .Values.prom_ingress_auth_url | replace "${CR_PROM_INGRESS_AUTH_SIGNIN}" .Values.prom_ingress_auth_signin | replace "${CR_PROM_INGRESS_ERROR_PAGE_403}" .Values.prom_ingress_error_page_403 | replace "HELM-NAMESPACE" .Release.Namespace | replace "${LIMITS_MEMORY}" .Values.limits.memory | replace "${LIMITS_CPU}" .Values.limits.cpu | replace "${REQUESTS_STORAGE}" .Values.requests.storage | replace "${RETENTION_TIME}" .Values.retention.time | replace "${RETENTION_SIZE}" .Values.retention.size | replace "${EXTERNAL_URL}" .Values.prom_external_url | replace "${CLOUD_ROBOTICS_DOMAIN}" .Values.domain | replace "${GCP_PROJECT_ID}" .Values.project }}
8+
{{- $data := .Files.Get "files/prometheus-operator-chart.cloud.yaml" -}}
9+
# Pre-process variables
10+
{{- $data = $data | replace "${CR_GF_SERVER_DOMAIN}" .Values.gf_server_domain | replace "${CR_GF_SERVER_ROOT_URL}" .Values.gf_server_root_url | replace "${CR_GF_CSRF_TRUSTED_ORIGINS}" .Values.gf_csrf_trusted_origins | replace "${CR_GF_SMTP_ENABLED}" .Values.gf_smtp_enabled | replace "${CR_GF_SMTP_HOST}" .Values.gf_smtp_host | replace "${CR_GF_SMTP_USER}" .Values.gf_smtp_user | replace "${CR_GF_SMTP_PASSWORD}" .Values.gf_smtp_password | replace "${CR_GF_SMTP_FROM_ADDRESS}" .Values.gf_smtp_from_address | replace "${CR_GF_SMTP_FROM_NAME}" .Values.gf_smtp_from_name | replace "${CR_GF_SMTP_SKIP_VERIFY}" .Values.gf_smtp_skip_verify | replace "${CR_GF_INGRESS_AUTH_URL}" .Values.gf_ingress_auth_url | replace "${CR_GF_INGRESS_AUTH_SIGNIN}" .Values.gf_ingress_auth_signin | replace "${CR_GF_INGRESS_ERROR_PAGE_403}" .Values.gf_ingress_error_page_403 | replace "${CR_PROM_INGRESS_AUTH_URL}" .Values.prom_ingress_auth_url | replace "${CR_PROM_INGRESS_AUTH_SIGNIN}" .Values.prom_ingress_auth_signin | replace "${CR_PROM_INGRESS_ERROR_PAGE_403}" .Values.prom_ingress_error_page_403 | replace "HELM-NAMESPACE" .Release.Namespace | replace "${LIMITS_MEMORY}" .Values.limits.memory | replace "${LIMITS_CPU}" .Values.limits.cpu | replace "${REQUESTS_STORAGE}" .Values.requests.storage | replace "${RETENTION_TIME}" .Values.retention.time | replace "${RETENTION_SIZE}" .Values.retention.size | replace "${EXTERNAL_URL}" .Values.prom_external_url | replace "${CLOUD_ROBOTICS_DOMAIN}" .Values.domain | replace "${GCP_PROJECT_ID}" .Values.project -}}
11+
12+
# Inject the nodeSelector as a pre-formatted YAML block to allow users to define multiple selectors in a dict within values-cloud.yaml while maintaining valid indentation in the output.
13+
{{- $prometheusNodeSelectorMap := .Values.prometheus.prometheusSpec.nodeSelector -}}
14+
{{- if $prometheusNodeSelectorMap }}
15+
{{- $prometheusNodeSelectorRawYaml := toYaml $prometheusNodeSelectorMap -}}
16+
{{- $formattedPrometheusNodeSelectorObject := $prometheusNodeSelectorRawYaml | nindent 6 -}}
17+
{{- $data = $data | replace "${CR_PROMETHEUS_NODE_SELECTOR_OBJECT}" $formattedPrometheusNodeSelectorObject -}}
18+
{{- else }}
19+
{{- $data = $data | replace "${CR_PROMETHEUS_NODE_SELECTOR_OBJECT}" " {}" -}}
20+
{{- end }}
21+
22+
# Inject the tolerations as a pre-formatted YAML block to support multiple key-value pairs in a list within values-cloud.yaml
23+
{{- $prometheusTolerationsList := .Values.prometheus.prometheusSpec.tolerations -}}
24+
{{- if $prometheusTolerationsList }}
25+
{{- $prometheusTolerationsRawYaml := toYaml $prometheusTolerationsList -}}
26+
{{- $formattedTolerationsObject := $prometheusTolerationsRawYaml | nindent 6 -}}
27+
{{- $data = $data | replace "${CR_PROMETHEUS_TOLERATIONS_OBJECT}" $formattedTolerationsObject -}}
28+
{{- else }}
29+
{{- $data = $data | replace "${CR_PROMETHEUS_TOLERATIONS_OBJECT}" " []" -}}
30+
{{- end }}
31+
32+
{{ $data }}

src/app_charts/prometheus/prometheus-cloud.values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ prometheus:
6363
retention: "${RETENTION_TIME}"
6464
retentionSize: "${RETENTION_SIZE}"
6565
walCompression: true
66+
nodeSelector: "${CR_PROMETHEUS_NODE_SELECTOR_OBJECT}"
67+
tolerations: "${CR_PROMETHEUS_TOLERATIONS_OBJECT}"
6668
resources:
6769
requests:
6870
cpu: "${LIMITS_CPU}"

src/app_charts/prometheus/values-cloud.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ retention:
3333

3434
# MetricRelabelConfigs to apply to samples after scraping, but before ingestion.
3535
prometheus:
36+
prometheusSpec:
37+
nodeSelector: {}
38+
tolerations: []
3639
serviceMonitor:
3740
metricRelabelings: []
3841

0 commit comments

Comments
 (0)