Skip to content

Commit 7c666fb

Browse files
committed
Update env var name
1 parent da5ce42 commit 7c666fb

5 files changed

+14
-50
lines changed

controllers/limitador_controller.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ func (r *LimitadorReconciler) getDeploymentOptions(ctx context.Context, limObj *
318318
deploymentOptions.VolumeMounts = limitador.DeploymentVolumeMounts(deploymentStorageOptions)
319319
deploymentOptions.Volumes = limitador.DeploymentVolumes(limObj, deploymentStorageOptions)
320320
deploymentOptions.DeploymentStrategy = deploymentStorageOptions.DeploymentStrategy
321-
deploymentOptions.EnvVar, err = r.getDeploymentEnvVar(ctx, limObj)
321+
deploymentOptions.EnvVar, err = r.getDeploymentEnvVar(limObj)
322322
if err != nil {
323323
return deploymentOptions, err
324324
}
@@ -346,14 +346,14 @@ func (r *LimitadorReconciler) getDeploymentStorageOptions(ctx context.Context, l
346346
return limitador.InMemoryDeploymentOptions()
347347
}
348348

349-
func (r *LimitadorReconciler) getDeploymentEnvVar(ctx context.Context, limObj *limitadorv1alpha1.Limitador) ([]v1.EnvVar, error) {
349+
func (r *LimitadorReconciler) getDeploymentEnvVar(limObj *limitadorv1alpha1.Limitador) ([]v1.EnvVar, error) {
350350
if limObj.Spec.Storage != nil {
351351
if limObj.Spec.Storage.Redis != nil {
352-
return limitador.DeploymentEnvVar(ctx, r.Client(), limObj.Namespace, limObj.Spec.Storage.Redis.ConfigSecretRef)
352+
return limitador.DeploymentEnvVar(limObj.Namespace, limObj.Spec.Storage.Redis.ConfigSecretRef)
353353
}
354354

355355
if limObj.Spec.Storage.RedisCached != nil {
356-
return limitador.DeploymentEnvVar(ctx, r.Client(), limObj.Namespace, limObj.Spec.Storage.RedisCached.ConfigSecretRef)
356+
return limitador.DeploymentEnvVar(limObj.Namespace, limObj.Spec.Storage.RedisCached.ConfigSecretRef)
357357
}
358358
}
359359

controllers/limitador_controller_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ var _ = Describe("Limitador controller", func() {
776776
"limitador-server",
777777
"/home/limitador/etc/limitador-config.yaml",
778778
"redis",
779-
"$(URL)",
779+
"$(LIMITADOR_OPERATOR_REDIS_URL)",
780780
},
781781
),
782782
)
@@ -859,7 +859,7 @@ var _ = Describe("Limitador controller", func() {
859859
"limitador-server",
860860
"/home/limitador/etc/limitador-config.yaml",
861861
"redis_cached",
862-
"$(URL)",
862+
"$(LIMITADOR_OPERATOR_REDIS_URL)",
863863
"--ttl", "1",
864864
"--ratio", "2",
865865
"--flush-period", "3",

pkg/limitador/redis_cache_storage_options_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func TestRedisCachedDeploymentOptions(t *testing.T) {
8686
assert.NilError(subT, err)
8787
assert.DeepEqual(subT, options,
8888
DeploymentStorageOptions{
89-
Command: []string{"redis_cached", "$(URL)"},
89+
Command: []string{"redis_cached", "$(LIMITADOR_OPERATOR_REDIS_URL)"},
9090
},
9191
)
9292
})
@@ -116,7 +116,7 @@ func TestRedisCachedDeploymentOptions(t *testing.T) {
116116
DeploymentStorageOptions{
117117
Command: []string{
118118
"redis_cached",
119-
"$(URL)",
119+
"$(LIMITADOR_OPERATOR_REDIS_URL)",
120120
"--ttl", "1",
121121
"--ratio", "2",
122122
"--flush-period", "3",

pkg/limitador/redis_storage_options.go

+3-8
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,14 @@ func RedisDeploymentOptions(ctx context.Context, cl client.Client, defSecretName
2626
}, nil
2727
}
2828

29-
func DeploymentEnvVar(ctx context.Context, cl client.Client, defSecretNamespace string, configSecretRef *v1.ObjectReference) ([]v1.EnvVar, error) {
29+
func DeploymentEnvVar(defSecretNamespace string, configSecretRef *v1.ObjectReference) ([]v1.EnvVar, error) {
3030
if configSecretRef == nil {
3131
return nil, errors.New("there's no ConfigSecretRef set")
3232
}
3333

34-
_, err := getURLFromRedisSecret(ctx, cl, defSecretNamespace, *configSecretRef)
35-
if err != nil {
36-
return nil, err
37-
}
38-
3934
env := []v1.EnvVar{
4035
{
41-
Name: "URL",
36+
Name: "LIMITADOR_OPERATOR_REDIS_URL",
4237
ValueFrom: &v1.EnvVarSource{
4338
SecretKeyRef: &v1.SecretKeySelector{
4439
Key: "URL",
@@ -73,7 +68,7 @@ func getURLFromRedisSecret(ctx context.Context, cl client.Client, defSecretNames
7368

7469
// nil map behaves as empty map when reading
7570
if _, ok := secret.Data["URL"]; ok {
76-
return "$(URL)", nil
71+
return "$(LIMITADOR_OPERATOR_REDIS_URL)", nil
7772
}
7873

7974
return "", errors.New("the storage config Secret doesn't have the `URL` field")

pkg/limitador/redis_storage_options_test.go

+3-34
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,14 @@ func TestRedisDeploymentOptions(t *testing.T) {
9696
assert.NilError(subT, err)
9797
assert.DeepEqual(subT, options,
9898
DeploymentStorageOptions{
99-
Command: []string{"redis", "$(URL)"},
99+
Command: []string{"redis", "$(LIMITADOR_OPERATOR_REDIS_URL)"},
100100
},
101101
)
102102
})
103103
}
104104

105105
func TestDeploymentEnvVar(t *testing.T) {
106106
type args struct {
107-
ctx context.Context
108-
cl client.Client
109107
defSecretNamespace string
110108
configSecretRef *v1.ObjectReference
111109
}
@@ -122,30 +120,11 @@ func TestDeploymentEnvVar(t *testing.T) {
122120
wantErr: true,
123121
error: "there's no ConfigSecretRef set",
124122
},
125-
{
126-
name: "Getting URL from Redis Secret fails",
127-
want: nil,
128-
wantErr: true,
129-
error: "doesn't have the `URL` field",
130-
args: args{
131-
ctx: context.TODO(),
132-
cl: fake.NewClientBuilder().WithObjects(&v1.Secret{
133-
ObjectMeta: metav1.ObjectMeta{
134-
Name: "test",
135-
Namespace: "test",
136-
},
137-
}).Build(),
138-
defSecretNamespace: "test",
139-
configSecretRef: &v1.ObjectReference{
140-
Name: "test",
141-
},
142-
},
143-
},
144123
{
145124
name: "Receive correct Env settings",
146125
want: []v1.EnvVar{
147126
{
148-
Name: "URL",
127+
Name: "LIMITADOR_OPERATOR_REDIS_URL",
149128
ValueFrom: &v1.EnvVarSource{
150129
SecretKeyRef: &v1.SecretKeySelector{
151130
LocalObjectReference: v1.LocalObjectReference{
@@ -158,16 +137,6 @@ func TestDeploymentEnvVar(t *testing.T) {
158137
},
159138
wantErr: false,
160139
args: args{
161-
ctx: context.TODO(),
162-
cl: fake.NewClientBuilder().WithObjects(&v1.Secret{
163-
ObjectMeta: metav1.ObjectMeta{
164-
Name: "test",
165-
Namespace: "test",
166-
},
167-
Data: map[string][]byte{
168-
"URL": []byte("cmVkaXM6Ly9yZWRpcy5kZWZhdWx0LnN2Yy5jbHVzdGVyLmxvY2FsLzA="),
169-
},
170-
}).Build(),
171140
defSecretNamespace: "test",
172141
configSecretRef: &v1.ObjectReference{
173142
Name: "test",
@@ -177,7 +146,7 @@ func TestDeploymentEnvVar(t *testing.T) {
177146
}
178147
for _, tt := range tests {
179148
t.Run(tt.name, func(t *testing.T) {
180-
got, err := DeploymentEnvVar(tt.args.ctx, tt.args.cl, tt.args.defSecretNamespace, tt.args.configSecretRef)
149+
got, err := DeploymentEnvVar(tt.args.defSecretNamespace, tt.args.configSecretRef)
181150
if (err != nil) != tt.wantErr {
182151
t.Errorf("DeploymentEnvVar() error = %v, wantErr %v", err, tt.wantErr)
183152
return

0 commit comments

Comments
 (0)