Skip to content
Open
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
8 changes: 0 additions & 8 deletions .github/workflows/lint-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@ jobs:
with:
fetch-depth: 0

- name: Envsubst
uses: danielr1996/[email protected]
env:
SLACK_TOKEN: ${{ secrets.SLACK_TOKEN }}
with:
input: charts/flagsmith/ci/e2e-test-values.yaml
output: charts/flagsmith/ci/e2e-test-values.yaml

- name: Set up Helm
uses: azure/setup-helm@v4
with:
Expand Down
13 changes: 0 additions & 13 deletions charts/flagsmith/ci/e2e-test-values.yaml

This file was deleted.

22 changes: 22 additions & 0 deletions charts/flagsmith/ci/test-values.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,24 @@
tests:
enabled: true

influxdb2:
enabled: false

devPostgresql:
enabled: true

databaseExternal:
replicas:
Comment on lines +7 to +11
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious we're testing integrated postgres enabled + replicas and not external postgres + replicas here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dev postgres is only so that there's an actual database we can use while running the tests. If we remove this, or refer to a non-existing external database, the API containers cannot come up and the tests fail.

In any case, we're not testing anything relating to the primary database (integrated or external). We're only testing that if you pass in the Helm values for replicas in different formats, then the API containers will have the correct environment variables set on them.

databases:
- url: postgres://user:[email protected]:5432/flagsmith

- type: postgres
host: 127.0.0.1
port: 5433
database: flagsmith
username: user
password: password

- fromExistingSecret:
name: test-replica-secret
key: database-url
32 changes: 28 additions & 4 deletions charts/flagsmith/templates/_api_environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,34 @@
name: {{ template "flagsmith.fullname" . }}
key: DATABASE_URL
{{- end }}
{{/*
Replica database URLs can be passed in different ways:
- Plaintext URL
- Plaintext dictionary config
- Secret reference
*/}}
{{- range $index, $db := .Values.databaseExternal.replicas.databases }}
- name: REPLICA_DATABASE_URL_{{ $index }}
{{- if $db.fromExistingSecret }}
valueFrom:
secretKeyRef:
name: {{ $db.fromExistingSecret.name }}
key: {{ $db.fromExistingSecret.key }}
{{- else }}
value: {{ include "flagsmith.api.formatDatabaseUrl" $db | quote }}
{{- end }}
{{- end }}
{{- range $index, $db := .Values.databaseExternal.crossRegionReplicas.databases }}
- name: CROSS_REGION_REPLICA_DATABASE_URL_{{ $index }}
{{- if $db.fromExistingSecret }}
valueFrom:
secretKeyRef:
name: {{ $db.fromExistingSecret.name }}
key: {{ $db.fromExistingSecret.key }}
{{- else }}
value: {{ include "flagsmith.api.formatDatabaseUrl" $db | quote }}
{{- end }}
{{- end }}
- name: DJANGO_SECRET_KEY
valueFrom:
secretKeyRef:
Expand Down Expand Up @@ -101,10 +129,6 @@
- name: USE_X_FORWARDED_HOST
value: 'true'
{{- end }}
{{- if and .Values._destructiveTests.enabled .Values._destructiveTests.testToken }}
- name: E2E_TEST_AUTH_TOKEN
value: {{ .Values._destructiveTests.testToken | quote }}
{{- end }}
{{- if .Values.api.logging.format }}
- name: LOG_FORMAT
value: {{ .Values.api.logging.format }}
Expand Down
52 changes: 21 additions & 31 deletions charts/flagsmith/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -253,16 +253,6 @@ Frontend environment
- name: FLAGSMITH_PROXY_API_URL
value: http://{{ include "flagsmith.fullname" . }}-api.{{ .Release.Namespace }}:{{ .Values.service.api.port }}
{{- end }}
{{- if and .Values._destructiveTests.enabled .Values._destructiveTests.testToken }}
- name: E2E_TEST_TOKEN_E2E
value: {{ .Values._destructiveTests.testToken | quote }}
- name: E2E_TEST_TOKEN
value: {{ .Values._destructiveTests.testToken | quote }}
- name: FLAGSMITH_API
value: {{ include "flagsmith.fullname" . }}-api.{{ .Release.Namespace }}:{{ .Values.service.api.port }}/api/v1/
- name: ENABLE_INFLUXDB_FEATURES
value: {{ .Values.influxdb2.enabled | ternary "true" "false" | squote }}
{{- end }}
{{- range $envName, $envValue := .Values.frontend.extraEnv }}
- name: {{ $envName }}
value: {{ $envValue | quote }}
Expand Down Expand Up @@ -316,27 +306,6 @@ Database URL for application
{{- end }}
{{- end }}

{{/*
Curl Test container
*/}}
{{- define "flagsmith.tests.curlContainer" -}}
name: {{ .name }}
image: curlimages/curl
command: ['curl']
args:
- --fail
- --max-time
- {{ .maxTime | squote }}
- --silent
{{- if not .printResponseBody }}
- --output
- /dev/null
{{- end }}
- --write-out
- 'URL: %{url_effective}\nHTTP status code: %{http_code}\nBytes downloaded: %{size_download}\nTime taken: %{time_total}s\n'
- {{ .url | squote }}
{{- end }}

{{/*
Replicas
*/}}
Expand All @@ -346,6 +315,27 @@ replicas: {{ . }}
{{- end }}
{{- end }}

{{/*
Determine database URL for direct URL format or component parts
*/}}
{{- define "flagsmith.api.formatDatabaseUrl" -}}
{{- if .url -}}
{{- .url -}}
{{- else -}}
{{- $type := .type | default "postgres" -}}
{{- $port := .port | default "5432" -}}
{{- $password := .password | default "" -}}
{{- $username := required "Must specify a database username" .username -}}
{{- $host := required "Must specify a database host" .host -}}
{{- $database := required "Must specify a database name" .database -}}

{{- if $password -}}
{{- printf "%s://%s:%s@%s:%v/%s" $type $username $password $host $port $database -}}
{{- else -}}
{{- printf "%s://%s@%s:%v/%s" $type $username $host $port $database -}}
{{- end -}}
{{- end -}}
{{- end -}}

{{- define "flagsmith.api.secretKeySecretName" -}}
{{- if .Values.api.secretKeyFromExistingSecret.enabled -}}
Expand Down
54 changes: 54 additions & 0 deletions charts/flagsmith/templates/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{{- if .Values.tests.enabled }}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ .Release.Name }}-test-serviceaccount
labels:
{{- include "flagsmith.labels" . | nindent 4 }}
app.kubernetes.io/component: test-replica-database-urls
annotations:
{{- $annotations := include "flagsmith.annotations" .Values.common }}
{{- if $annotations }}
{{- $annotations | nindent 4 }}
{{- end }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: {{ .Release.Name }}-test-role
labels:
{{- include "flagsmith.labels" . | nindent 4 }}
rules:
- apiGroups: ["apps"]
resources: ["deployments"]
verbs: ["get"]
- apiGroups: [""]
resources: ["pods"]
verbs: ["get", "list"]
- apiGroups: [""]
resources: ["pods/exec"]
verbs: ["create"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: {{ .Release.Name }}-test-rolebinding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: {{ .Release.Name }}-test-role
subjects:
- kind: ServiceAccount
name: {{ .Release.Name }}-test-serviceaccount
---
apiVersion: v1
kind: Secret
metadata:
name: test-replica-secret
labels:
app.kubernetes.io/component: test-replica-secret
type: Opaque
stringData:
database-url: "postgres://user:[email protected]:5434/flagsmith"

{{- end }}
24 changes: 0 additions & 24 deletions charts/flagsmith/templates/tests/test-api-http-health.yaml

This file was deleted.

33 changes: 0 additions & 33 deletions charts/flagsmith/templates/tests/test-e2e.yaml

This file was deleted.

26 changes: 0 additions & 26 deletions charts/flagsmith/templates/tests/test-frontend-http.yaml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{{- if and .Values.tests.enabled }}
apiVersion: v1
kind: Pod
metadata:
name: {{ template "flagsmith.fullname" . }}-test-replica-database-urls
labels:
{{- include "flagsmith.labels" . | nindent 4 }}
app.kubernetes.io/component: test-replica-database-urls
annotations:
{{- $annotations := include "flagsmith.annotations" .Values.common }}
{{- if $annotations }}
{{- $annotations | nindent 4 }}
{{- end }}
"helm.sh/hook": test
spec:
containers:
- name: test-replica-database-urls
image: bitnami/kubectl
command:
- /bin/bash
- -c
- |
set -e
set -o pipefail

expected_replicas=(
"postgres://user:[email protected]:5432/flagsmith"
"postgres://user:[email protected]:5433/flagsmith"
"postgres://user:[email protected]:5434/flagsmith"
)

# Get all environment variables in one command
replicas=( $(
kubectl exec deploy/{{ template "flagsmith.fullname" . }}-api --\
sh -c "echo \$REPLICA_DATABASE_URL_0; echo \$REPLICA_DATABASE_URL_1; echo \$REPLICA_DATABASE_URL_2"
) )

for i in "${!expected_replicas[@]}"; do
echo "REPLICA_DATABASE_URL_$i = ${replicas[$i]}"
if [ "${replicas[$i]}" != "${expected_replicas[$i]}" ]; then
echo "Replica $i did not match expected value. Expected: ${expected_replicas[$i]}, Got: ${replicas[$i]}"
exit 1
fi
done

serviceAccountName: {{ .Release.Name }}-test-serviceaccount
restartPolicy: Never
{{- end }}
Loading
Loading