Skip to content

Commit

Permalink
Multitenant tests
Browse files Browse the repository at this point in the history
Added new test pod for multitenant tests
refactored test auth configuration for better code reuse
  • Loading branch information
blaskoa committed Jan 18, 2024
1 parent 7e7b119 commit 640cc2b
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 50 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,10 @@ metadata:
| streamDataDbWorker.tolerations | list | `[]` | |
| tests.authentication.tenant1.clientId | string | `""` | |
| tests.authentication.tenant1.clientSecret | string | `""` | |
| tests.authentication.tenant1.name | string | `""` | |
| tests.authentication.tenant2.clientId | string | `""` | |
| tests.authentication.tenant2.clientSecret | string | `""` | |
| tests.authentication.tenant2.name | string | `""` | |
| tests.image.digest | string | `nil` | Overrides the image tag with an image digest |
| tests.image.pullPolicy | string | `"IfNotPresent"` | Docker image pull policy |
| tests.image.registry | string | `nil` | The Docker registry, overrides `global.image.registry` |
Expand Down
9 changes: 9 additions & 0 deletions templates/_components.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -514,3 +514,12 @@ Template used for resolving GraphQL tests name
{{- $suffix := "graphql-tests" -}}
{{- printf "%s-%s" $prefix $suffix -}}
{{- end -}}

{{/*
Template used for resolving Multitenant tests name
*/}}
{{- define "smartface.multitenantTests.name" }}
{{- $prefix := include "smartface.name" . -}}
{{- $suffix := "multitenant-tests" -}}
{{- printf "%s-%s" $prefix $suffix -}}
{{- end -}}
31 changes: 31 additions & 0 deletions templates/_configurations.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,34 @@ Enabling statistics pulishing for countly sender
- name: "Statistics__SendStatisticsData"
value: {{ .Values.countlyPublisher.enabled | quote }}
{{- end }}

{{/*
Template used for setting up authentication data for test pods
*/}}
{{- define "smartface.testsAuthConfig" -}}
{{- $configName := ( .Values.configurations.apiAuth.existingConfigMapName | default (include "smartface.auth.name" . )) }}
- name: "SF_TENANT_1_NAME"
value: {{ .Values.tests.authentication.tenant1.name }}
- name: "SF_TENANT_1_CLIENT_ID"
value: {{ .Values.tests.authentication.tenant1.clientId }}
- name: "SF_TENANT_1_SECRET"
value: {{ .Values.tests.authentication.tenant1.clientSecret }}
- name: "SF_TENANT_2_NAME"
value: {{ .Values.tests.authentication.tenant2.name }}
- name: "SF_TENANT_2_CLIENT_ID"
value: {{ .Values.tests.authentication.tenant2.clientId }}
- name: "SF_TENANT_2_SECRET"
value: {{ .Values.tests.authentication.tenant2.clientSecret }}
- name: "SF_USE_AUTH"
value: "true"
- name: "SF_AUTH_AUDIENCE"
valueFrom:
configMapKeyRef:
name: {{ $configName }}
key: "audience"
- name: "SF_OAUTH_TOKEN_URL"
valueFrom:
configMapKeyRef:
name: {{ $configName }}
key: "oauth_token_url"
{{- end }}
18 changes: 1 addition & 17 deletions templates/tests/edge-stream-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,7 @@ spec:
- name: "SF_MQTT_PASS"
value: "$(MQTT__Password)"
{{- if $useAuth }}
{{- $configName := ( .Values.configurations.apiAuth.existingConfigMapName | default (include "smartface.auth.name" . )) }}
- name: "SF_TENANT_1_ID"
value: {{ .Values.tests.authentication.tenant1.clientId }}
- name: "SF_TENANT_1_SECRET"
value: {{ .Values.tests.authentication.tenant1.clientSecret }}
- name: "SF_USE_AUTH"
value: "true"
- name: "SF_AUTH_AUDIENCE"
valueFrom:
configMapKeyRef:
name: {{ $configName }}
key: "audience"
- name: "SF_OAUTH_TOKEN_URL"
valueFrom:
configMapKeyRef:
name: {{ $configName }}
key: "oauth_token_url"
{{- include "smartface.testsAuthConfig" . | nindent 4 }}
{{- end }}
volumeMounts:
{{- include "smartface.licVolumeMount" . | nindent 4 }}
Expand Down
18 changes: 1 addition & 17 deletions templates/tests/graphql-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,7 @@ spec:
- name: "SF_TEST_GQL_API_URL"
value: "http://{{ include "smartface.graphqlApi.name" . }}.{{ .Release.Namespace }}.svc.cluster.local:{{ .Values.graphqlApi.servicePort }}"
{{- if $useAuth }}
{{- $configName := ( .Values.configurations.apiAuth.existingConfigMapName | default (include "smartface.auth.name" . )) }}
- name: "SF_TENANT_1_ID"
value: {{ .Values.tests.authentication.tenant1.clientId }}
- name: "SF_TENANT_1_SECRET"
value: {{ .Values.tests.authentication.tenant1.clientSecret }}
- name: "SF_USE_AUTH"
value: "true"
- name: "SF_AUTH_AUDIENCE"
valueFrom:
configMapKeyRef:
name: {{ $configName }}
key: "audience"
- name: "SF_OAUTH_TOKEN_URL"
valueFrom:
configMapKeyRef:
name: {{ $configName }}
key: "oauth_token_url"
{{- include "smartface.testsAuthConfig" . | nindent 4 }}
{{- end }}
volumeMounts:
{{- include "smartface.licVolumeMount" . | nindent 4 }}
Expand Down
59 changes: 59 additions & 0 deletions templates/tests/multitenant-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@

{{- if and .Values.authApi.enabled .Values.graphqlApi.enableAuth .Values.features.multitenancy -}}
{{- $name := include "smartface.multitenantTests.name" . -}}
{{- $apiUrl := printf "http://%s.%s.svc.cluster.local:%d" (include "smartface.authApi.name" .) .Release.Namespace (.Values.authApi.servicePort | int) -}}
{{- $apiMetricsUrl := printf "http://%s.%s.svc.cluster.local:%d" (include "smartface.authApi.name" .) .Release.Namespace (.Values.metrics.port | int) -}}
{{- $configName := ( .Values.configurations.apiAuth.existingConfigMapName | default (include "smartface.auth.name" . )) }}
apiVersion: v1
kind: Pod
metadata:
name: {{ $name | quote }}
annotations:
"helm.sh/hook": test
{{- with .Values.podAnnotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.tests.podAnnotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
labels:
{{- with .Values.podLabels }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.tests.podLabels }}
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
serviceAccountName: {{ .Values.serviceAccount.name | quote }}
automountServiceAccountToken: {{ .Values.serviceAccount.automountServiceAccountToken }}
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 4 }}
{{- end }}
containers:
- name: {{ $name | quote }}
image: {{ include "smartface.image" (dict "local" .Values.tests.image "global" .Values.global.image "defaultVersion" .Chart.AppVersion) }}
imagePullPolicy: {{ .Values.tests.image.pullPolicy }}
args: ['--filter', 'Category=Multitenant']
env:
- name: "SF_TEST_API_URL"
value: {{ $apiUrl | quote }}
- name: "SF_TEST_GQL_API_URL"
value: "http://{{ include "smartface.graphqlApi.name" . }}.{{ .Release.Namespace }}.svc.cluster.local:{{ .Values.graphqlApi.servicePort }}"
- name: "SF_API_METRICS_URL"
value: {{ $apiMetricsUrl | quote }}
{{- include "smartface.testsAuthConfig" . | nindent 4 }}
volumeMounts:
{{- include "smartface.licVolumeMount" . | nindent 4 }}
volumes:
{{- include "smartface.licVolume" . | nindent 4 }}
{{- with .Values.tests.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.tests.tolerations }}
tolerations:
{{- toYaml . | nindent 4 }}
{{- end }}
restartPolicy: Never
{{- end }}
17 changes: 1 addition & 16 deletions templates/tests/watchlist-auth-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,7 @@ spec:
env:
- name: "SF_TEST_API_URL"
value: {{ $apiUrl | quote }}
- name: "SF_TENANT_1_ID"
value: {{ .Values.tests.authentication.tenant1.clientId }}
- name: "SF_TENANT_1_SECRET"
value: {{ .Values.tests.authentication.tenant1.clientSecret }}
- name: "SF_USE_AUTH"
value: "true"
- name: "SF_AUTH_AUDIENCE"
valueFrom:
configMapKeyRef:
name: {{ $configName }}
key: "audience"
- name: "SF_OAUTH_TOKEN_URL"
valueFrom:
configMapKeyRef:
name: {{ $configName }}
key: "oauth_token_url"
{{- include "smartface.testsAuthConfig" . | nindent 4 }}
volumeMounts:
{{- include "smartface.licVolumeMount" . | nindent 4 }}
volumes:
Expand Down
5 changes: 5 additions & 0 deletions values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,11 @@ countlyPublisher:
tests:
authentication:
tenant1:
name: ""
clientId: ""
clientSecret: ""
tenant2:
name: ""
clientId: ""
clientSecret: ""
# -- Annotations for test pods
Expand Down

0 comments on commit 640cc2b

Please sign in to comment.