Skip to content

Commit

Permalink
feat: adding namespace override
Browse files Browse the repository at this point in the history
Signed-off-by: Rafael Brito <[email protected]>
  • Loading branch information
brito-rafa committed Jan 11, 2024
1 parent 7da1888 commit 43623fd
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 4 deletions.
23 changes: 21 additions & 2 deletions charts/opencost/README.md.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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=<your-namespace>`
`--set opencost.prometheus.internal.service=<your-service>`
```


{{ template "chart.requirementsSection" . }}

{{ template "chart.valuesSection" . }}
Expand Down
11 changes: 11 additions & 0 deletions charts/opencost/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
2 changes: 1 addition & 1 deletion charts/opencost/templates/clusterrolebinding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ roleRef:
subjects:
- kind: ServiceAccount
name: {{ template "opencost.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
namespace: {{ include "opencost.namespace" . }}
{{- end }}
1 change: 1 addition & 0 deletions charts/opencost/templates/configmap-custom-pricing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Values.opencost.customPricing.configmapName }}
namespace: {{ include "opencost.namespace" . }}
data:
{{ include "opencost.configFileName" . }}.json: |-
{
Expand Down
1 change: 1 addition & 0 deletions charts/opencost/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
1 change: 1 addition & 0 deletions charts/opencost/templates/ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
2 changes: 1 addition & 1 deletion charts/opencost/templates/networkpolicy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
kind: NetworkPolicy
metadata:
name: {{ .Release.Name }}-opencost
namespace: {{ .Release.Namespace }}
namespace: {{ include "opencost.namespace" . }}
spec:
podSelector:
matchLabels:
Expand Down
1 change: 1 addition & 0 deletions charts/opencost/templates/pvc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
1 change: 1 addition & 0 deletions charts/opencost/templates/secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
1 change: 1 addition & 0 deletions charts/opencost/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
1 change: 1 addition & 0 deletions charts/opencost/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
2 changes: 2 additions & 0 deletions charts/opencost/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: []
Expand Down

0 comments on commit 43623fd

Please sign in to comment.