Skip to content

Commit 982e3cc

Browse files
authored
Merge pull request #337 from opencost/cloud-integration-json
Add cloudIntegrationJSON support
2 parents 01c308d + 930c94d commit 982e3cc

File tree

7 files changed

+177
-12
lines changed

7 files changed

+177
-12
lines changed

charts/opencost/Chart.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ name: opencost
44
description: OpenCost and OpenCost UI
55
type: application
66
keywords:
7-
- cloud-costs
8-
- cost-optimization
9-
- finops
10-
- monitoring
11-
- opencost
12-
version: 2.5.9
7+
- cloud-costs
8+
- cost-optimization
9+
- finops
10+
- monitoring
11+
- opencost
12+
version: 2.5.10
1313
maintainers:
1414
- name: jessegoodier
1515
- name: toscott

charts/opencost/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ $ helm install opencost opencost/opencost
5050
| opencost.cloudCost.queryWindowDays | int | `7` | The max number of days that any single query will be made to construct Cloud Costs |
5151
| opencost.cloudCost.refreshRateHours | int | `6` | Number of hours between each run of the Cloud Cost pipeline |
5252
| opencost.cloudCost.runWindowDays | int | `3` | Number of days into the past that a Cloud Cost standard run will query for |
53-
| opencost.cloudIntegrationSecret | string | `""` | |
53+
| opencost.cloudIntegrationSecret | string | `""` | Existing secret name containing `cloud-integration.json` for Cloud Costs. Mutually exclusive with `opencost.cloudIntegrationJSON`. |
54+
| opencost.cloudIntegrationJSON | string | `""` | Raw JSON string for `cloud-integration.json`. Creates `<fullname>-cloud-integration` in the release namespace. Mutually exclusive with `opencost.cloudIntegrationSecret`. |
5455
| opencost.customPricing.configPath | string | `"/tmp/custom-config"` | Path for the pricing configuration. |
5556
| opencost.customPricing.configmapName | string | `"custom-pricing-model"` | Customize the configmap name used for custom pricing |
5657
| opencost.customPricing.costModel | object | `{"CPU":1.25,"GPU":0.95,"RAM":0.5,"description":"Modified pricing configuration.","internetNetworkEgress":0.12,"regionNetworkEgress":0.01,"spotCPU":0.006655,"spotRAM":0.000892,"storage":0.25,"zoneNetworkEgress":0.01}` | More information about these values here: https://www.opencost.io/docs/configuration/on-prem#custom-pricing-using-the-opencost-helm-chart |

charts/opencost/templates/_helpers.tpl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,28 @@ We truncate at 63 chars because some Kubernetes name fields are limited to this
5353
{{- end -}}
5454
{{- end -}}
5555

56+
{{/*
57+
Cloud integration source contents check. Either the Secret must be specified or the JSON, not both.
58+
*/}}
59+
{{- define "opencost.cloudIntegration.secretConfigCheck" -}}
60+
{{- if and .Values.opencost.cloudIntegrationSecret .Values.opencost.cloudIntegrationJSON -}}
61+
{{- fail "opencost.cloudIntegrationSecret and opencost.cloudIntegrationJSON are mutually exclusive. Please specify only one." -}}
62+
{{- end -}}
63+
{{- end -}}
64+
65+
{{/*
66+
Compute the cloud integration secret name when enabled.
67+
*/}}
68+
{{- define "opencost.cloudIntegration.secretName" -}}
69+
{{- if or .Values.opencost.cloudIntegrationSecret .Values.opencost.cloudIntegrationJSON -}}
70+
{{- if .Values.opencost.cloudIntegrationSecret -}}
71+
{{- .Values.opencost.cloudIntegrationSecret -}}
72+
{{- else -}}
73+
{{- printf "%s-cloud-integration" (include "opencost.fullname" .) -}}
74+
{{- end -}}
75+
{{- end -}}
76+
{{- end -}}
77+
5678
{{/*
5779
Common labels
5880
*/}}
@@ -212,6 +234,7 @@ apiVersion: networking.k8s.io/v1beta1
212234
"configmap-custom-pricing.yaml"
213235
"configmap-frontend.yaml"
214236
"configmap-metrics-config.yaml"
237+
"secret-cloud-integration.yaml"
215238
"secret.yaml"
216239
-}}
217240
{{- $checksum := "" -}}

charts/opencost/templates/deployment.yaml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{{- include "isPrometheusConfigValid" . }}
22
{{- include "kubeRBACProxyBearerTokenCheck" . }}
33
{{ include "opencost.caCertsSecretConfig.check" . }}
4+
{{ include "opencost.cloudIntegration.secretConfigCheck" . }}
5+
{{- $cloudIntegrationSecretName := include "opencost.cloudIntegration.secretName" . -}}
46
apiVersion: apps/v1
57
kind: Deployment
68
metadata:
@@ -331,7 +333,7 @@ spec:
331333
- name: MCP_SERVER_ENABLED
332334
value: "false"
333335
{{- end }}
334-
{{- if or .Values.plugins.enabled .Values.opencost.exporter.persistence.enabled .Values.opencost.exporter.extraVolumeMounts .Values.opencost.customPricing.enabled .Values.opencost.cloudIntegrationSecret .Values.opencost.updateCaTrust.enabled}}
336+
{{- if or .Values.plugins.enabled .Values.opencost.exporter.persistence.enabled .Values.opencost.exporter.extraVolumeMounts .Values.opencost.customPricing.enabled .Values.opencost.metrics.config.enabled $cloudIntegrationSecretName .Values.opencost.updateCaTrust.enabled}}
335337
volumeMounts:
336338
{{- if .Values.plugins.enabled }}
337339
- mountPath: /opt/opencost/plugin
@@ -353,7 +355,7 @@ spec:
353355
- mountPath: {{ .Values.opencost.customPricing.configPath }}
354356
name: custom-configs
355357
{{- end }}
356-
{{- if .Values.opencost.cloudIntegrationSecret }}
358+
{{- if $cloudIntegrationSecretName }}
357359
- name: cloud-integration
358360
mountPath: /var/configs/cloud-integration.json
359361
subPath: cloud-integration.json
@@ -463,7 +465,7 @@ spec:
463465
{{- toYaml . | nindent 12 }}
464466
{{- end }}
465467
{{- end }}
466-
{{- if or .Values.plugins.enabled .Values.opencost.exporter.persistence.enabled .Values.extraVolumes .Values.opencost.customPricing.enabled .Values.opencost.cloudIntegrationSecret .Values.opencost.ui.enabled .Values.opencost.updateCaTrust.enabled }}
468+
{{- if or .Values.plugins.enabled .Values.opencost.exporter.persistence.enabled .Values.extraVolumes .Values.opencost.customPricing.enabled .Values.opencost.metrics.config.enabled $cloudIntegrationSecretName .Values.opencost.ui.enabled .Values.opencost.updateCaTrust.enabled }}
467469
volumes:
468470
{{- if .Values.plugins.enabled }}
469471
{{- if .Values.plugins.install.enabled}}
@@ -486,10 +488,10 @@ spec:
486488
persistentVolumeClaim:
487489
claimName: {{ include "opencost.fullname" . }}-pvc
488490
{{- end }}
489-
{{- if .Values.opencost.cloudIntegrationSecret }}
491+
{{- if $cloudIntegrationSecretName }}
490492
- name: cloud-integration
491493
secret:
492-
secretName: {{ .Values.opencost.cloudIntegrationSecret }}
494+
secretName: {{ $cloudIntegrationSecretName }}
493495
items:
494496
- key: cloud-integration.json
495497
path: cloud-integration.json
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{{- if .Values.opencost.cloudIntegrationJSON }}
2+
apiVersion: v1
3+
kind: Secret
4+
type: Opaque
5+
metadata:
6+
name: {{ include "opencost.cloudIntegration.secretName" . }}
7+
namespace: {{ include "opencost.namespace" . }}
8+
labels:
9+
{{- include "opencost.labels" . | nindent 4 }}
10+
data:
11+
cloud-integration.json: {{ .Values.opencost.cloudIntegrationJSON | trimSuffix "\n" | b64enc | quote }}
12+
{{- end }}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
suite: cloud integration deployment
2+
templates:
3+
- templates/deployment.yaml
4+
release:
5+
name: opencost
6+
namespace: default
7+
tests:
8+
- it: should mount existing cloud integration secret
9+
set:
10+
opencost.cloudIntegrationSecret: cloud-costs
11+
asserts:
12+
- contains:
13+
path: spec.template.spec.volumes
14+
content:
15+
name: cloud-integration
16+
secret:
17+
secretName: cloud-costs
18+
items:
19+
- key: cloud-integration.json
20+
path: cloud-integration.json
21+
- contains:
22+
path: spec.template.spec.containers[0].volumeMounts
23+
content:
24+
name: cloud-integration
25+
mountPath: /var/configs/cloud-integration.json
26+
subPath: cloud-integration.json
27+
readOnly: true
28+
- it: should mount generated cloud integration secret
29+
set:
30+
opencost.cloudIntegrationJSON: '{"aws":[]}'
31+
asserts:
32+
- contains:
33+
path: spec.template.spec.volumes
34+
content:
35+
name: cloud-integration
36+
secret:
37+
secretName: opencost-cloud-integration
38+
items:
39+
- key: cloud-integration.json
40+
path: cloud-integration.json
41+
- contains:
42+
path: spec.template.spec.containers[0].volumeMounts
43+
content:
44+
name: cloud-integration
45+
mountPath: /var/configs/cloud-integration.json
46+
subPath: cloud-integration.json
47+
readOnly: true
48+
---
49+
suite: cloud integration secret
50+
templates:
51+
- templates/secret-cloud-integration.yaml
52+
release:
53+
name: opencost
54+
namespace: default
55+
tests:
56+
- it: should render secret when cloudIntegrationJSON is set
57+
set:
58+
opencost.cloudIntegrationJSON: '{"aws":[]}'
59+
asserts:
60+
- isKind:
61+
of: Secret
62+
- equal:
63+
path: metadata.name
64+
value: opencost-cloud-integration
65+
- equal:
66+
path: data.cloud-integration.json
67+
value: eyJhd3MiOltdfQ==
68+
---
69+
suite: cloud integration validation
70+
templates:
71+
- templates/deployment.yaml
72+
release:
73+
name: opencost
74+
namespace: default
75+
tests:
76+
- it: should fail when cloudIntegrationSecret and cloudIntegrationJSON are set
77+
set:
78+
opencost.cloudIntegrationSecret: cloud-costs
79+
opencost.cloudIntegrationJSON: '{"aws":[]}'
80+
asserts:
81+
- failedTemplate:
82+
errorMessage: opencost.cloudIntegrationSecret and opencost.cloudIntegrationJSON are mutually exclusive. Please specify only one.

charts/opencost/values.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,52 @@ pdb:
127127
opencost:
128128
# -- <SECRET_NAME> for the secret containing the Cloud Costs cloud-integration.json https://www.opencost.io/docs/configuration/#cloud-costs
129129
# -- kubectl create secret generic <SECRET_NAME> --from-file=cloud-integration.json -n opencost
130+
# -- Mutually exclusive with opencost.cloudIntegrationJSON.
130131
cloudIntegrationSecret: ""
132+
# -- Specify the cloud integration information in JSON form. This will create a Secret named
133+
# -- "<fullname>-cloud-integration" in the release namespace. Mutually exclusive with
134+
# -- opencost.cloudIntegrationSecret.
135+
cloudIntegrationJSON: ""
136+
# cloudIntegrationJSON: |-
137+
# {
138+
# "aws": [
139+
# {
140+
# "athenaBucketName": "s3://AWS_cloud_integration_athenaBucketName",
141+
# "athenaRegion": "AWS_cloud_integration_athenaRegion",
142+
# "athenaDatabase": "AWS_cloud_integration_athenaDatabase",
143+
# "athenaTable": "AWS_cloud_integration_athenaTable",
144+
# "projectID": "AWS_cloud_integration_athena_projectID",
145+
# "serviceKeyName": "AWS_cloud_integration_athena_serviceKeyName",
146+
# "serviceKeySecret": "AWS_cloud_integration_athena_serviceKeySecret"
147+
# }
148+
# ],
149+
# "azure": [
150+
# {
151+
# "azureSubscriptionID": "my-subscription-id",
152+
# "azureStorageAccount": "my-storage-account",
153+
# "azureStorageAccessKey": "my-storage-access-key",
154+
# "azureStorageContainer": "my-storage-container"
155+
# }
156+
# ],
157+
# "gcp": [
158+
# {
159+
# "projectID": "my-project-id",
160+
# "billingDataDataset": "detailedbilling.my-billing-dataset",
161+
# "key": {
162+
# "type": "service_account",
163+
# "project_id": "my-project-id",
164+
# "private_key_id": "my-private-key-id",
165+
# "private_key": "my-pem-encoded-private-key",
166+
# "client_email": "my-service-account-name@my-project-id.iam.gserviceaccount.com",
167+
# "client_id": "my-client-id",
168+
# "auth_uri": "auth-uri",
169+
# "token_uri": "token-uri",
170+
# "auth_provider_x509_cert_url": "my-x509-provider-cert",
171+
# "client_x509_cert_url": "my-x509-cert-url"
172+
# }
173+
# }
174+
# ]
175+
# }
131176

132177
# -- MCP (Model Context Protocol) Server Configuration
133178
# The MCP server provides AI agents with access to cost allocation and asset data

0 commit comments

Comments
 (0)