Skip to content

Commit 9aa86f9

Browse files
authored
chore(performance): use sealed secrets in k8s (#1811)
<!--- Provide a general summary of your changes in the Title above --> ## Description Use sealed secrets in k8s instead of sending user/passwd in to the k6 archive command (cleartext). Also fix use of hardcoded env-variables for api-version and environment ## Related Issue(s) - #1810 ## Verification - [ ] **Your** code builds clean without any errors or warnings - [ ] Manual testing done (required) - [ ] Relevant automated test added (if you find this hard, leave it and we'll help out) ## Documentation - [ ] Documentation is updated (either in `docs`-directory, Altinnpedia or a separate linked PR in [altinn-studio-docs.](https://github.com/Altinn/altinn-studio-docs), if applicable)
1 parent 870ccd3 commit 9aa86f9

File tree

4 files changed

+9
-20
lines changed

4 files changed

+9
-20
lines changed

.github/workflows/dispatch-k6-breakpoint.yml

-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ jobs:
5858
name: "Run K6 performance test"
5959
uses: ./.github/workflows/workflow-run-k6-performance.yml
6060
secrets:
61-
TOKEN_GENERATOR_USERNAME: ${{ secrets.TOKEN_GENERATOR_USERNAME }}
62-
TOKEN_GENERATOR_PASSWORD: ${{ secrets.TOKEN_GENERATOR_PASSWORD }}
6361
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
6462
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
6563
with:

.github/workflows/dispatch-k6-performance.yml

-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ jobs:
5555
name: "Run K6 performance test"
5656
uses: ./.github/workflows/workflow-run-k6-performance.yml
5757
secrets:
58-
TOKEN_GENERATOR_USERNAME: ${{ secrets.TOKEN_GENERATOR_USERNAME }}
59-
TOKEN_GENERATOR_PASSWORD: ${{ secrets.TOKEN_GENERATOR_PASSWORD }}
6058
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
6159
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
6260
with:

.github/workflows/workflow-run-k6-performance.yml

-6
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ on:
2828
required: true
2929
type: boolean
3030
secrets:
31-
TOKEN_GENERATOR_USERNAME:
32-
required: true
33-
TOKEN_GENERATOR_PASSWORD:
34-
required: true
3531
AZURE_CLIENT_ID:
3632
required: true
3733
AZURE_TENANT_ID:
@@ -81,5 +77,3 @@ jobs:
8177
env:
8278
API_ENVIRONMENT: ${{ inputs.environment }}
8379
API_VERSION: ${{ inputs.apiVersion }}
84-
TOKEN_GENERATOR_USERNAME: ${{ secrets.TOKEN_GENERATOR_USERNAME }}
85-
TOKEN_GENERATOR_PASSWORD: ${{ secrets.TOKEN_GENERATOR_PASSWORD }}

tests/k6/tests/scripts/run-test-in-k8s.sh

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
11
#!/bin/bash
22

3-
tokengenuser=${TOKEN_GENERATOR_USERNAME}
4-
tokengenpasswd=${TOKEN_GENERATOR_PASSWORD}
3+
API_VERSION=${API_VERSION:-v1}
4+
API_ENVIRONMENT=${API_ENVIRONMENT:-yt01}
55
failed=0
6-
76
kubectl config set-context --current --namespace=dialogporten
87

9-
# Validate required environment variables
10-
if [ -z "$TOKEN_GENERATOR_USERNAME" ] || [ -z "$TOKEN_GENERATOR_PASSWORD" ]; then
11-
echo "Error: TOKEN_GENERATOR_USERNAME and TOKEN_GENERATOR_PASSWORD must be set"
12-
exit 1
13-
fi
14-
158
help() {
169
echo "Usage: $0 [OPTIONS]"
1710
echo "Options:"
@@ -126,7 +119,10 @@ if $breakpoint; then
126119
fi
127120
# Create the k6 archive
128121

129-
if ! k6 archive $filename -e API_VERSION=v1 -e API_ENVIRONMENT=yt01 -e TOKEN_GENERATOR_USERNAME=$tokengenuser -e TOKEN_GENERATOR_PASSWORD=$tokengenpasswd -e TESTID=$testid $archive_args; then
122+
if ! k6 archive $filename \
123+
-e API_VERSION="$API_VERSION" \
124+
-e API_ENVIRONMENT="$API_ENVIRONMENT" \
125+
-e TESTID=$testid $archive_args; then
130126
echo "Error: Failed to create k6 archive"
131127
exit 1
132128
fi
@@ -162,6 +158,9 @@ spec:
162158
value: "http://kube-prometheus-stack-prometheus.monitoring:9090/api/v1/write"
163159
- name: K6_PROMETHEUS_RW_TREND_STATS
164160
value: "avg,min,med,max,p(95),p(99),p(99.5),p(99.9),count"
161+
envFrom:
162+
- secretRef:
163+
name: "token-generator-creds"
165164
metadata:
166165
labels:
167166
k6-test: $name

0 commit comments

Comments
 (0)