Skip to content

Commit 4f0477c

Browse files
odubajDTtoddbaert
andauthored
fix: include parameters with default values to envVars (#648)
Signed-off-by: odubajDT <ondrej.dubaj@dynatrace.com> Co-authored-by: Todd Baert <toddbaert@gmail.com>
1 parent e627f11 commit 4f0477c

7 files changed

+95
-92
lines changed

apis/core/v1beta1/featureflagsource_types.go

+24-31
Original file line numberDiff line numberDiff line change
@@ -214,46 +214,39 @@ func (fc *FeatureFlagSourceSpec) ToEnvVars() []corev1.EnvVar {
214214
})
215215
}
216216

217-
if fc.ManagementPort != common.DefaultManagementPort {
218-
envs = append(envs, corev1.EnvVar{
219-
Name: common.EnvVarKey(fc.EnvVarPrefix, common.ManagementPortEnvVar),
220-
Value: fmt.Sprintf("%d", fc.ManagementPort),
221-
})
222-
}
223-
224-
if fc.Port != common.DefaultRPCPort {
225-
envs = append(envs, corev1.EnvVar{
226-
Name: common.EnvVarKey(fc.EnvVarPrefix, common.PortEnvVar),
227-
Value: fmt.Sprintf("%d", fc.Port),
228-
})
229-
}
217+
// default values are always included in the envVars
218+
envs = append(envs, corev1.EnvVar{
219+
Name: common.EnvVarKey(fc.EnvVarPrefix, common.ManagementPortEnvVar),
220+
Value: fmt.Sprintf("%d", fc.ManagementPort),
221+
})
230222

231-
if fc.Evaluator != common.DefaultEvaluator {
232-
envs = append(envs, corev1.EnvVar{
233-
Name: common.EnvVarKey(fc.EnvVarPrefix, common.EvaluatorEnvVar),
234-
Value: fc.Evaluator,
235-
})
236-
}
223+
envs = append(envs, corev1.EnvVar{
224+
Name: common.EnvVarKey(fc.EnvVarPrefix, common.PortEnvVar),
225+
Value: fmt.Sprintf("%d", fc.Port),
226+
})
237227

238-
if fc.SocketPath != "" {
239-
envs = append(envs, corev1.EnvVar{
240-
Name: common.EnvVarKey(fc.EnvVarPrefix, common.SocketPathEnvVar),
241-
Value: fc.SocketPath,
242-
})
243-
}
228+
envs = append(envs, corev1.EnvVar{
229+
Name: common.EnvVarKey(fc.EnvVarPrefix, common.EvaluatorEnvVar),
230+
Value: fc.Evaluator,
231+
})
244232

245-
if fc.LogFormat != common.DefaultLogFormat {
246-
envs = append(envs, corev1.EnvVar{
247-
Name: common.EnvVarKey(fc.EnvVarPrefix, common.LogFormatEnvVar),
248-
Value: fc.LogFormat,
249-
})
250-
}
233+
envs = append(envs, corev1.EnvVar{
234+
Name: common.EnvVarKey(fc.EnvVarPrefix, common.LogFormatEnvVar),
235+
Value: fc.LogFormat,
236+
})
251237

252238
// sets the FLAGD_RESOLVER var to "rpc" to configure the provider for RPC evaluation mode
253239
envs = append(envs, corev1.EnvVar{
254240
Name: common.EnvVarKey(fc.EnvVarPrefix, common.ResolverEnvVar),
255241
Value: common.RPCResolverType,
256242
})
257243

244+
if fc.SocketPath != "" {
245+
envs = append(envs, corev1.EnvVar{
246+
Name: common.EnvVarKey(fc.EnvVarPrefix, common.SocketPathEnvVar),
247+
Value: fc.SocketPath,
248+
})
249+
}
250+
258251
return envs
259252
}

apis/core/v1beta1/featureflagsource_types_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,6 @@ func Test_FLagSourceConfiguration_ToEnvVars(t *testing.T) {
210210
Name: "PRE_EVALUATOR",
211211
Value: "evaluator",
212212
},
213-
{
214-
Name: "PRE_SOCKET_PATH",
215-
Value: "socket-path",
216-
},
217213
{
218214
Name: "PRE_LOG_FORMAT",
219215
Value: "log",
@@ -222,6 +218,10 @@ func Test_FLagSourceConfiguration_ToEnvVars(t *testing.T) {
222218
Name: "PRE_RESOLVER",
223219
Value: "rpc",
224220
},
221+
{
222+
Name: "PRE_SOCKET_PATH",
223+
Value: "socket-path",
224+
},
225225
}
226226
require.Equal(t, expected, ff.Spec.ToEnvVars())
227227
}

apis/core/v1beta1/inprocessconfiguration_types.go

+29-38
Original file line numberDiff line numberDiff line change
@@ -152,26 +152,37 @@ func (fc *InProcessConfigurationSpec) ToEnvVars() []corev1.EnvVar {
152152
})
153153
}
154154

155-
if fc.Host != common.DefaultHost {
156-
envs = append(envs, corev1.EnvVar{
157-
Name: common.EnvVarKey(fc.EnvVarPrefix, common.HostEnvVar),
158-
Value: fc.Host,
159-
})
160-
}
155+
// default values are always included in the envVars
156+
envs = append(envs, corev1.EnvVar{
157+
Name: common.EnvVarKey(fc.EnvVarPrefix, common.HostEnvVar),
158+
Value: fc.Host,
159+
})
161160

162-
if fc.Port != common.DefaultInProcessPort {
163-
envs = append(envs, corev1.EnvVar{
164-
Name: common.EnvVarKey(fc.EnvVarPrefix, common.PortEnvVar),
165-
Value: fmt.Sprintf("%d", fc.Port),
166-
})
167-
}
161+
envs = append(envs, corev1.EnvVar{
162+
Name: common.EnvVarKey(fc.EnvVarPrefix, common.PortEnvVar),
163+
Value: fmt.Sprintf("%d", fc.Port),
164+
})
168165

169-
if fc.TLS != common.DefaultTLS {
170-
envs = append(envs, corev1.EnvVar{
171-
Name: common.EnvVarKey(fc.EnvVarPrefix, common.TLSEnvVar),
172-
Value: fmt.Sprintf("%t", fc.TLS),
173-
})
174-
}
166+
envs = append(envs, corev1.EnvVar{
167+
Name: common.EnvVarKey(fc.EnvVarPrefix, common.TLSEnvVar),
168+
Value: fmt.Sprintf("%t", fc.TLS),
169+
})
170+
171+
envs = append(envs, corev1.EnvVar{
172+
Name: common.EnvVarKey(fc.EnvVarPrefix, common.CacheEnvVar),
173+
Value: fc.Cache,
174+
})
175+
176+
envs = append(envs, corev1.EnvVar{
177+
Name: common.EnvVarKey(fc.EnvVarPrefix, common.CacheMaxSizeEnvVar),
178+
Value: fmt.Sprintf("%d", fc.CacheMaxSize),
179+
})
180+
181+
// sets the FLAGD_RESOLVER var to "in-process" to configure the provider for in-process evaluation mode
182+
envs = append(envs, corev1.EnvVar{
183+
Name: common.EnvVarKey(fc.EnvVarPrefix, common.ResolverEnvVar),
184+
Value: common.InProcessResolverType,
185+
})
175186

176187
if fc.SocketPath != "" {
177188
envs = append(envs, corev1.EnvVar{
@@ -194,25 +205,5 @@ func (fc *InProcessConfigurationSpec) ToEnvVars() []corev1.EnvVar {
194205
})
195206
}
196207

197-
if fc.Cache != common.DefaultCache {
198-
envs = append(envs, corev1.EnvVar{
199-
Name: common.EnvVarKey(fc.EnvVarPrefix, common.CacheEnvVar),
200-
Value: fc.Cache,
201-
})
202-
}
203-
204-
if fc.CacheMaxSize != int(common.DefaultCacheMaxSize) {
205-
envs = append(envs, corev1.EnvVar{
206-
Name: common.EnvVarKey(fc.EnvVarPrefix, common.CacheMaxSizeEnvVar),
207-
Value: fmt.Sprintf("%d", fc.CacheMaxSize),
208-
})
209-
}
210-
211-
// sets the FLAGD_RESOLVER var to "in-process" to configure the provider for in-process evaluation mode
212-
envs = append(envs, corev1.EnvVar{
213-
Name: common.EnvVarKey(fc.EnvVarPrefix, common.ResolverEnvVar),
214-
Value: common.InProcessResolverType,
215-
})
216-
217208
return envs
218209
}

apis/core/v1beta1/inprocessconfiguration_types_test.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -149,18 +149,6 @@ func Test_InProcessConfiguration_ToEnvVars(t *testing.T) {
149149
Name: "PRE_TLS",
150150
Value: "true",
151151
},
152-
{
153-
Name: "PRE_SOCKET_PATH",
154-
Value: "socket-path",
155-
},
156-
{
157-
Name: "PRE_OFFLINE_FLAG_SOURCE_PATH",
158-
Value: "path1",
159-
},
160-
{
161-
Name: "PRE_SOURCE_SELECTOR",
162-
Value: "selector",
163-
},
164152
{
165153
Name: "PRE_CACHE",
166154
Value: "cache",
@@ -173,6 +161,18 @@ func Test_InProcessConfiguration_ToEnvVars(t *testing.T) {
173161
Name: "PRE_RESOLVER",
174162
Value: "in-process",
175163
},
164+
{
165+
Name: "PRE_SOCKET_PATH",
166+
Value: "socket-path",
167+
},
168+
{
169+
Name: "PRE_OFFLINE_FLAG_SOURCE_PATH",
170+
Value: "path1",
171+
},
172+
{
173+
Name: "PRE_SOURCE_SELECTOR",
174+
Value: "selector",
175+
},
176176
}
177177
require.Equal(t, expected, ff.Spec.ToEnvVars())
178178
}

common/flagdinjector/flagdinjector_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,14 @@ func getExpectedPod(namespace string) v1.Pod {
800800
Name: "flagd_my-env-var",
801801
Value: "my-value",
802802
},
803+
{
804+
Name: "flagd_MANAGEMENT_PORT",
805+
Value: "8014",
806+
},
807+
{
808+
Name: "flagd_PORT",
809+
Value: "8013",
810+
},
803811
{
804812
Name: "flagd_EVALUATOR",
805813
Value: "",
@@ -829,6 +837,14 @@ func getExpectedPod(namespace string) v1.Pod {
829837
Name: "flagd_my-env-var",
830838
Value: "my-value",
831839
},
840+
{
841+
Name: "flagd_MANAGEMENT_PORT",
842+
Value: "8014",
843+
},
844+
{
845+
Name: "flagd_PORT",
846+
Value: "8013",
847+
},
832848
{
833849
Name: "flagd_EVALUATOR",
834850
Value: "",

test/e2e/chainsaw/in-process/00-assert.yaml

+10-6
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@ spec:
1717
- name: my-second-prefix_HOST
1818
value: my-host
1919
- name: my-second-prefix_PORT
20-
value: "2424"
20+
value: "8015"
2121
- name: my-second-prefix_TLS
2222
value: "true"
23-
- name: my-second-prefix_OFFLINE_FLAG_SOURCE_PATH
24-
value: my-path
23+
- name: my-second-prefix_CACHE
24+
value: "lru"
2525
- name: my-second-prefix_MAX_CACHE_SIZE
2626
value: "11"
2727
- name: my-second-prefix_RESOLVER
2828
value: in-process
29+
- name: my-second-prefix_OFFLINE_FLAG_SOURCE_PATH
30+
value: my-path
2931
- name: open-feature-e2e-test2
3032
image: busybox:1.36.1
3133
env:
@@ -36,12 +38,14 @@ spec:
3638
- name: my-second-prefix_HOST
3739
value: my-host
3840
- name: my-second-prefix_PORT
39-
value: "2424"
41+
value: "8015"
4042
- name: my-second-prefix_TLS
4143
value: "true"
42-
- name: my-second-prefix_OFFLINE_FLAG_SOURCE_PATH
43-
value: my-path
44+
- name: my-second-prefix_CACHE
45+
value: "lru"
4446
- name: my-second-prefix_MAX_CACHE_SIZE
4547
value: "11"
4648
- name: my-second-prefix_RESOLVER
4749
value: in-process
50+
- name: my-second-prefix_OFFLINE_FLAG_SOURCE_PATH
51+
value: my-path

test/e2e/chainsaw/in-process/00-install.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ kind: InProcessConfiguration
3232
metadata:
3333
name: source-configuration
3434
spec:
35-
port: 2424
3635
tls: true
3736
offlineFlagSourcePath: "my-path"
3837
cacheMaxSize: 11

0 commit comments

Comments
 (0)