From 43623fdbe47572f9ca677f85c972a51842ff6579 Mon Sep 17 00:00:00 2001 From: Rafael Brito Date: Thu, 11 Jan 2024 14:52:40 -0600 Subject: [PATCH] feat: adding namespace override Signed-off-by: Rafael Brito --- charts/opencost/README.md.gotmpl | 23 +++++++++++++++++-- charts/opencost/templates/_helpers.tpl | 11 +++++++++ .../templates/clusterrolebinding.yaml | 2 +- .../templates/configmap-custom-pricing.yaml | 1 + charts/opencost/templates/deployment.yaml | 1 + charts/opencost/templates/ingress.yaml | 1 + charts/opencost/templates/networkpolicy.yaml | 2 +- charts/opencost/templates/pvc.yaml | 1 + charts/opencost/templates/secret.yaml | 1 + charts/opencost/templates/service.yaml | 1 + charts/opencost/templates/serviceaccount.yaml | 1 + charts/opencost/values.yaml | 2 ++ 12 files changed, 43 insertions(+), 4 deletions(-) diff --git a/charts/opencost/README.md.gotmpl b/charts/opencost/README.md.gotmpl index 6747337..c932069 100644 --- a/charts/opencost/README.md.gotmpl +++ b/charts/opencost/README.md.gotmpl @@ -10,12 +10,31 @@ ## Installing the Chart -To install the chart with the release name `opencost`: +To install the chart with the release name `opencost` on `opencost` namespace: ```console -$ helm install opencost opencost/{{ template "chart.name" . }} +$ helm install opencost opencost/{{ template "chart.name" . }} --namespace opencost --create-namespace ``` +In order to have a working opencost installation, you need to provide one running instance of Prometheus. +The following will install a prometheus instance on the namespace `prometheus-system`, where the default helm chart is expecting: + +``` +helm install prometheus --repo https://prometheus-community.github.io/helm-charts prometheus \ + --namespace prometheus-system --create-namespace \ + --set prometheus-pushgateway.enabled=false \ + --set alertmanager.enabled=false \ + -f https://raw.githubusercontent.com/opencost/opencost/develop/kubernetes/prometheus/extraScrapeConfigs.yaml +``` + +During installation, you can specify the following parameters if you have your own internal Prometheus: + +``` +`--set opencost.prometheus.internal.namespace=` +`--set opencost.prometheus.internal.service=` +``` + + {{ template "chart.requirementsSection" . }} {{ template "chart.valuesSection" . }} diff --git a/charts/opencost/templates/_helpers.tpl b/charts/opencost/templates/_helpers.tpl index bb93c20..282fc0e 100644 --- a/charts/opencost/templates/_helpers.tpl +++ b/charts/opencost/templates/_helpers.tpl @@ -30,6 +30,17 @@ We truncate at 63 chars because some Kubernetes name fields are limited to this {{- end -}} {{- end -}} +{{/* +Allow the release namespace to be overridden +*/}} +{{- define "opencost.namespace" -}} + {{- if .Values.namespaceOverride -}} + {{- .Values.namespaceOverride -}} + {{- else -}} + {{- .Release.Namespace -}} + {{- end -}} +{{- end -}} + {{/* Create a default fully qualified app name. We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). diff --git a/charts/opencost/templates/clusterrolebinding.yaml b/charts/opencost/templates/clusterrolebinding.yaml index 8671197..56f4e00 100644 --- a/charts/opencost/templates/clusterrolebinding.yaml +++ b/charts/opencost/templates/clusterrolebinding.yaml @@ -14,5 +14,5 @@ roleRef: subjects: - kind: ServiceAccount name: {{ template "opencost.serviceAccountName" . }} - namespace: {{ .Release.Namespace }} + namespace: {{ include "opencost.namespace" . }} {{- end }} diff --git a/charts/opencost/templates/configmap-custom-pricing.yaml b/charts/opencost/templates/configmap-custom-pricing.yaml index 8f2bae0..d749737 100644 --- a/charts/opencost/templates/configmap-custom-pricing.yaml +++ b/charts/opencost/templates/configmap-custom-pricing.yaml @@ -3,6 +3,7 @@ apiVersion: v1 kind: ConfigMap metadata: name: {{ .Values.opencost.customPricing.configmapName }} + namespace: {{ include "opencost.namespace" . }} data: {{ include "opencost.configFileName" . }}.json: |- { diff --git a/charts/opencost/templates/deployment.yaml b/charts/opencost/templates/deployment.yaml index b726c2e..f44a1bf 100644 --- a/charts/opencost/templates/deployment.yaml +++ b/charts/opencost/templates/deployment.yaml @@ -3,6 +3,7 @@ apiVersion: apps/v1 kind: Deployment metadata: name: {{ include "opencost.fullname" . }} + namespace: {{ include "opencost.namespace" . }} labels: {{- include "opencost.labels" . | nindent 4 }} {{- with .Values.annotations }} annotations: {{- toYaml . | nindent 4 }} diff --git a/charts/opencost/templates/ingress.yaml b/charts/opencost/templates/ingress.yaml index 0c7010d..7973d12 100644 --- a/charts/opencost/templates/ingress.yaml +++ b/charts/opencost/templates/ingress.yaml @@ -3,6 +3,7 @@ apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: {{ include "opencost.fullname" . }}-ingress + namespace: {{ include "opencost.namespace" . }} labels: {{- include "opencost.labels" . | nindent 4 }} {{- with .Values.opencost.ui.ingress.annotations }} annotations: {{- toYaml . | nindent 4 }} diff --git a/charts/opencost/templates/networkpolicy.yaml b/charts/opencost/templates/networkpolicy.yaml index 3362177..ae6efd9 100644 --- a/charts/opencost/templates/networkpolicy.yaml +++ b/charts/opencost/templates/networkpolicy.yaml @@ -6,7 +6,7 @@ kind: NetworkPolicy metadata: name: {{ .Release.Name }}-opencost - namespace: {{ .Release.Namespace }} + namespace: {{ include "opencost.namespace" . }} spec: podSelector: matchLabels: diff --git a/charts/opencost/templates/pvc.yaml b/charts/opencost/templates/pvc.yaml index 7a158b2..1295765 100644 --- a/charts/opencost/templates/pvc.yaml +++ b/charts/opencost/templates/pvc.yaml @@ -3,6 +3,7 @@ kind: PersistentVolumeClaim apiVersion: v1 metadata: name: {{ include "opencost.fullname" . }}-pvc + namespace: {{ include "opencost.namespace" . }} labels: {{- include "opencost.labels" . | nindent 4 }} {{- with .Values.opencost.exporter.persistence.annotations }} annotations: {{- toYaml . | nindent 4 }} diff --git a/charts/opencost/templates/secret.yaml b/charts/opencost/templates/secret.yaml index e451637..214f649 100644 --- a/charts/opencost/templates/secret.yaml +++ b/charts/opencost/templates/secret.yaml @@ -3,6 +3,7 @@ apiVersion: v1 kind: Secret metadata: name: {{ include "opencost.prometheus.secretname" . }} + namespace: {{ include "opencost.namespace" . }} labels: {{- include "opencost.labels" . | nindent 4 }} {{- with .Values.secretAnnotations }} annotations: {{- toYaml . | nindent 4 }} diff --git a/charts/opencost/templates/service.yaml b/charts/opencost/templates/service.yaml index f07b677..ac3d963 100644 --- a/charts/opencost/templates/service.yaml +++ b/charts/opencost/templates/service.yaml @@ -3,6 +3,7 @@ apiVersion: v1 kind: Service metadata: name: {{ include "opencost.fullname" . }} + namespace: {{ include "opencost.namespace" . }} labels: {{- include "opencost.labels" . | nindent 4 }} {{- with .Values.service.labels }} diff --git a/charts/opencost/templates/serviceaccount.yaml b/charts/opencost/templates/serviceaccount.yaml index d93f1ce..cdfe390 100644 --- a/charts/opencost/templates/serviceaccount.yaml +++ b/charts/opencost/templates/serviceaccount.yaml @@ -3,6 +3,7 @@ apiVersion: v1 kind: ServiceAccount metadata: name: {{ template "opencost.serviceAccountName" . }} + namespace: {{ include "opencost.namespace" . }} labels: {{- include "opencost.labels" . | nindent 4 }} {{- with .Values.serviceAccount.annotations }} annotations: {{- toYaml . | nindent 4 }} diff --git a/charts/opencost/values.yaml b/charts/opencost/values.yaml index d3959bb..ee58f6c 100644 --- a/charts/opencost/values.yaml +++ b/charts/opencost/values.yaml @@ -2,6 +2,8 @@ nameOverride: "" # -- Overwrite all resources name created by the chart fullnameOverride: "" +# -- Override the deployment namespace +namespaceOverride: "" # -- List of secret names to use for pulling the images imagePullSecrets: []