@@ -186,9 +186,13 @@ func (r *ValkeyReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
186
186
}
187
187
}
188
188
189
- password , err := r .upsertSecret (ctx , valkey , true )
190
- if err != nil {
191
- return ctrl.Result {}, err
189
+ password := ""
190
+ if ! valkey .Spec .AnonymousAuth {
191
+ var err error
192
+ password , err = r .upsertSecret (ctx , valkey , true )
193
+ if err != nil {
194
+ return ctrl.Result {}, err
195
+ }
192
196
}
193
197
if err := r .upsertPodDisruptionBudget (ctx , valkey ); err != nil {
194
198
return ctrl.Result {}, err
@@ -264,7 +268,9 @@ func (r *ValkeyReconciler) checkState(ctx context.Context, valkey *hyperv1.Valke
264
268
265
269
opt := valkeyClient.ClientOption {
266
270
InitAddress : []string {valkey .Name + "." + valkey .Namespace + ".svc:6379" },
267
- Password : password ,
271
+ }
272
+ if ! valkey .Spec .AnonymousAuth {
273
+ opt .Password = password
268
274
}
269
275
if valkey .Spec .TLS {
270
276
ca , err := r .getCACertificate (ctx , valkey )
@@ -455,12 +461,6 @@ func (r *ValkeyReconciler) initCluster(ctx context.Context, valkey *hyperv1.Valk
455
461
456
462
logger .Info ("initializing cluster" )
457
463
458
- password , err := r .GetPassword (ctx , valkey )
459
- if err != nil {
460
- logger .Error (err , "failed to get password" )
461
- return err
462
- }
463
-
464
464
podNames , err := r .getPodNames (ctx , valkey )
465
465
if err != nil {
466
466
logger .Error (err , "failed to get pod names" )
@@ -488,9 +488,17 @@ func (r *ValkeyReconciler) initCluster(ctx context.Context, valkey *hyperv1.Valk
488
488
address := podName + ":6379"
489
489
opt := valkeyClient.ClientOption {
490
490
InitAddress : []string {address },
491
- Password : password ,
492
491
ForceSingleClient : true , // this is necessary to avoid failing through to another shard and setting the wrong ip
493
492
}
493
+ if ! valkey .Spec .AnonymousAuth {
494
+ var err error
495
+ opt .Password , err = r .GetPassword (ctx , valkey )
496
+ if err != nil {
497
+ logger .Error (err , "failed to get password" )
498
+ return err
499
+ }
500
+ }
501
+
494
502
if valkey .Spec .TLS {
495
503
ca , err := r .getCACertificate (ctx , valkey )
496
504
if err != nil {
@@ -626,20 +634,26 @@ func (r *ValkeyReconciler) setClusterAnnounceIp(ctx context.Context, valkey *hyp
626
634
if len (ips ) == 0 {
627
635
return errors .NewBadRequest ("external ip is empty" )
628
636
}
629
- password , err := r .GetPassword (ctx , valkey )
630
- if err != nil {
631
- logger .Error (err , "failed to get password" )
632
- return err
637
+ password := ""
638
+ if ! valkey .Spec .AnonymousAuth {
639
+ var err error
640
+ password , err = r .GetPassword (ctx , valkey )
641
+ if err != nil {
642
+ logger .Error (err , "failed to get password" )
643
+ return err
644
+ }
633
645
}
634
646
clients := map [string ]valkeyClient.Client {}
635
647
for podName , ip := range ips {
636
648
address := podName + "." + valkey .Name + "-headless." + valkey .Namespace + ":6379"
637
649
logger .Info ("working on node" , "ip" , ip , "pod" , podName , "address" , address )
638
650
opt := valkeyClient.ClientOption {
639
651
InitAddress : []string {address },
640
- Password : password ,
641
652
ForceSingleClient : true , // this is necessary to avoid failing through to another shard and setting the wrong ip
642
653
}
654
+ if ! valkey .Spec .AnonymousAuth {
655
+ opt .Password = password
656
+ }
643
657
if valkey .Spec .TLS {
644
658
ca , err := r .getCACertificate (ctx , valkey )
645
659
if err != nil {
@@ -950,10 +964,17 @@ func (r *ValkeyReconciler) upsertExternalAccessProxySecret(ctx context.Context,
950
964
trusted_ca:
951
965
filename: "/etc/valkey/certs/ca.crt"`
952
966
}
953
- password , err := r .GetPassword (ctx , valkey )
954
- if err != nil {
955
- logger .Error (err , "failed to get password" )
956
- return err
967
+ upstreamPassword := ""
968
+ downstreamPassword := ""
969
+ if ! valkey .Spec .AnonymousAuth {
970
+ password , err := r .GetPassword (ctx , valkey )
971
+ if err != nil {
972
+ logger .Error (err , "failed to get password" )
973
+ return err
974
+ }
975
+ downstreamPassword = ` downstream_auth_password:
976
+ inline_string: "` + password + `"`
977
+ upstreamPassword = ` inline_string: "` + password + `"`
957
978
}
958
979
proxyLabels := labels (valkey )
959
980
proxyLabels ["app.kubernetes.io/component" ] = ValkeyProxy
@@ -984,8 +1005,7 @@ static_resources:
984
1005
prefix_routes:
985
1006
catch_all_route:
986
1007
cluster: redis_cluster
987
- downstream_auth_password:
988
- inline_string: "` + password + `"
1008
+ ` + downstreamPassword + `
989
1009
` + tlsServer + `
990
1010
clusters:
991
1011
- name: redis_cluster
@@ -1008,7 +1028,7 @@ static_resources:
1008
1028
"@type": type.googleapis.com/google.protobuf.Struct
1009
1029
value:
1010
1030
auth_password:
1011
- inline_string: " ` + password + `"
1031
+ ` + upstreamPassword + `
1012
1032
` + tlsClient + `
1013
1033
admin:
1014
1034
address:
@@ -1486,15 +1506,16 @@ func removePort(addr string) string {
1486
1506
func (r * ValkeyReconciler ) balanceNodes (ctx context.Context , valkey * hyperv1.Valkey ) error { // nolint: gocyclo
1487
1507
logger := log .FromContext (ctx )
1488
1508
1489
- password , err := r .upsertSecret (ctx , valkey , true )
1490
- if err != nil {
1491
- return err
1492
- }
1493
-
1494
1509
// connect to the first node!
1495
1510
opt := valkeyClient.ClientOption {
1496
1511
InitAddress : []string {valkey .Name + "-0." + valkey .Name + "-headless." + valkey .Namespace + ".svc:6379" },
1497
- Password : password ,
1512
+ }
1513
+ if ! valkey .Spec .AnonymousAuth {
1514
+ var err error
1515
+ opt .Password , err = r .upsertSecret (ctx , valkey , true )
1516
+ if err != nil {
1517
+ return err
1518
+ }
1498
1519
}
1499
1520
if valkey .Spec .TLS {
1500
1521
ca , err := r .getCACertificate (ctx , valkey )
@@ -1836,28 +1857,6 @@ func (r *ValkeyReconciler) exporter(valkey *hyperv1.Valkey) corev1.Container {
1836
1857
Name : "VALKEY_ADDR" ,
1837
1858
Value : "valkey://127.0.0.1:6379" ,
1838
1859
},
1839
- {
1840
- Name : "VALKEY_PASSWORD" ,
1841
- ValueFrom : & corev1.EnvVarSource {
1842
- SecretKeyRef : & corev1.SecretKeySelector {
1843
- Key : "password" ,
1844
- LocalObjectReference : corev1.LocalObjectReference {
1845
- Name : valkey .Name ,
1846
- },
1847
- },
1848
- },
1849
- },
1850
- {
1851
- Name : "REDIS_PASSWORD" ,
1852
- ValueFrom : & corev1.EnvVarSource {
1853
- SecretKeyRef : & corev1.SecretKeySelector {
1854
- Key : "password" ,
1855
- LocalObjectReference : corev1.LocalObjectReference {
1856
- Name : valkey .Name ,
1857
- },
1858
- },
1859
- },
1860
- },
1861
1860
{
1862
1861
Name : "VALKEY_EXPORTER_WEB_LISTEN_ADDRESS" ,
1863
1862
Value : ":9121" ,
@@ -1894,6 +1893,30 @@ func (r *ValkeyReconciler) exporter(valkey *hyperv1.Valkey) corev1.Container {
1894
1893
},
1895
1894
},
1896
1895
}
1896
+ if ! valkey .Spec .AnonymousAuth {
1897
+ container .Env = append (container .Env , corev1.EnvVar {
1898
+ Name : "VALKEY_PASSWORD" ,
1899
+ ValueFrom : & corev1.EnvVarSource {
1900
+ SecretKeyRef : & corev1.SecretKeySelector {
1901
+ Key : "password" ,
1902
+ LocalObjectReference : corev1.LocalObjectReference {
1903
+ Name : valkey .Name ,
1904
+ },
1905
+ },
1906
+ },
1907
+ })
1908
+ container .Env = append (container .Env , corev1.EnvVar {
1909
+ Name : "REDIS_PASSWORD" ,
1910
+ ValueFrom : & corev1.EnvVarSource {
1911
+ SecretKeyRef : & corev1.SecretKeySelector {
1912
+ Key : "password" ,
1913
+ LocalObjectReference : corev1.LocalObjectReference {
1914
+ Name : valkey .Name ,
1915
+ },
1916
+ },
1917
+ },
1918
+ })
1919
+ }
1897
1920
if valkey .Spec .TLS {
1898
1921
container .VolumeMounts = append (container .VolumeMounts , corev1.VolumeMount {
1899
1922
Name : "valkey-tls" ,
@@ -2100,7 +2123,7 @@ func (r *ValkeyReconciler) upsertStatefulSet(ctx context.Context, valkey *hyperv
2100
2123
Command : []string {
2101
2124
"valkey-server" ,
2102
2125
"/valkey/etc/valkey.conf" ,
2103
- "--requirepass " , "$(VALKEY_PASSWORD) " ,
2126
+ "--protected-mode " , "no " ,
2104
2127
},
2105
2128
Env : []corev1.EnvVar {
2106
2129
{
@@ -2115,28 +2138,6 @@ func (r *ValkeyReconciler) upsertStatefulSet(ctx context.Context, valkey *hyperv
2115
2138
Name : "VALKEY_NODES" ,
2116
2139
Value : getNodeNames (valkey ),
2117
2140
},
2118
- {
2119
- Name : "REDISCLI_AUTH" ,
2120
- ValueFrom : & corev1.EnvVarSource {
2121
- SecretKeyRef : & corev1.SecretKeySelector {
2122
- Key : "password" ,
2123
- LocalObjectReference : corev1.LocalObjectReference {
2124
- Name : valkey .Name ,
2125
- },
2126
- },
2127
- },
2128
- },
2129
- {
2130
- Name : "VALKEY_PASSWORD" ,
2131
- ValueFrom : & corev1.EnvVarSource {
2132
- SecretKeyRef : & corev1.SecretKeySelector {
2133
- Key : "password" ,
2134
- LocalObjectReference : corev1.LocalObjectReference {
2135
- Name : valkey .Name ,
2136
- },
2137
- },
2138
- },
2139
- },
2140
2141
{
2141
2142
Name : "VALKEY_CLUSTER_PREFERRED_ENDPOINT_TYPE" ,
2142
2143
Value : endpointType ,
@@ -2334,6 +2335,35 @@ func (r *ValkeyReconciler) upsertStatefulSet(ctx context.Context, valkey *hyperv
2334
2335
},
2335
2336
})
2336
2337
}
2338
+ if ! valkey .Spec .AnonymousAuth {
2339
+ sts .Spec .Template .Spec .Containers [0 ].Env = append (sts .Spec .Template .Spec .Containers [0 ].Env , corev1.EnvVar {
2340
+ Name : "REDISCLI_AUTH" ,
2341
+ ValueFrom : & corev1.EnvVarSource {
2342
+ SecretKeyRef : & corev1.SecretKeySelector {
2343
+ Key : "password" ,
2344
+ LocalObjectReference : corev1.LocalObjectReference {
2345
+ Name : valkey .Name ,
2346
+ },
2347
+ },
2348
+ },
2349
+ })
2350
+ sts .Spec .Template .Spec .Containers [0 ].Env = append (sts .Spec .Template .Spec .Containers [0 ].Env , corev1.EnvVar {
2351
+ Name : "VALKEY_PASSWORD" ,
2352
+ ValueFrom : & corev1.EnvVarSource {
2353
+ SecretKeyRef : & corev1.SecretKeySelector {
2354
+ Key : "password" ,
2355
+ LocalObjectReference : corev1.LocalObjectReference {
2356
+ Name : valkey .Name ,
2357
+ },
2358
+ },
2359
+ },
2360
+ })
2361
+ sts .Spec .Template .Spec .Containers [0 ].Command = []string {
2362
+ "valkey-server" ,
2363
+ "/valkey/etc/valkey.conf" ,
2364
+ "--requirepass" , "$(VALKEY_PASSWORD)" ,
2365
+ }
2366
+ }
2337
2367
if valkey .Spec .ExternalAccess != nil && valkey .Spec .ExternalAccess .Enabled {
2338
2368
sts .Spec .Template .Spec .Containers [0 ].Env = append (sts .Spec .Template .Spec .Containers [0 ].Env , corev1.EnvVar {
2339
2369
Name : "VALKEY_EXTERNAL_ACCESS" ,
0 commit comments