Skip to content

Commit 06e79cd

Browse files
authored
Merge pull request #255 from aenix-io/opencost
Add opencost
2 parents 14a8a34 + e8eb5fd commit 06e79cd

26 files changed

Lines changed: 1854 additions & 0 deletions
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
apiVersion: v2
2+
name: cozy-opencost
3+
version: 0.0.0 # Placeholder, the actual version will be automatically set during the build process

‎packages/system/opencost/Makefile‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export NAME=opencost
2+
export NAMESPACE=cozy-$(NAME)
3+
4+
include ../../../scripts/package-system.mk
5+
6+
update:
7+
rm -rf charts
8+
helm repo add opencost-charts https://opencost.github.io/opencost-helm-chart
9+
helm repo update opencost-charts
10+
helm pull opencost-charts/opencost --untar --untardir charts
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: v2
2+
appVersion: 1.111.0
3+
description: OpenCost and OpenCost UI
4+
home: https://github.com/opencost/opencost-helm-chart
5+
keywords:
6+
- cloud-costs
7+
- cost-optimization
8+
- finops
9+
- monitoring
10+
- opencost
11+
maintainers:
12+
- name: mattray
13+
url: https://mattray.dev
14+
- name: toscott
15+
16+
name: brito-rafa
17+
name: opencost
18+
type: application
19+
version: 1.41.0

‎packages/system/opencost/charts/opencost/README.md‎

Lines changed: 213 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{{ template "chart.header" . }}
2+
3+
{{ template "chart.description" . }}
4+
5+
{{ template "chart.versionBadge" . }}
6+
{{ template "chart.typeBadge" . }}
7+
{{ template "chart.appVersionBadge" . }}
8+
[![Artifact Hub](https://img.shields.io/endpoint?url=https://artifacthub.io/badge/repository/opencost)](https://artifacthub.io/packages/search?repo=opencost)
9+
[![Artifact Hub](https://img.shields.io/endpoint?url=https://artifacthub.io/badge/repository/opencost-oci)](https://artifacthub.io/packages/search?repo=opencost-oci)
10+
11+
12+
{{ template "chart.maintainersSection" . }}
13+
14+
## Installing the Chart
15+
16+
To install the chart with the release name `opencost`:
17+
18+
```console
19+
$ helm install opencost opencost/{{ template "chart.name" . }}
20+
```
21+
22+
{{ template "chart.requirementsSection" . }}
23+
24+
{{ template "chart.valuesSection" . }}
25+
26+
{{ template "helm-docs.versionFooter" . }}
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
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 -}}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Cluster role giving opencost to get, list, watch required resources
2+
# No write permissions are required
3+
apiVersion: rbac.authorization.k8s.io/v1
4+
kind: ClusterRole
5+
metadata:
6+
name: {{ include "opencost.fullname" . }}
7+
labels: {{- include "opencost.labels" . | nindent 4 }}
8+
rules:
9+
- apiGroups: [""]
10+
resources:
11+
- configmaps
12+
- deployments
13+
- nodes
14+
- pods
15+
- services
16+
- resourcequotas
17+
- replicationcontrollers
18+
- limitranges
19+
- persistentvolumeclaims
20+
- persistentvolumes
21+
- namespaces
22+
- endpoints
23+
verbs:
24+
- get
25+
- list
26+
- watch
27+
- apiGroups:
28+
- extensions
29+
resources:
30+
- daemonsets
31+
- deployments
32+
- replicasets
33+
verbs:
34+
- get
35+
- list
36+
- watch
37+
- apiGroups:
38+
- apps
39+
resources:
40+
- statefulsets
41+
- deployments
42+
- daemonsets
43+
- replicasets
44+
verbs:
45+
- list
46+
- watch
47+
- apiGroups:
48+
- batch
49+
resources:
50+
- cronjobs
51+
- jobs
52+
verbs:
53+
- get
54+
- list
55+
- watch
56+
- apiGroups:
57+
- autoscaling
58+
resources:
59+
- horizontalpodautoscalers
60+
verbs:
61+
- get
62+
- list
63+
- watch
64+
- apiGroups:
65+
- policy
66+
resources:
67+
- poddisruptionbudgets
68+
verbs:
69+
- get
70+
- list
71+
- watch
72+
- apiGroups:
73+
- storage.k8s.io
74+
resources:
75+
- storageclasses
76+
verbs:
77+
- get
78+
- list
79+
- watch
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{{- if .Values.rbac.enabled }}
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
kind: ClusterRoleBinding
4+
metadata:
5+
name: {{ include "opencost.fullname" . }}
6+
labels: {{- include "opencost.labels" . | nindent 4 }}
7+
{{- with .Values.annotations }}
8+
annotations: {{- toYaml . | nindent 4 }}
9+
{{- end }}
10+
roleRef:
11+
apiGroup: rbac.authorization.k8s.io
12+
kind: ClusterRole
13+
name: {{ include "opencost.fullname" . }}
14+
subjects:
15+
- kind: ServiceAccount
16+
name: {{ template "opencost.serviceAccountName" . }}
17+
namespace: {{ include "opencost.namespace" . }}
18+
{{- end }}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{{- if and .Values.opencost.customPricing.createConfigmap .Values.opencost.customPricing.enabled }}
2+
apiVersion: v1
3+
kind: ConfigMap
4+
metadata:
5+
name: {{ .Values.opencost.customPricing.configmapName }}
6+
namespace: {{ include "opencost.namespace" . }}
7+
data:
8+
{{ include "opencost.configFileName" . }}.json: |-
9+
{
10+
{{- range $key, $val := .Values.opencost.customPricing.costModel }}
11+
{{ $key | quote | indent 6}}: {{ $val | quote }},
12+
{{- end}}
13+
"provider" : {{ .Values.opencost.customPricing.provider | quote }}
14+
}
15+
{{- end }}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{{- if .Values.opencost.metrics.config.enabled }}
2+
apiVersion: v1
3+
kind: ConfigMap
4+
metadata:
5+
name: {{ .Values.opencost.metrics.config.configmapName }}
6+
namespace: {{ include "opencost.namespace" . }}
7+
labels: {{- include "opencost.labels" . | nindent 4 }}
8+
data:
9+
metrics.json: |-
10+
{"disabledMetrics": {{ toJson .Values.opencost.metrics.config.disabledMetrics }} }
11+
{{- end }}

0 commit comments

Comments
 (0)