From c5f41f00678abcbf89d52b58aab4123f6470151c Mon Sep 17 00:00:00 2001 From: Houssem Date: Sun, 24 Sep 2023 18:28:17 +0200 Subject: [PATCH] adding support to custom pricing configuration in helm chart (#109) * #108: adding support to custom pricing configuration in helm chart * adding support for custom pricing configuration and bumping version * #108: update chart version and adding EOF to configmap yaml file * #108: update README file * updates the OpenCost Helm chart to include custom pricing options for on-premise setups. Closes #108 * #108: renaming configmap and resolving trailing comma issue * #108: updating docs --------- Co-authored-by: Houssem Charfeddine --- charts/opencost/Chart.yaml | 2 +- charts/opencost/README.md | 30 ++++++++++++++----- .../templates/configmap-custom-pricing.yaml | 14 +++++++++ charts/opencost/templates/deployment.yaml | 19 ++++++++++-- charts/opencost/values.yaml | 21 +++++++++++++ 5 files changed, 76 insertions(+), 10 deletions(-) create mode 100644 charts/opencost/templates/configmap-custom-pricing.yaml diff --git a/charts/opencost/Chart.yaml b/charts/opencost/Chart.yaml index b187290..9514536 100755 --- a/charts/opencost/Chart.yaml +++ b/charts/opencost/Chart.yaml @@ -9,7 +9,7 @@ keywords: - kubecost - opencost - monitoring -version: 1.19.3 +version: 1.19.4 maintainers: - name: mattray url: https://mattray.dev diff --git a/charts/opencost/README.md b/charts/opencost/README.md index 763507a..92824e1 100644 --- a/charts/opencost/README.md +++ b/charts/opencost/README.md @@ -2,16 +2,16 @@ OpenCost and OpenCost UI -![Version: 1.19.3](https://img.shields.io/badge/Version-1.19.3-informational?style=flat-square) +![Version: 1.19.4](https://img.shields.io/badge/Version-1.19.4-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 1.105.2](https://img.shields.io/badge/AppVersion-1.105.2-informational?style=flat-square) ## Maintainers -| Name | Url | -| ---- | --- | -| mattray | | -| toscott | | +| Name | Email | Url | +| ---- | ------ | --- | +| mattray | | | +| toscott | | | ## Installing the Chart @@ -28,13 +28,20 @@ $ helm install opencost opencost/opencost | annotations | object | `{}` | Annotations to add to the all the resources | | extraVolumes | list | `[]` | A list of volumes to be added to the pod | | fullnameOverride | string | `""` | Overwrite all resources name created by the chart | +| imagePullSecrets | list | `[]` | List of secret names to use for pulling the images | | nameOverride | string | `""` | Overwrite the default name of the chart | | opencost.affinity | object | `{}` | Affinity settings for pod assignment | +| opencost.customPricing.configPath | string | `"/tmp/custom-config"` | Path for the pricing configuration. | +| opencost.customPricing.configmapName | string | `"custom-pricing-model"` | | +| opencost.customPricing.costModel | object | `{"CPU":1.25,"GPU":0.95,"RAM":0.5,"description":"Modified prices based on your internal pricing","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 | +| opencost.customPricing.createConfigmap | bool | `true` | Configures the pricing model provided in the values file. | +| opencost.customPricing.enabled | bool | `false` | Enables custom pricing for on-premise setup. | | opencost.exporter.aws.access_key_id | string | `""` | AWS secret key id | | opencost.exporter.aws.secret_access_key | string | `""` | AWS secret access key | | opencost.exporter.cloudProviderApiKey | string | `""` | The GCP Pricing API requires a key. This is supplied just for evaluation. | | opencost.exporter.csv_path | string | `""` | | | opencost.exporter.defaultClusterId | string | `"default-cluster"` | Default cluster ID to use if cluster_id is not set in Prometheus metrics. | +| opencost.exporter.env | list | `[]` | List of additional environment variables to set in the container | | opencost.exporter.extraEnv | object | `{}` | Any extra environment variables you would like to pass on to the pod | | opencost.exporter.extraVolumeMounts | list | `[]` | A list of volume mounts to be added to the pod | | opencost.exporter.image.pullPolicy | string | `"IfNotPresent"` | Exporter container image pull policy | @@ -43,7 +50,7 @@ $ helm install opencost opencost/opencost | opencost.exporter.image.tag | string | `""` (use appVersion in Chart.yaml) | Exporter container image tag | | opencost.exporter.livenessProbe.enabled | bool | `true` | Whether probe is enabled | | opencost.exporter.livenessProbe.failureThreshold | int | `3` | Number of failures for probe to be considered failed | -| opencost.exporter.livenessProbe.initialDelaySeconds | int | `30` | Number of seconds before probe is initiated | +| opencost.exporter.livenessProbe.initialDelaySeconds | int | `120` | Number of seconds before probe is initiated | | opencost.exporter.livenessProbe.periodSeconds | int | `10` | Probe frequency in seconds | | opencost.exporter.persistence.accessMode | string | `""` | Access mode for persistent volume | | opencost.exporter.persistence.annotations | object | `{}` | Annotations for persistent volume | @@ -52,7 +59,7 @@ $ helm install opencost opencost/opencost | opencost.exporter.persistence.storageClass | string | `""` | Storage class for persistent volume | | opencost.exporter.readinessProbe.enabled | bool | `true` | Whether probe is enabled | | opencost.exporter.readinessProbe.failureThreshold | int | `3` | Number of failures for probe to be considered failed | -| opencost.exporter.readinessProbe.initialDelaySeconds | int | `30` | Number of seconds before probe is initiated | +| opencost.exporter.readinessProbe.initialDelaySeconds | int | `120` | Number of seconds before probe is initiated | | opencost.exporter.readinessProbe.periodSeconds | int | `10` | Probe frequency in seconds | | opencost.exporter.replicas | int | `1` | Number of OpenCost replicas to run | | opencost.exporter.resources.limits | object | `{"cpu":"999m","memory":"1Gi"}` | CPU/Memory resource limits | @@ -77,6 +84,15 @@ $ helm install opencost opencost/opencost | opencost.prometheus.password | string | `""` | Prometheus Basic auth password | | opencost.prometheus.password_key | string | `"DB_BASIC_AUTH_PW"` | Key in the secret that references the password | | opencost.prometheus.secret_name | string | `nil` | Secret name that contains credentials for Prometheus | +| opencost.prometheus.thanos.enabled | bool | `false` | | +| opencost.prometheus.thanos.external.enabled | bool | `false` | | +| opencost.prometheus.thanos.external.url | string | `"https://thanos-query.example.com/thanos"` | | +| opencost.prometheus.thanos.internal.enabled | bool | `true` | | +| opencost.prometheus.thanos.internal.namespaceName | string | `"opencost"` | | +| opencost.prometheus.thanos.internal.port | int | `10901` | | +| opencost.prometheus.thanos.internal.serviceName | string | `"my-thanos-query"` | | +| opencost.prometheus.thanos.maxSourceResolution | string | `""` | | +| opencost.prometheus.thanos.queryOffset | string | `""` | | | opencost.prometheus.username | string | `""` | Prometheus Basic auth username | | opencost.prometheus.username_key | string | `"DB_BASIC_AUTH_USERNAME"` | Key in the secret that references the username | | opencost.tolerations | list | `[]` | Toleration labels for pod assignment | diff --git a/charts/opencost/templates/configmap-custom-pricing.yaml b/charts/opencost/templates/configmap-custom-pricing.yaml new file mode 100644 index 0000000..a405c9f --- /dev/null +++ b/charts/opencost/templates/configmap-custom-pricing.yaml @@ -0,0 +1,14 @@ +{{- if and .Values.opencost.customPricing.createConfigmap .Values.opencost.customPricing.enabled }} +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ .Values.opencost.customPricing.configmapName }} +data: + default.json: |- + { +{{- range $key, $val := .Values.opencost.customPricing.costModel }} +{{ $key | quote | indent 6}}: {{ $val | quote }}, +{{- end}} + "provider" : "custom" + } +{{- end }} diff --git a/charts/opencost/templates/deployment.yaml b/charts/opencost/templates/deployment.yaml index 005b02e..807bce3 100644 --- a/charts/opencost/templates/deployment.yaml +++ b/charts/opencost/templates/deployment.yaml @@ -143,17 +143,27 @@ spec: {{- with .Values.opencost.exporter.env }} {{- toYaml . | nindent 12 }} {{- end }} + {{- if .Values.opencost.customPricing.enabled }} + - name: CONFIG_PATH + value: {{ .Values.opencost.customPricing.configPath | quote }} + {{- end }} + # Add any additional provided variables {{- range $key, $value := .Values.opencost.exporter.extraEnv }} - name: {{ $key }} value: {{ $value | quote }} {{- end }} - {{- if or .Values.opencost.exporter.persistence.enabled .Values.opencost.exporter.extraVolumeMounts }} + {{- if or .Values.opencost.exporter.persistence.enabled .Values.opencost.exporter.extraVolumeMounts .Values.opencost.customPricing.enabled}} volumeMounts: {{- if .Values.opencost.exporter.persistence.enabled }} - mountPath: /mnt/export name: opencost-export readOnly: false {{- end }} + {{- if .Values.opencost.customPricing.enabled }} + - mountPath: {{ .Values.opencost.customPricing.configPath }} + name: custom-configs + readOnly: true + {{- end }} {{- with .Values.opencost.exporter.extraVolumeMounts }} {{- toYaml . | nindent 12 }} {{- end }} @@ -191,8 +201,13 @@ spec: volumeMounts: {{- toYaml . | nindent 12 }} {{- end }} {{- end }} - {{- if or .Values.opencost.exporter.persistence.enabled .Values.extraVolumes }} + {{- if or .Values.opencost.exporter.persistence.enabled .Values.extraVolumes .Values.opencost.customPricing.enabled}} volumes: + {{- if .Values.opencost.customPricing.enabled }} + - name: custom-configs + configMap: + name: {{ .Values.opencost.customPricing.configmapName }} + {{- end }} {{- if .Values.opencost.exporter.persistence.enabled }} - name: opencost-export persistentVolumeClaim: diff --git a/charts/opencost/values.yaml b/charts/opencost/values.yaml index 7da5083..3266fb0 100644 --- a/charts/opencost/values.yaml +++ b/charts/opencost/values.yaml @@ -129,6 +129,27 @@ opencost: # -- Any extra environment variables you would like to pass on to the pod extraEnv: {} # FOO: BAR + customPricing: + # -- Enables custom pricing for on-premise setup. + enabled: false + configmapName: custom-pricing-model + # -- Path for the pricing configuration. + configPath: /tmp/custom-config + # -- Configures the pricing model provided in the values file. + createConfigmap: true + # -- More information about these values here: https://www.opencost.io/docs/configuration/on-prem#custom-pricing-using-the-opencost-helm-chart + costModel: + description: Modified prices based on your internal pricing + CPU: 1.25 + spotCPU: 0.006655 + RAM: 0.50 + spotRAM: 0.000892 + GPU: 0.95 + storage: 0.25 + zoneNetworkEgress: 0.01 + regionNetworkEgress: 0.01 + internetNetworkEgress: 0.12 + metrics: serviceMonitor: