Skip to content

Commit

Permalink
implement plugin support in helm chart (#180)
Browse files Browse the repository at this point in the history
* implement plugin support in helm chart

Signed-off-by: Alex Meijer <[email protected]>

* added missing files

Signed-off-by: Alex Meijer <[email protected]>

* bump chart ver

* fix CI

* code review fixes

* code review fixes

* debugged

---------

Signed-off-by: Alex Meijer <[email protected]>
  • Loading branch information
ameijer authored Mar 8, 2024
1 parent aacbdeb commit a2b2992
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 3 deletions.
2 changes: 1 addition & 1 deletion charts/opencost/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ keywords:
- finops
- monitoring
- opencost
version: 1.30.0
version: 1.31.0
maintainers:
- name: mattray
- name: toscott
Expand Down
45 changes: 43 additions & 2 deletions charts/opencost/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,20 @@ spec:
{{- with.Values.opencost.topologySpreadConstraints }}
topologySpreadConstraints: {{- toYaml . | nindent 8 }}
{{- end }}
{{- if (and .Values.plugins.enabled .Values.plugins.install.enabled )}}
initContainers:
- name: plugin-installer
image: {{ .Values.plugins.install.fullImageName }}
command: ["sh", "/install/install_plugins.sh"]
{{- with .Values.plugins.install.securityContext }}
securityContext: {{- toYaml . | nindent 12 }}
{{- end }}
volumeMounts:
- name: install-script
mountPath: /install
- name: plugins-dir
mountPath: {{ .Values.plugins.folder }}
{{- end }}
containers:
- name: {{ include "opencost.fullname" . }}
{{- if .Values.opencost.exporter.image.fullImageName }}
Expand Down Expand Up @@ -93,6 +107,10 @@ spec:
securityContext: {{- toYaml . | nindent 12 }}
{{- end }}
env:
- name: LOG_LEVEL
value: {{ .Values.loglevel }}
- name: CUSTOM_COST_ENABLED
value: {{ .Values.plugins.enabled | quote }}
{{- if .Values.opencost.exporter.apiPort }}
- name: API_PORT
value: {{ .Values.opencost.exporter.apiPort | quote }}
Expand Down Expand Up @@ -185,8 +203,19 @@ spec:
- name: {{ $key }}
value: {{ $value | quote }}
{{- end }}
{{- if or .Values.opencost.exporter.persistence.enabled .Values.opencost.exporter.extraVolumeMounts .Values.opencost.customPricing.enabled .Values.opencost.cloudIntegrationSecret}}
{{- if or .Values.plugins.enabled .Values.opencost.exporter.persistence.enabled .Values.opencost.exporter.extraVolumeMounts .Values.opencost.customPricing.enabled .Values.opencost.cloudIntegrationSecret}}
volumeMounts:
{{- if .Values.plugins.enabled }}
- mountPath: /opt/opencost/plugin
name: plugins-dir
readOnly: false
{{- range $key, $config := .Values.plugins.configs }}
- mountPath: /opt/opencost/plugin/config/{{$key}}_config.json
subPath: {{$key}}_config.json
name: plugins-config
readOnly: true
{{- end }}
{{- end }}
{{- if .Values.opencost.exporter.persistence.enabled }}
- mountPath: /mnt/export
name: opencost-export
Expand Down Expand Up @@ -294,8 +323,20 @@ spec:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- end }}
{{- if or .Values.opencost.exporter.persistence.enabled .Values.extraVolumes .Values.opencost.customPricing.enabled .Values.opencost.cloudIntegrationSecret}}
{{- if or .Values.plugins.enabled .Values.opencost.exporter.persistence.enabled .Values.extraVolumes .Values.opencost.customPricing.enabled .Values.opencost.cloudIntegrationSecret}}
volumes:
{{- if .Values.plugins.enabled }}
{{- if .Values.plugins.install.enabled}}
- name: install-script
configMap:
name: {{ template "opencost.fullname" . }}-install-plugins
{{- end }}
- name: plugins-dir
emptyDir: {}
- name: plugins-config
secret:
secretName: {{ template "opencost.fullname" . }}-plugins-config
{{- end }}
{{- if .Values.opencost.customPricing.enabled }}
- name: custom-configs
configMap:
Expand Down
46 changes: 46 additions & 0 deletions charts/opencost/templates/install-plugins.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{{- if .Values.plugins.enabled }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "opencost.fullname" . }}-install-plugins
labels:
app: {{ template "opencost.name" . }}
chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
data:
install_plugins.sh: |-
{{- if .Values.plugins.install.enabled }}
set -ex
rm -f {{ .Values.plugins.folder }}/bin/*
mkdir -p {{ .Values.plugins.folder }}/bin
cd {{ .Values.plugins.folder }}/bin
OSTYPE=$(cat /etc/os-release)
OS=''
case "$OSTYPE" in
*Linux*) OS='linux';;
*) echo "$OSTYPE is unsupported" && exit 1 ;;
esac
UNAME_OUTPUT=$(uname -m)
ARCH=''
case "$UNAME_OUTPUT" in
*x86_64*) ARCH='amd64';;
*amd64*) ARCH='amd64';;
*aarch64*) ARCH='arm64';;
*arm64*) ARCH='arm64';;
*) echo "$UNAME_OUTPUT is unsupported" && exit 1 ;;
esac
{{- if .Values.plugins.version }}
VER={{ .Values.plugins.version | quote}}
{{- else }}
VER=$(curl --silent https://api.github.com/repos/opencost/opencost-plugins/releases/latest | grep ".tag_name" | awk -F\" '{print $4}')
{{- end }}
{{- range $pluginName, $config := .Values.plugins.configs }}
curl -fsSLO "https://github.com/opencost/opencost-plugins/releases/download/$VER/{{ $pluginName }}.ocplugin.$OS.$ARCH"
chmod a+rx "{{ $pluginName }}.ocplugin.$OS.$ARCH"
{{- end }}
{{- end }}
{{- end }}
16 changes: 16 additions & 0 deletions charts/opencost/templates/plugins-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{- if .Values.plugins.enabled }}
apiVersion: v1
kind: Secret
metadata:
name: {{ template "opencost.fullname" . }}-plugins-config
labels:
app: {{ template "opencost.name" . }}
chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
data:
{{- range $key, $config := .Values.plugins.configs }}
{{ $key }}_config.json:
{{ $config | b64enc | indent 4}}
{{- end }}
{{- end }}
28 changes: 28 additions & 0 deletions charts/opencost/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,34 @@ fullnameOverride: ""
# -- Override the deployment namespace
namespaceOverride: ""

loglevel: info

plugins:
enabled: false
install:
enabled: true
fullImageName: curlimages/curl:latest
securityContext:
allowPrivilegeEscalation: false
seccompProfile:
type: RuntimeDefault
capabilities:
drop:
- ALL
readOnlyRootFilesystem: true
runAsNonRoot: true
runAsUser: 1000
folder: /opt/opencost/plugin
# leave this commented to always download most recent version of plugins
# version: <INSERT_SPECIFIC_PLUGINS_VERSION>
configs:
# datadog: |
# {
# "datadog_site": "<INSERT_DATADOG_SITE>",
# "datadog_api_key": "<INSERT_DATADOG_API_KEY>",
# "datadog_app_key": "<INSERT_DATADOG_APP_KEY>"
# }

# -- List of secret names to use for pulling the images
imagePullSecrets: []

Expand Down

0 comments on commit a2b2992

Please sign in to comment.