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

Reformat chart templates #81

Merged
merged 2 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion charts/opencost/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ keywords:
- kubecost
- opencost
- monitoring
version: 1.15.0
version: 1.16.0
maintainers:
- name: mattray
url: https://mattray.dev
Expand Down
2 changes: 1 addition & 1 deletion charts/opencost/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

OpenCost and OpenCost UI

![Version: 1.15.0](https://img.shields.io/badge/Version-1.15.0-informational?style=flat-square)
![Version: 1.16.0](https://img.shields.io/badge/Version-1.16.0-informational?style=flat-square)
![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square)
![AppVersion: 1.104.0](https://img.shields.io/badge/AppVersion-1.104.0-informational?style=flat-square)

Expand Down
56 changes: 28 additions & 28 deletions charts/opencost/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,43 @@
Expand the name of the chart.
*/}}
{{- define "opencost.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "opencost.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- 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).
*/}}
{{- define "opencost.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- if contains $name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- if contains $name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- 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).
*/}}
{{- define "opencost.prometheus.secretname" -}}
{{- if .Values.opencost.prometheus.secret_name -}}
{{- .Values.opencost.prometheus.secret_name -}}
{{- else -}}
{{- include "opencost.fullname" . -}}
{{- end -}}
{{- if .Values.opencost.prometheus.secret_name -}}
{{- .Values.opencost.prometheus.secret_name -}}
{{- else -}}
{{- include "opencost.fullname" . -}}
{{- end -}}
{{- end -}}

{{/*
Expand Down Expand Up @@ -70,33 +70,33 @@ app.kubernetes.io/instance: {{ .Release.Name }}
Create the name of the controller service account to use
*/}}
{{- define "opencost.serviceAccountName" -}}
{{- if .Values.serviceAccount.create -}}
{{ default (include "opencost.fullname" .) .Values.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.serviceAccount.name }}
{{- end -}}
{{- if .Values.serviceAccount.create -}}
{{- default (include "opencost.fullname" .) .Values.serviceAccount.name }}
{{- else -}}
{{- default "default" .Values.serviceAccount.name }}
{{- end -}}
{{- end -}}

{{/*
Create the name of the controller service account to use
*/}}
{{- define "opencost.prometheusServerEndpoint" -}}
{{- if .Values.opencost.prometheus.external.enabled -}}
{{- if .Values.opencost.prometheus.external.enabled -}}
{{ .Values.opencost.prometheus.external.url }}
{{- else -}}
{{- else -}}
{{- $host := .Values.opencost.prometheus.internal.serviceName }}
{{- $ns := .Values.opencost.prometheus.internal.namespaceName }}
{{- $port := .Values.opencost.prometheus.internal.port | int }}
{{- printf "http://%s.%s.svc:%d" $host $ns $port -}}
{{- end -}}
{{- end -}}
{{- end -}}


{{/*
Check that either prometheus external or internal is defined
*/}}
{{- define "isPrometheusConfigValid" -}}
{{- if and .Values.opencost.prometheus.external.enabled .Values.opencost.prometheus.internal.enabled -}}
{{- fail "Only use one of the prometheus setups, internal or external" -}}
{{- end -}}
{{- if and .Values.opencost.prometheus.external.enabled .Values.opencost.prometheus.internal.enabled -}}
{{- fail "Only use one of the prometheus setups, internal or external" -}}
{{- end -}}
{{- end -}}
3 changes: 1 addition & 2 deletions charts/opencost/templates/clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
{{- include "opencost.labels" . | nindent 4 }}
name: {{ include "opencost.fullname" . }}
labels: {{- include "opencost.labels" . | nindent 4 }}
rules:
- apiGroups: [""]
resources:
Expand Down
12 changes: 5 additions & 7 deletions charts/opencost/templates/clusterrolebinding.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
{{- if .Values.rbac.enabled -}}
{{- if .Values.rbac.enabled }}
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
labels:
{{- include "opencost.labels" . | nindent 4 }}
name: {{ include "opencost.fullname" . }}
{{- if .Values.annotations }}
annotations:
{{- toYaml .Values.annotations | nindent 4 }}
labels: {{- include "opencost.labels" . | nindent 4 }}
{{- with .Values.annotations }}
annotations: {{- toYaml . | nindent 4 }}
{{- end }}
roleRef:
apiGroup: rbac.authorization.k8s.io
Expand All @@ -17,4 +15,4 @@ subjects:
- kind: ServiceAccount
name: {{ template "opencost.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
{{- end -}}
{{- end }}
150 changes: 70 additions & 80 deletions charts/opencost/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
{{- include "isPrometheusConfigValid" . -}}
{{- include "isPrometheusConfigValid" . }}
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
{{- include "opencost.labels" . | nindent 4 }}
name: {{ include "opencost.fullname" . }}
{{- if .Values.annotations }}
annotations: {{ toYaml .Values.annotations | nindent 4 }}
labels: {{- include "opencost.labels" . | nindent 4 }}
{{- with .Values.annotations }}
annotations: {{- toYaml . | nindent 4 }}
{{- end }}
spec:
replicas: {{ .Values.opencost.exporter.replicas }}
selector:
matchLabels:
{{- include "opencost.selectorLabels" . | nindent 6 }}
matchLabels: {{- include "opencost.selectorLabels" . | nindent 6 }}
strategy:
rollingUpdate:
maxSurge: 1
Expand All @@ -22,72 +20,63 @@ spec:
metadata:
labels:
{{- include "opencost.selectorLabels" . | nindent 8 }}
{{- if .Values.podLabels }}
{{- toYaml .Values.podLabels | nindent 8 }}
{{- with .Values.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- if .Values.podAnnotations }}
annotations:
{{- toYaml .Values.podAnnotations | nindent 8 }}
{{- with .Values.podAnnotations }}
annotations: {{- toYaml . | nindent 8 }}
{{- end }}
spec:
{{- if .Values.imagePullSecrets }}
imagePullSecrets: {{ toYaml .Values.imagePullSecrets | nindent 8 }}
{{- end }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
serviceAccountName: {{ template "opencost.serviceAccountName" . }}
tolerations:
{{- toYaml .Values.opencost.tolerations | nindent 8 }}
{{- with .Values.opencost.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- with .Values.imagePullSecrets }}
imagePullSecrets: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.priorityClassName }}
priorityClassName: {{ . }}
{{- end }}
{{- with .Values.podSecurityContext }}
securityContext: {{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ template "opencost.serviceAccountName" . }}
{{- with .Values.opencost.tolerations }}
tolerations: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.opencost.nodeSelector }}
nodeSelector: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.opencost.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
affinity: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with.Values.opencost.topologySpreadConstraints }}
topologySpreadConstraints:
{{- toYaml . | nindent 8 }}
topologySpreadConstraints: {{- toYaml . | nindent 8 }}
{{- end }}
containers:
- image: "{{ .Values.opencost.exporter.image.registry }}/{{ .Values.opencost.exporter.image.repository }}:{{ .Values.opencost.exporter.image.tag | default (printf "prod-%s" .Chart.AppVersion) }}"
name: {{ include "opencost.fullname" . }}
resources:
{{- toYaml .Values.opencost.exporter.resources | nindent 12 }}
{{- with .Values.opencost.exporter.livenessProbe }}
{{- if .enabled }}
- name: {{ include "opencost.fullname" . }}
image: "{{ .Values.opencost.exporter.image.registry }}/{{ .Values.opencost.exporter.image.repository }}:{{ .Values.opencost.exporter.image.tag | default (printf "prod-%s" .Chart.AppVersion) }}"
imagePullPolicy: Always
ports:
- containerPort: 9003
name: http
resources: {{- toYaml .Values.opencost.exporter.resources | nindent 12 }}
{{- if .Values.opencost.exporter.livenessProbe.enabled }}
livenessProbe:
httpGet:
path: /healthz
port: 9003
initialDelaySeconds: {{ .initialDelaySeconds }}
periodSeconds: {{ .periodSeconds }}
failureThreshold: {{ .failureThreshold }}
initialDelaySeconds: {{ .Values.opencost.exporter.livenessProbe.initialDelaySeconds }}
periodSeconds: {{ .Values.opencost.exporter.livenessProbe.periodSeconds }}
failureThreshold: {{ .Values.opencost.exporter.livenessProbe.failureThreshold }}
{{- end }}
{{- end }}
{{- with .Values.opencost.exporter.readinessProbe }}
{{- if .enabled }}
{{- if .Values.opencost.exporter.readinessProbe.enabled }}
readinessProbe:
httpGet:
path: /healthz
port: 9003
initialDelaySeconds: {{ .initialDelaySeconds }}
periodSeconds: {{ .periodSeconds }}
failureThreshold: {{ .failureThreshold }}
{{- end }}
initialDelaySeconds: {{ .Values.opencost.exporter.readinessProbe.initialDelaySeconds }}
periodSeconds: {{ .Values.opencost.exporter.readinessProbe.periodSeconds }}
failureThreshold: {{ .Values.opencost.exporter.readinessProbe.failureThreshold }}
{{- end }}
ports:
- containerPort: 9003
name: http
securityContext:
{{- toYaml .Values.opencost.exporter.securityContext | nindent 12 }}
{{- with .Values.opencost.exporter.extraVolumeMounts }}
volumeMounts:
{{- toYaml . | nindent 12 }}
{{- with .Values.opencost.exporter.securityContext }}
securityContext: {{- toYaml . | nindent 12 }}
{{- end }}
env:
- name: PROMETHEUS_SERVER_ENDPOINT
Expand Down Expand Up @@ -145,57 +134,58 @@ spec:
- name: {{ $key }}
value: {{ $value | quote }}
{{- end }}
{{- if .Values.opencost.exporter.persistence.enabled }}
{{- if or .Values.opencost.exporter.persistence.enabled .Values.opencost.exporter.extraVolumeMounts }}
volumeMounts:
{{- if .Values.opencost.exporter.persistence.enabled }}
- mountPath: /mnt/export
name: opencost-export
readOnly: false
{{- end }}
{{- with .Values.opencost.exporter.extraVolumeMounts }}
{{- toYaml . | nindent 12 }}
{{- end }}
{{- end }}
imagePullPolicy: Always
{{- if .Values.opencost.ui.enabled }}
- image: "{{ .Values.opencost.ui.image.registry }}/{{ .Values.opencost.ui.image.repository }}:{{ .Values.opencost.ui.image.tag | default (printf "prod-%s" .Chart.AppVersion) }}"
name: opencost-ui
{{- with .Values.opencost.ui.livenessProbe }}
{{- if .enabled }}
- name: opencost-ui
image: "{{ .Values.opencost.ui.image.registry }}/{{ .Values.opencost.ui.image.repository }}:{{ .Values.opencost.ui.image.tag | default (printf "prod-%s" .Chart.AppVersion) }}"
imagePullPolicy: Always
ports:
- containerPort: 9090
name: http-ui
resources: {{- toYaml .Values.opencost.ui.resources | nindent 12 }}
{{- if .Values.opencost.ui.livenessProbe.enabled }}
livenessProbe:
httpGet:
path: /healthz
port: 9090
initialDelaySeconds: {{ .initialDelaySeconds }}
periodSeconds: {{ .periodSeconds }}
failureThreshold: {{ .failureThreshold }}
{{- end }}
initialDelaySeconds: {{ .Values.opencost.ui.livenessProbe.initialDelaySeconds }}
periodSeconds: {{ .Values.opencost.ui.livenessProbe.periodSeconds }}
failureThreshold: {{ .Values.opencost.ui.livenessProbe.failureThreshold }}
{{- end }}
{{- with .Values.opencost.ui.readinessProbe }}
{{- if .enabled }}
{{- if .Values.opencost.ui.readinessProbe.enabled }}
readinessProbe:
httpGet:
path: /healthz
port: 9090
initialDelaySeconds: {{ .initialDelaySeconds }}
periodSeconds: {{ .periodSeconds }}
failureThreshold: {{ .failureThreshold }}
initialDelaySeconds: {{ .Values.opencost.ui.readinessProbe.initialDelaySeconds }}
periodSeconds: {{ .Values.opencost.ui.readinessProbe.periodSeconds }}
failureThreshold: {{ .Values.opencost.ui.readinessProbe.failureThreshold }}
{{- end }}
{{- with .Values.opencost.ui.securityContext }}
securityContext: {{- toYaml . | nindent 12 }}
{{- end }}
resources:
{{- toYaml .Values.opencost.ui.resources | nindent 12 }}
imagePullPolicy: Always
ports:
- containerPort: 9090
name: http-ui
securityContext:
{{- toYaml .Values.opencost.ui.securityContext | nindent 12 }}
{{- with .Values.opencost.ui.extraVolumeMounts }}
volumeMounts:
{{- toYaml . | nindent 12 }}
volumeMounts: {{- toYaml . | nindent 12 }}
{{- end }}
{{- end }}
{{- if or .Values.opencost.exporter.persistence.enabled .Values.extraVolumes }}
volumes:
{{- if .Values.opencost.exporter.persistence.enabled }}
{{- if .Values.opencost.exporter.persistence.enabled }}
- name: opencost-export
persistentVolumeClaim:
claimName: {{ include "opencost.fullname" . }}-pvc
{{- end }}
{{- with .Values.extraVolumes }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.extraVolumes }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- end }}
Loading