Skip to content

Commit f389cdb

Browse files
valkey gets it's own secret
1 parent 02f5f71 commit f389cdb

File tree

5 files changed

+32
-22
lines changed

5 files changed

+32
-22
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ require (
1414
github.com/magiconair/properties v1.8.9
1515
github.com/mitchellh/hashstructure v1.1.0
1616
github.com/mitchellh/mapstructure v1.5.0
17-
github.com/nais/liberator v0.0.0-20250321111657-2305f498619e
17+
github.com/nais/liberator v0.0.0-20250321121702-2399ce86b625
1818
github.com/novln/docker-parser v1.0.0
1919
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.74.0
2020
github.com/prometheus/client_golang v1.21.0

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ github.com/nais/liberator v0.0.0-20250319104751-ae803ff00b4f h1:sQkwvc4OPh/vT2Bf
149149
github.com/nais/liberator v0.0.0-20250319104751-ae803ff00b4f/go.mod h1:F3YcGoCG6HAyX5R2tgGH79/R0LBAU2xtRgRaveSXKiA=
150150
github.com/nais/liberator v0.0.0-20250321111657-2305f498619e h1:HSv15/Xr61GYo35NKxtE5x7snZKo0p/R8ZYnghkpHh8=
151151
github.com/nais/liberator v0.0.0-20250321111657-2305f498619e/go.mod h1:F3YcGoCG6HAyX5R2tgGH79/R0LBAU2xtRgRaveSXKiA=
152+
github.com/nais/liberator v0.0.0-20250321121702-2399ce86b625 h1:/gRu1JuvaNLIpFgGBYpUFefQqEvszoP3DrOKUFO00uo=
153+
github.com/nais/liberator v0.0.0-20250321121702-2399ce86b625/go.mod h1:F3YcGoCG6HAyX5R2tgGH79/R0LBAU2xtRgRaveSXKiA=
152154
github.com/novln/docker-parser v1.0.0 h1:PjEBd9QnKixcWczNGyEdfUrP6GR0YUilAqG7Wksg3uc=
153155
github.com/novln/docker-parser v1.0.0/go.mod h1:oCeM32fsoUwkwByB5wVjsrsVQySzPWkl3JdlTn1txpE=
154156
github.com/onsi/ginkgo/v2 v2.22.1 h1:QW7tbJAUDyVDVOM5dFa7qaybo+CRfR7bemlQUN6Z8aM=

pkg/resourcecreator/aiven/valkey.go

+10-4
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,24 @@ func Valkey(ast *resource.Ast, config Config, source Source, aivenApp *aiven_nai
2020
return false, fmt.Errorf("aiven project not defined for this cluster; needed for Valkey")
2121
}
2222

23+
secretName, err := generateAivenSecretName(aivenApp.Name, "valkey", aivenApp.ObjectMeta.Labels["aiven.nais.io/secret-generation"])
24+
if err != nil {
25+
return false, err
26+
}
27+
2328
for _, valkey := range valkeyes {
2429
if valkey.Instance == "" {
2530
return false, fmt.Errorf("Valkey requires instance name")
2631
}
2732

28-
addValkeyEnvVariables(ast, aivenApp.Spec.SecretName, valkey.Instance)
33+
addValkeyEnvVariables(ast, secretName, valkey.Instance)
2934
// Make the transition easier for teams coming from Redis by setting the `REDIS_` env variables too
30-
addRedisEnvVariables(ast, aivenApp.Spec.SecretName, valkey.Instance)
35+
addRedisEnvVariables(ast, secretName, valkey.Instance)
3136

3237
aivenApp.Spec.Valkey = append(aivenApp.Spec.Valkey, &aiven_nais_io_v1.ValkeySpec{
33-
Instance: valkey.Instance,
34-
Access: valkey.Access,
38+
Instance: valkey.Instance,
39+
Access: valkey.Access,
40+
SecretName: secretName,
3541
})
3642

3743
addDefaultValkeyIfNotExists(ast, source, config.GetAivenProject(), valkey.Instance)

pkg/resourcecreator/testdata/naisjob/cronjob_valkey.yaml

+7-6
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ tests:
2929
name: "secret name is generated"
3030
resource:
3131
spec:
32-
secretName: ^aiven-mynaisjob-.{8}-\d{4}-\d\d?-0$
32+
valkey:
33+
- secretName: ^aiven-valkey-mynaisjob-.{8}-\d{4}-\d\d?-0$
3334
- name: "instance and access is propagated"
3435
type: subset
3536
resource:
@@ -62,28 +63,28 @@ tests:
6263
valueFrom:
6364
secretKeyRef:
6465
key: VALKEY_USERNAME_NAISTEST1
65-
name: ^aiven-mynaisjob-.{8}-\d{4}-\d\d?-0$
66+
name: ^aiven-valkey-mynaisjob-.{8}-\d{4}-\d\d?-0$
6667
- name: VALKEY_PASSWORD_NAISTEST1
6768
valueFrom:
6869
secretKeyRef:
6970
key: VALKEY_PASSWORD_NAISTEST1
70-
name: ^aiven-mynaisjob-.{8}-\d{4}-\d\d?-0$
71+
name: ^aiven-valkey-mynaisjob-.{8}-\d{4}-\d\d?-0$
7172
- name: VALKEY_URI_NAISTEST1
7273
valueFrom:
7374
secretKeyRef:
7475
key: VALKEY_URI_NAISTEST1
75-
name: ^aiven-mynaisjob-.{8}-\d{4}-\d\d?-0$
76+
name: ^aiven-valkey-mynaisjob-.{8}-\d{4}-\d\d?-0$
7677
- name: VALKEY_HOST_NAISTEST1
7778
valueFrom:
7879
secretKeyRef:
7980
key: VALKEY_HOST_NAISTEST1
80-
name: ^aiven-mynaisjob-.{8}-\d{4}-\d\d?-0$
81+
name: ^aiven-valkey-mynaisjob-.{8}-\d{4}-\d\d?-0$
8182
optional: true
8283
- name: VALKEY_PORT_NAISTEST1
8384
valueFrom:
8485
secretKeyRef:
8586
key: VALKEY_PORT_NAISTEST1
86-
name: ^aiven-mynaisjob-.{8}-\d{4}-\d\d?-0$
87+
name: ^aiven-valkey-mynaisjob-.{8}-\d{4}-\d\d?-0$
8788
optional: true
8889
- operation: CreateIfNotExists
8990
apiVersion: aiven.io/v1alpha1

pkg/resourcecreator/testdata/valkey.yaml

+12-11
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ tests:
2828
name: "secret name is generated"
2929
resource:
3030
spec:
31-
secretName: ^aiven-myapplication-.{8}-\d{4}-\d\d?-0$
31+
valkey:
32+
- secretName: ^aiven-valkey-myapplication-.{8}-\d{4}-\d\d?-0$
3233
- name: "instance and access is propagated"
3334
type: subset
3435
resource:
@@ -59,55 +60,55 @@ tests:
5960
valueFrom:
6061
secretKeyRef:
6162
key: REDIS_USERNAME_NAISTEST1
62-
name: ^aiven-myapplication-.{8}-\d{4}-\d\d?-0$
63+
name: ^aiven-valkey-myapplication-.{8}-\d{4}-\d\d?-0$
6364
- name: REDIS_PASSWORD_NAISTEST1
6465
valueFrom:
6566
secretKeyRef:
6667
key: REDIS_PASSWORD_NAISTEST1
67-
name: ^aiven-myapplication-.{8}-\d{4}-\d\d?-0$
68+
name: ^aiven-valkey-myapplication-.{8}-\d{4}-\d\d?-0$
6869
- name: REDIS_URI_NAISTEST1
6970
valueFrom:
7071
secretKeyRef:
7172
key: REDIS_URI_NAISTEST1
72-
name: ^aiven-myapplication-.{8}-\d{4}-\d\d?-0$
73+
name: ^aiven-valkey-myapplication-.{8}-\d{4}-\d\d?-0$
7374
- name: REDIS_HOST_NAISTEST1
7475
valueFrom:
7576
secretKeyRef:
7677
key: REDIS_HOST_NAISTEST1
77-
name: ^aiven-myapplication-.{8}-\d{4}-\d\d?-0$
78+
name: ^aiven-valkey-myapplication-.{8}-\d{4}-\d\d?-0$
7879
optional: true
7980
- name: REDIS_PORT_NAISTEST1
8081
valueFrom:
8182
secretKeyRef:
8283
key: REDIS_PORT_NAISTEST1
83-
name: ^aiven-myapplication-.{8}-\d{4}-\d\d?-0$
84+
name: ^aiven-valkey-myapplication-.{8}-\d{4}-\d\d?-0$
8485
optional: true
8586
- name: VALKEY_USERNAME_NAISTEST1
8687
valueFrom:
8788
secretKeyRef:
8889
key: VALKEY_USERNAME_NAISTEST1
89-
name: ^aiven-myapplication-.{8}-\d{4}-\d\d?-0$
90+
name: ^aiven-valkey-myapplication-.{8}-\d{4}-\d\d?-0$
9091
- name: VALKEY_PASSWORD_NAISTEST1
9192
valueFrom:
9293
secretKeyRef:
9394
key: VALKEY_PASSWORD_NAISTEST1
94-
name: ^aiven-myapplication-.{8}-\d{4}-\d\d?-0$
95+
name: ^aiven-valkey-myapplication-.{8}-\d{4}-\d\d?-0$
9596
- name: VALKEY_URI_NAISTEST1
9697
valueFrom:
9798
secretKeyRef:
9899
key: VALKEY_URI_NAISTEST1
99-
name: ^aiven-myapplication-.{8}-\d{4}-\d\d?-0$
100+
name: ^aiven-valkey-myapplication-.{8}-\d{4}-\d\d?-0$
100101
- name: VALKEY_HOST_NAISTEST1
101102
valueFrom:
102103
secretKeyRef:
103104
key: VALKEY_HOST_NAISTEST1
104-
name: ^aiven-myapplication-.{8}-\d{4}-\d\d?-0$
105+
name: ^aiven-valkey-myapplication-.{8}-\d{4}-\d\d?-0$
105106
optional: true
106107
- name: VALKEY_PORT_NAISTEST1
107108
valueFrom:
108109
secretKeyRef:
109110
key: VALKEY_PORT_NAISTEST1
110-
name: ^aiven-myapplication-.{8}-\d{4}-\d\d?-0$
111+
name: ^aiven-valkey-myapplication-.{8}-\d{4}-\d\d?-0$
111112
optional: true
112113
- operation: CreateIfNotExists
113114
apiVersion: aiven.io/v1alpha1

0 commit comments

Comments
 (0)