Skip to content

Commit 1a11f6a

Browse files
feat: add valueFrom field handling in envVars for FeatureFlagSource and InProcessConfiguration
1 parent e6d6be9 commit 1a11f6a

5 files changed

Lines changed: 195 additions & 13 deletions

File tree

api/core/v1beta1/featureflagsource_types.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,17 @@ func (fc *FeatureFlagSourceSpec) ToEnvVars() []corev1.EnvVar {
221221
envs := []corev1.EnvVar{}
222222

223223
for _, envVar := range fc.EnvVars {
224-
envs = append(envs, corev1.EnvVar{
225-
Name: fc.decorateEnvVarName(envVar.Name),
226-
Value: envVar.Value,
227-
})
224+
newEnvVar := corev1.EnvVar{
225+
Name: fc.decorateEnvVarName(envVar.Name),
226+
}
227+
228+
if envVar.Value != "" {
229+
newEnvVar.Value = envVar.Value
230+
} else if envVar.ValueFrom != nil {
231+
newEnvVar.ValueFrom = envVar.ValueFrom
232+
}
233+
234+
envs = append(envs, newEnvVar)
228235
}
229236

230237
// default values are always included in the envVars

api/core/v1beta1/featureflagsource_types_test.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,43 @@ func Test_FLagSourceConfiguration_ToEnvVars(t *testing.T) {
180180
Name: "env2",
181181
Value: "val2",
182182
},
183+
{
184+
Name: "configMapKeyRef",
185+
ValueFrom: &v1.EnvVarSource{
186+
ConfigMapKeyRef: &v1.ConfigMapKeySelector{
187+
LocalObjectReference: v1.LocalObjectReference{
188+
Name: "configMapName",
189+
},
190+
},
191+
},
192+
},
193+
{
194+
Name: "fieldRef",
195+
ValueFrom: &v1.EnvVarSource{
196+
FieldRef: &v1.ObjectFieldSelector{
197+
FieldPath: "fieldPath",
198+
},
199+
},
200+
},
201+
{
202+
Name: "resourceFieldRef",
203+
ValueFrom: &v1.EnvVarSource{
204+
ResourceFieldRef: &v1.ResourceFieldSelector{
205+
ContainerName: "containerName",
206+
Resource: "resourceField",
207+
},
208+
},
209+
},
210+
{
211+
Name: "secretKeyRef",
212+
ValueFrom: &v1.EnvVarSource{
213+
SecretKeyRef: &v1.SecretKeySelector{
214+
LocalObjectReference: v1.LocalObjectReference{
215+
Name: "secretName",
216+
},
217+
},
218+
},
219+
},
183220
{
184221
Name: "AZURE_STORAGE_ACCOUNT",
185222
Value: "account123",
@@ -206,6 +243,43 @@ func Test_FLagSourceConfiguration_ToEnvVars(t *testing.T) {
206243
Name: "PRE_env2",
207244
Value: "val2",
208245
},
246+
{
247+
Name: "PRE_configMapKeyRef",
248+
ValueFrom: &v1.EnvVarSource{
249+
ConfigMapKeyRef: &v1.ConfigMapKeySelector{
250+
LocalObjectReference: v1.LocalObjectReference{
251+
Name: "configMapName",
252+
},
253+
},
254+
},
255+
},
256+
{
257+
Name: "PRE_fieldRef",
258+
ValueFrom: &v1.EnvVarSource{
259+
FieldRef: &v1.ObjectFieldSelector{
260+
FieldPath: "fieldPath",
261+
},
262+
},
263+
},
264+
{
265+
Name: "PRE_resourceFieldRef",
266+
ValueFrom: &v1.EnvVarSource{
267+
ResourceFieldRef: &v1.ResourceFieldSelector{
268+
ContainerName: "containerName",
269+
Resource: "resourceField",
270+
},
271+
},
272+
},
273+
{
274+
Name: "PRE_secretKeyRef",
275+
ValueFrom: &v1.EnvVarSource{
276+
SecretKeyRef: &v1.SecretKeySelector{
277+
LocalObjectReference: v1.LocalObjectReference{
278+
Name: "secretName",
279+
},
280+
},
281+
},
282+
},
209283
{
210284
Name: "AZURE_STORAGE_ACCOUNT",
211285
Value: "account123",

api/core/v1beta1/inprocessconfiguration_types.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,17 @@ func (fc *InProcessConfigurationSpec) ToEnvVars() []corev1.EnvVar {
146146
envs := []corev1.EnvVar{}
147147

148148
for _, envVar := range fc.EnvVars {
149-
envs = append(envs, corev1.EnvVar{
150-
Name: common.EnvVarKey(fc.EnvVarPrefix, envVar.Name),
151-
Value: envVar.Value,
152-
})
149+
newEnvVar := corev1.EnvVar{
150+
Name: common.EnvVarKey(fc.EnvVarPrefix, envVar.Name),
151+
}
152+
153+
if envVar.Value != "" {
154+
newEnvVar.Value = envVar.Value
155+
} else if envVar.ValueFrom != nil {
156+
newEnvVar.ValueFrom = envVar.ValueFrom
157+
}
158+
159+
envs = append(envs, newEnvVar)
153160
}
154161

155162
// default values are always included in the envVars

api/core/v1beta1/inprocessconfiguration_types_test.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,43 @@ func Test_InProcessConfiguration_ToEnvVars(t *testing.T) {
116116
Name: "env2",
117117
Value: "val2",
118118
},
119+
{
120+
Name: "configMapKeyRef",
121+
ValueFrom: &v1.EnvVarSource{
122+
ConfigMapKeyRef: &v1.ConfigMapKeySelector{
123+
LocalObjectReference: v1.LocalObjectReference{
124+
Name: "configMapName",
125+
},
126+
},
127+
},
128+
},
129+
{
130+
Name: "fieldRef",
131+
ValueFrom: &v1.EnvVarSource{
132+
FieldRef: &v1.ObjectFieldSelector{
133+
FieldPath: "fieldPath",
134+
},
135+
},
136+
},
137+
{
138+
Name: "resourceFieldRef",
139+
ValueFrom: &v1.EnvVarSource{
140+
ResourceFieldRef: &v1.ResourceFieldSelector{
141+
ContainerName: "containerName",
142+
Resource: "resourceField",
143+
},
144+
},
145+
},
146+
{
147+
Name: "secretKeyRef",
148+
ValueFrom: &v1.EnvVarSource{
149+
SecretKeyRef: &v1.SecretKeySelector{
150+
LocalObjectReference: v1.LocalObjectReference{
151+
Name: "secretName",
152+
},
153+
},
154+
},
155+
},
119156
},
120157
EnvVarPrefix: "PRE",
121158
Port: 33,
@@ -137,6 +174,43 @@ func Test_InProcessConfiguration_ToEnvVars(t *testing.T) {
137174
Name: "PRE_env2",
138175
Value: "val2",
139176
},
177+
{
178+
Name: "PRE_configMapKeyRef",
179+
ValueFrom: &v1.EnvVarSource{
180+
ConfigMapKeyRef: &v1.ConfigMapKeySelector{
181+
LocalObjectReference: v1.LocalObjectReference{
182+
Name: "configMapName",
183+
},
184+
},
185+
},
186+
},
187+
{
188+
Name: "PRE_fieldRef",
189+
ValueFrom: &v1.EnvVarSource{
190+
FieldRef: &v1.ObjectFieldSelector{
191+
FieldPath: "fieldPath",
192+
},
193+
},
194+
},
195+
{
196+
Name: "PRE_resourceFieldRef",
197+
ValueFrom: &v1.EnvVarSource{
198+
ResourceFieldRef: &v1.ResourceFieldSelector{
199+
ContainerName: "containerName",
200+
Resource: "resourceField",
201+
},
202+
},
203+
},
204+
{
205+
Name: "PRE_secretKeyRef",
206+
ValueFrom: &v1.EnvVarSource{
207+
SecretKeyRef: &v1.SecretKeySelector{
208+
LocalObjectReference: v1.LocalObjectReference{
209+
Name: "secretName",
210+
},
211+
},
212+
},
213+
},
140214
{
141215
Name: "PRE_HOST",
142216
Value: "host",

docs/feature_flag_source.md

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,32 @@ Given below is an example configuration with provider type `azblob` and supporte
9191
sources:
9292
- source: azblob://my-bucket/test.json # my-bucket - container name
9393
provider: azblob
94-
envVars:
95-
- name: AZURE_STORAGE_ACCOUNT
96-
value: <account_name>
97-
- name: AZURE_STORAGE_SAS_TOKEN
98-
value: <SAS token>
94+
envVars:
95+
- name: AZURE_STORAGE_ACCOUNT
96+
value: <account_name>
97+
- name: AZURE_STORAGE_SAS_TOKEN
98+
value: <SAS token>
9999
```
100+
101+
Alternative way to provide credentials is to use Kubernetes secrets, for example:
102+
103+
```yaml
104+
sources:
105+
- source: azblob://my-bucket/test.json # my-bucket - container name
106+
provider: azblob
107+
envVars:
108+
- name: AZURE_STORAGE_ACCOUNT
109+
valueFrom:
110+
secretKeyRef:
111+
name: my-secret
112+
key: account_name
113+
- name: AZURE_STORAGE_SAS_TOKEN
114+
valueFrom:
115+
secretKeyRef:
116+
name: my-secret
117+
key: sas_token
118+
```
119+
100120
Other type of credentials for Azure Blob Storage are supported, for details (see [AZ credentials config](https://pkg.go.dev/gocloud.dev/blob/azureblob#hdr-URLs))
101121

102122
## Sidecar configurations

0 commit comments

Comments
 (0)