Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenCTI: EnvFromSecret variable not taking precedence over normal env in chart #50

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 25 additions & 22 deletions charts/opencti/templates/connector/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,44 +54,47 @@ spec:
{{- end }}
imagePullPolicy: {{ .image.pullPolicy | default "IfNotPresent" }}
env:
# Variables in plain text
# Variables from secrets have precedence
{{- $envList := dict -}}

{{- if .envFromSecrets }}
{{- range $key, $value := .envFromSecrets }}
- name: {{ $key | upper }}
valueFrom:
secretKeyRef:
name: {{ $value.name }}
key: {{ $value.key | default $key }}
{{- $_ := set $envList $key true }}
{{- end }}
{{- end }}

{{- if and (not (hasKey $envList "OPENCTI_TOKEN")) (.env.APP__ADMIN__TOKEN) }}
- name: OPENCTI_TOKEN
value: "{{ .env.APP__ADMIN__TOKEN }}"
{{- end }}

# Special handling for OPENCTI_URL which is constructed from other values
{{- if not (hasKey $.Values.env "OPENCTI_URL") }}
{{- if eq $.Values.env.APP__BASE_PATH "/" }}
- name: OPENCTI_URL
value: "http://{{ include "opencti.fullname" $ }}-server:{{ $.Values.service.port }}"
{{- else }}
- name: OPENCTI_URL
value: "http://{{ include "opencti.fullname" $ }}-server:{{ $.Values.service.port }}{{ $.Values.env.APP__BASE_PATH }}"
{{- end }}

{{- if $.Values.env.APP__ADMIN__TOKEN }}
- name: OPENCTI_TOKEN
value: "{{ $.Values.env.APP__ADMIN__TOKEN }}"
{{- end }}

{{- if $.Values.connectorsGlobalEnv }}
{{- range $key, $value := $.Values.connectorsGlobalEnv }}
- name: {{ $key | upper }}
value: {{ $value | quote }}
{{- end }}
{{- end }}

# Add Variables in plain text if they were not already added from secrets
{{- if .env }}
{{- range $key, $value := .env }}
{{- if not (hasKey $envList $key) }}
- name: {{ $key | upper }}
value: {{ $value | quote }}
{{- $_ := set $envList $key true }}
{{- end }}
{{- end }}

# Variables from secrets
{{- if .envFromSecrets }}
{{- range $key, $value := .envFromSecrets }}
- name: {{ $key | upper }}
valueFrom:
secretKeyRef:
name: {{ $value.name }}
key: {{ $value.key | default $key }}
{{- end }}
{{- end }}

resources:
{{- toYaml .resources | nindent 12 }}
{{- with .nodeSelector }}
Expand Down
28 changes: 13 additions & 15 deletions charts/opencti/templates/server/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,34 +123,32 @@ spec:
- name: PROVIDERS__LOCAL__STRATEGY
value: LocalStrategy

# Variables in plain text
{{- if .Values.env }}
{{- range $key, $value := .Values.env }}
- name: {{ $key | upper }}
value: {{ $value | quote }}
{{- end }}
{{- end }}

# Variables from secrets
# Variables from secrets have precedence
{{- $envList := dict -}}
{{- if .Values.envFromSecrets }}
{{- range $key, $value := .Values.envFromSecrets }}
{{- if not (hasKey $envList $key) }}
- name: {{ $key | upper }}
valueFrom:
secretKeyRef:
name: {{ $value.name }}
key: {{ $value.key | default $key }}
{{- $_ := set $envList $key true }}
{{- end }}
{{- end }}
{{- end }}

{{- if .Values.envFromSecrets }}
{{- range $key, $value := .Values.envFromSecrets }}
# Add Variables in plain text if they were not already added from secrets
{{- if .Values.env }}
{{- range $key, $value := .Values.env }}
{{- if not (hasKey $envList $key) }}
- name: {{ $key | upper }}
valueFrom:
secretKeyRef:
name: {{ $value.name }}
key: {{ $value.key | default $key }}
value: {{ $value | quote }}
{{- $_ := set $envList $key true }}
{{- end }}
{{- end }}
{{- end }}

resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.nodeSelector }}
Expand Down
37 changes: 25 additions & 12 deletions charts/opencti/templates/worker/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,35 +64,48 @@ spec:
protocol: TCP
{{- end }}
env:
# Variables in plain text
# Variables from secrets have precedence

{{- $envList := dict -}}

{{- if .Values.worker.envFromSecrets }}
{{- range $key, $value := .Values.worker.envFromSecrets }}
- name: {{ $key | upper }}
valueFrom:
secretKeyRef:
name: {{ $value.name }}
key: {{ $value.key | default $key }}
{{- $_ := set $envList $key true }}
{{- end }}
{{- end }}

# Special handling for OPENCTI_URL which is constructed from other values
{{- if not (hasKey $envList "OPENCTI_URL") }}
{{- if eq .Values.env.APP__BASE_PATH "/" }}
- name: OPENCTI_URL
value: "http://{{ include "opencti.fullname" . }}-server:{{ .Values.service.port }}"
{{- else }}
- name: OPENCTI_URL
value: "http://{{ include "opencti.fullname" . }}-server:{{ .Values.service.port }}{{ .Values.env.APP__BASE_PATH }}"
{{- end }}
{{- if .Values.env.APP__ADMIN__TOKEN }}
{{- end }}

{{- if and (not (hasKey $envList "OPENCTI_TOKEN")) (.Values.env.APP__ADMIN__TOKEN) }}
- name: OPENCTI_TOKEN
value: "{{ .Values.env.APP__ADMIN__TOKEN }}"
{{- end }}

# Add Variables in plain text from .Values.worker.env if they were not already added from secrets
{{- if .Values.worker.env }}
{{- range $key, $value := .Values.worker.env }}
{{- if not (hasKey $envList $key) }}
- name: {{ $key | upper }}
value: {{ $value | quote }}
{{- $_ := set $envList $key true }}
{{- end }}
{{- end }}

# Variables from secrets
{{- if .Values.worker.envFromSecrets }}
{{- range $key, $value := .Values.worker.envFromSecrets }}
- name: {{ $key | upper }}
valueFrom:
secretKeyRef:
name: {{ $value.name }}
key: {{ $value.key | default $key }}
{{- end }}
{{- end }}

resources:
{{- toYaml .Values.worker.resources | nindent 12 }}
{{- with .Values.worker.nodeSelector }}
Expand Down
Loading