Skip to content

Commit fbee83d

Browse files
authored
Merge pull request #339 from opencost/atm/admin-token
add admin token infra support
2 parents 982e3cc + 6f3d73b commit fbee83d

File tree

6 files changed

+38
-1
lines changed

6 files changed

+38
-1
lines changed

charts/opencost/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ keywords:
99
- finops
1010
- monitoring
1111
- opencost
12-
version: 2.5.10
12+
version: 2.5.11
1313
maintainers:
1414
- name: jessegoodier
1515
- name: toscott

charts/opencost/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ $ helm install opencost opencost/opencost
8787
| opencost.exporter.env | list | `[]` | List of additional environment variables to set in the container |
8888
| opencost.exporter.extraArgs | list | `[]` | List of extra arguments for the command, e.g.: log-format=json |
8989
| opencost.exporter.extraEnv | object | `{}` | Any extra environment variables you would like to pass on to the pod |
90+
| opencost.exporter.adminToken.enabled | bool | `false` | When true, set ADMIN_TOKEN from value or existingSecret; when false, ADMIN_TOKEN is not set and no admin-token Secret is deployed. |
91+
| opencost.exporter.adminToken.value | string | `""` | If set, the chart creates a Secret with this value and sets ADMIN_TOKEN from it (use existingSecret in production). |
92+
| opencost.exporter.adminToken.existingSecret | string | `""` | Use an existing Secret for the admin token; must contain the key in adminToken.secretKey. |
93+
| opencost.exporter.adminToken.secretKey | string | `"ADMIN_TOKEN"` | Key in the Secret that holds the admin token (for write operations: POST /serviceKey, cloud config endpoints). |
9094
| opencost.exporter.extraVolumeMounts | list | `[]` | A list of volume mounts to be added to the pod |
9195
| opencost.exporter.image | object | `{"fullImageName":null,"pullPolicy":"IfNotPresent","registry":"ghcr.io","repository":"opencost/opencost","tag":"1.118.0@sha256:c1a08767fe3c3b2964a75885c145bae0cba32225c0b4c1e0382a77566aef93e9"}` | This overrides the above defaultClusterId. Ensure the ConfigMap exists and contains the required CLUSTER_ID key. clusterIdConfigmap: cluster-id-configmap |
9296
| opencost.exporter.image.fullImageName | string | `nil` | Override the full image name for development purposes |

charts/opencost/templates/_helpers.tpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ apiVersion: networking.k8s.io/v1beta1
236236
"configmap-metrics-config.yaml"
237237
"secret-cloud-integration.yaml"
238238
"secret.yaml"
239+
"secret-admin-token.yaml"
239240
-}}
240241
{{- $checksum := "" -}}
241242
{{- range $files -}}

charts/opencost/templates/deployment.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,13 @@ spec:
323323
- name: {{ $key }}
324324
value: {{ $value | quote }}
325325
{{- end }}
326+
{{- if and .Values.opencost.exporter.adminToken.enabled (or .Values.opencost.exporter.adminToken.value .Values.opencost.exporter.adminToken.existingSecret) }}
327+
- name: ADMIN_TOKEN
328+
valueFrom:
329+
secretKeyRef:
330+
name: {{ .Values.opencost.exporter.adminToken.existingSecret | default (printf "%s-admin-token" (include "opencost.fullname" .)) }}
331+
key: {{ .Values.opencost.exporter.adminToken.secretKey | default "ADMIN_TOKEN" }}
332+
{{- end }}
326333
{{- if .Values.opencost.mcp.enabled }}
327334
# MCP Server Configuration
328335
- name: MCP_SERVER_ENABLED
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{{- if and .Values.opencost.exporter.adminToken.enabled .Values.opencost.exporter.adminToken.value (not .Values.opencost.exporter.adminToken.existingSecret) }}
2+
apiVersion: v1
3+
kind: Secret
4+
metadata:
5+
name: {{ include "opencost.fullname" . }}-admin-token
6+
namespace: {{ include "opencost.namespace" . }}
7+
labels: {{- include "opencost.labels" . | nindent 4 }}
8+
{{- with .Values.secretAnnotations }}
9+
annotations: {{- toYaml . | nindent 4 }}
10+
{{- end }}
11+
type: Opaque
12+
data:
13+
{{ .Values.opencost.exporter.adminToken.secretKey | default "ADMIN_TOKEN" }}: {{ .Values.opencost.exporter.adminToken.value | toString | b64enc | quote }}
14+
{{- end }}

charts/opencost/values.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,17 @@ opencost:
363363
# FOO: BAR
364364
# For example, if accessing mimir directly and getting 401 Unauthorized
365365
# PROMETHEUS_HEADER_X_SCOPE_ORGID: anonymous
366+
# Admin token for write operations (e.g. POST /serviceKey, cloud config endpoints).
367+
# Set ADMIN_TOKEN env from a chart-created secret or an existing secret.
368+
adminToken:
369+
# -- When true, the chart creates the admin-token Secret (if value is set) or mounts existingSecret as ADMIN_TOKEN. When false, ADMIN_TOKEN is not set and no secret is deployed.
370+
enabled: false
371+
# -- If set, the chart creates a Secret with this value and sets ADMIN_TOKEN from it (not recommended for production; use existingSecret instead).
372+
value: ""
373+
# -- Use an existing Secret for the admin token (recommended). Secret must contain the key below.
374+
existingSecret: ""
375+
# -- Key in the Secret that holds the admin token (used for both value-created and existing secrets).
376+
secretKey: "ADMIN_TOKEN"
366377
apiIngress:
367378
# -- Ingress for OpenCost API
368379
enabled: false

0 commit comments

Comments
 (0)