1+ { {/* vim: set filetype= mustache: */} }
2+ { {/*
3+ Expand the name of the chart.
4+ */} }
5+ { {- define " opencost.name" -} }
6+ { {- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix " -" -} }
7+ { {- end -} }
8+
9+ { {/*
10+ Create chart name and version as used by the chart label.
11+ */} }
12+ { {- define " opencost.chart" -} }
13+ { {- printf " %s-%s" .Chart.Name .Chart.Version | replace " +" " _" | trunc 63 | trimSuffix " -" -} }
14+ { {- end -} }
15+
16+ { {/*
17+ Create a default fully qualified app name.
18+ We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
19+ */} }
20+ { {- define " opencost.fullname" -} }
21+ { {- if .Values.fullnameOverride -} }
22+ { {- .Values.fullnameOverride | trunc 63 | trimSuffix " -" -} }
23+ { {- else -} }
24+ { {- $name := default .Chart.Name .Values.nameOverride -} }
25+ { {- if contains $name .Release.Name -} }
26+ { {- .Release.Name | trunc 63 | trimSuffix " -" -} }
27+ { {- else -} }
28+ { {- printf " %s-%s" .Release.Name $name | trunc 63 | trimSuffix " -" -} }
29+ { {- end -} }
30+ { {- end -} }
31+ { {- end -} }
32+
33+ { {/*
34+ Allow the release namespace to be overridden
35+ */} }
36+ { {- define " opencost.namespace" -} }
37+ { {- if .Values.namespaceOverride -} }
38+ { {- .Values.namespaceOverride -} }
39+ { {- else -} }
40+ { {- .Release.Namespace -} }
41+ { {- end -} }
42+ { {- end -} }
43+
44+ { {/*
45+ Create a default fully qualified app name.
46+ We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
47+ */} }
48+ { {- define " opencost.prometheus.secretname" -} }
49+ { {- if .Values.opencost.prometheus.secret_name -} }
50+ { {- .Values.opencost.prometheus.secret_name -} }
51+ { {- else -} }
52+ { {- include " opencost.fullname" . -} }
53+ { {- end -} }
54+ { {- end -} }
55+
56+ { {/*
57+ Common labels
58+ */} }
59+ { {- define " opencost.labels" -} }
60+ helm.sh/chart: { { include " opencost.chart" . } }
61+ { { include " opencost.selectorLabels" . } }
62+ { {- if .Chart.AppVersion } }
63+ app.kubernetes.io/version: { { .Chart.AppVersion | quote } }
64+ { {- end } }
65+ app.kubernetes.io/part-of: { { template " opencost.name" . } }
66+ app.kubernetes.io/managed-by: { { .Release.Service } }
67+ { {- if .Values.commonLabels} }
68+ { { toYaml .Values.commonLabels } }
69+ { {- end } }
70+ { {- end -} }
71+
72+ { {/*
73+ Selector labels
74+ */} }
75+ { {- define " opencost.selectorLabels" -} }
76+ app.kubernetes.io/name: { { include " opencost.name" . } }
77+ app.kubernetes.io/instance: { { .Release.Name } }
78+ { {- end -} }
79+
80+ { {/*
81+ Create the name of the controller service account to use
82+ */} }
83+ { {- define " opencost.serviceAccountName" -} }
84+ { {- if .Values.serviceAccount.create -} }
85+ { {- default (include " opencost.fullname" .) .Values.serviceAccount.name } }
86+ { {- else -} }
87+ { {- default " default" .Values.serviceAccount.name } }
88+ { {- end -} }
89+ { {- end -} }
90+
91+ { {/*
92+ Create the name of the controller service account to use
93+ */} }
94+ { {- define " opencost.prometheusServerEndpoint" -} }
95+ { {- if .Values.opencost.prometheus.external.enabled -} }
96+ { { tpl .Values.opencost.prometheus.external.url . } }
97+ { {- else if (and .Values.opencost.prometheus.amp.enabled .Values.opencost.sigV4Proxy) -} }
98+ { {- $port := .Values.opencost.sigV4Proxy.port | int } }
99+ { {- $ws := .Values.opencost.prometheus.amp.workspaceId } }
100+ { {- printf " http://localhost:%d/workspaces/%v" $port $ws -} }
101+ { {- else -} }
102+ { {- $host := tpl .Values.opencost.prometheus.internal.serviceName . } }
103+ { {- $ns := tpl .Values.opencost.prometheus.internal.namespaceName . } }
104+ { {- $port := .Values.opencost.prometheus.internal.port | int } }
105+ { {- printf " http://%s.%s.svc.cluster.local:%d" $host $ns $port -} }
106+ { {- end -} }
107+ { {- end -} }
108+
109+ { {/*
110+ Check that either thanos external or internal is defined
111+ */} }
112+ { {- define " opencost.thanosServerEndpoint" -} }
113+ { {- if .Values.opencost.prometheus.thanos.external.enabled -} }
114+ { { .Values.opencost.prometheus.thanos.external.url } }
115+ { {- else -} }
116+ { {- $host := .Values.opencost.prometheus.thanos.internal.serviceName } }
117+ { {- $ns := .Values.opencost.prometheus.thanos.internal.namespaceName } }
118+ { {- $port := .Values.opencost.prometheus.thanos.internal.port | int } }
119+ { {- printf " http://%s.%s.svc.cluster.local:%d" $host $ns $port -} }
120+ { {- end -} }
121+ { {- end -} }
122+
123+ { {/*
124+ Check that the config is valid
125+ */} }
126+ { {- define " isPrometheusConfigValid" -} }
127+ { {- $prometheusModes := add .Values.opencost.prometheus.external.enabled .Values.opencost.prometheus.internal.enabled .Values.opencost.prometheus.amp.enabled | int } }
128+ { {- if gt $prometheusModes 1 -} }
129+ { {- fail " Only use one of the prometheus setups: internal, external, or amp" -} }
130+ { {- end -} }
131+ { {- if .Values.opencost.prometheus.thanos.enabled -} }
132+ { {- if and .Values.opencost.prometheus.thanos.external.enabled .Values.opencost.prometheus.thanos.internal.enabled -} }
133+ { {- fail " Only use one of the thanos setups: internal or external" -} }
134+ { {- end -} }
135+ { {- end -} }
136+ { {- end -} }
137+
138+ { {/*
139+ Define opencost config file name
140+ */} }
141+ { {- define " opencost.configFileName" -} }
142+ { {- if eq .Values.opencost.customPricing.provider " custom" -} }
143+ { {- print " default" -} }
144+ { {- else -} }
145+ { {- .Values.opencost.customPricing.provider -} }
146+ { {- end -} }
147+ { {- end -} }
148+
149+ { {/*
150+ Get api version of networking.k8s.io
151+ */} }
152+ { {- define " networkingAPIVersion" -} }
153+ { {- if .Capabilities.APIVersions.Has " networking.k8s.io/v1" } }
154+ apiVersion: networking.k8s.io/v1
155+ { {- else if .Capabilities.APIVersions.Has " networking.k8s.io/v1beta1" } }
156+ apiVersion: networking.k8s.io/v1beta1
157+ { {- end } }
158+ { {- end -} }
159+
160+ { {- define " opencost.imageTag" -} }
161+ { { .Values.opencost.exporter.image.tag | default (printf " %s" .Chart.AppVersion) } }
162+ { {- end -} }
163+
164+ { {- define " opencost.fullImageName" -} }
165+ { {- if .Values.opencost.exporter.image.fullImageName } }
166+ { {- .Values.opencost.exporter.image.fullImageName -} }
167+ { {- else } }
168+ { {- .Values.opencost.exporter.image.registry -} }/{ {- .Values.opencost.exporter.image.repository -} }:{ {- include " opencost.imageTag" . -} }
169+ { {- end -} }
170+ { {- end -} }
171+
172+ { {- define " opencostUi.imageTag" -} }
173+ { {- .Values.opencost.ui.image.tag | default (printf " %s" .Chart.AppVersion) -} }
174+ { {- end -} }
175+
176+ { {- define " opencostUi.fullImageName" -} }
177+ { {- if .Values.opencost.ui.image.fullImageName } }
178+ { {- .Values.opencost.ui.image.fullImageName -} }
179+ { {- else } }
180+ { {- .Values.opencost.ui.image.registry -} }/{ {- .Values.opencost.ui.image.repository -} }:{ {- include " opencostUi.imageTag" . -} }
181+ { {- end -} }
182+ { {- end -} }
0 commit comments