Skip to content

Commit 1c67f34

Browse files
feat: migrate flagd startup argument to sources flag (#427)
Signed-off-by: Kavindu Dodanduwa <[email protected]>
1 parent 651c63c commit 1c67f34

11 files changed

+346
-161
lines changed

apis/core/v1alpha1/flagsourceconfiguration_types.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ const (
5353
SyncProviderKubernetes SyncProviderType = "kubernetes"
5454
SyncProviderFilepath SyncProviderType = "filepath"
5555
SyncProviderHttp SyncProviderType = "http"
56+
SyncProviderGrpc SyncProviderType = "grpc"
5657
SyncProviderFlagdProxy SyncProviderType = "flagd-proxy"
5758
)
5859

@@ -124,14 +125,32 @@ type FlagSourceConfigurationSpec struct {
124125
}
125126

126127
type Source struct {
128+
// Source is a URI of the flag sources
127129
Source string `json:"source"`
130+
131+
// Provider type - kubernetes, http, grpc or filepath
128132
// +optional
129133
Provider SyncProviderType `json:"provider"`
134+
135+
// HttpSyncBearerToken is a bearer token. Used by http(s) sync provider only
130136
// +optional
131137
HttpSyncBearerToken string `json:"httpSyncBearerToken"`
132-
// LogFormat allows for the sidecar log format to be overridden, defaults to 'json'
138+
139+
// TLS - Enable/Disable secure TLS connectivity. Currently used only by GRPC sync
133140
// +optional
134-
LogFormat string `json:"logFormat"`
141+
TLS bool `json:"tls"`
142+
143+
// CertPath is a path of a certificate to be used by grpc TLS connection
144+
// +optional
145+
CertPath string `json:"certPath"`
146+
147+
// ProviderID is an identifier to be used in grpc provider
148+
// +optional
149+
ProviderID string `json:"providerID"`
150+
151+
// Selector is a flag configuration selector used by grpc provider
152+
// +optional
153+
Selector string `json:"selector,omitempty"`
135154
}
136155

137156
// FlagSourceConfigurationStatus defines the observed state of FlagSourceConfiguration
@@ -351,6 +370,10 @@ func (s SyncProviderType) IsFilepath() bool {
351370
return s == SyncProviderFilepath
352371
}
353372

373+
func (s SyncProviderType) IsGrpc() bool {
374+
return s == SyncProviderGrpc
375+
}
376+
354377
func (s SyncProviderType) IsFlagdProxy() bool {
355378
return s == SyncProviderFlagdProxy
356379
}

apis/core/v1alpha1/flagsourceconfiguration_types_test.go

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@ func Test_FLagSourceConfiguration_SyncProvider(t *testing.T) {
1212
k := SyncProviderKubernetes
1313
f := SyncProviderFilepath
1414
h := SyncProviderHttp
15+
g := SyncProviderGrpc
1516

1617
require.True(t, k.IsKubernetes())
1718
require.True(t, f.IsFilepath())
1819
require.True(t, h.IsHttp())
20+
require.True(t, g.IsGrpc())
1921

2022
require.False(t, f.IsKubernetes())
2123
require.False(t, h.IsFilepath())
22-
require.False(t, k.IsHttp())
24+
require.False(t, k.IsGrpc())
25+
require.False(t, g.IsHttp())
2326
}
2427

2528
func Test_FLagSourceConfiguration_envVarKey(t *testing.T) {
@@ -103,10 +106,12 @@ func Test_FLagSourceConfiguration_Merge(t *testing.T) {
103106
Tag: "tag",
104107
Sources: []Source{
105108
{
106-
Source: "src1",
107-
Provider: SyncProviderKubernetes,
108-
HttpSyncBearerToken: "token1",
109-
LogFormat: "log1",
109+
Source: "src1",
110+
Provider: SyncProviderGrpc,
111+
TLS: true,
112+
CertPath: "etc/cert.ca",
113+
ProviderID: "app",
114+
Selector: "source=database",
110115
},
111116
},
112117
SyncProviderArgs: []string{"arg1", "arg2"},
@@ -140,10 +145,12 @@ func Test_FLagSourceConfiguration_Merge(t *testing.T) {
140145
Tag: "tag",
141146
Sources: []Source{
142147
{
143-
Source: "src1",
144-
Provider: SyncProviderKubernetes,
145-
HttpSyncBearerToken: "token1",
146-
LogFormat: "log1",
148+
Source: "src1",
149+
Provider: SyncProviderGrpc,
150+
TLS: true,
151+
CertPath: "etc/cert.ca",
152+
ProviderID: "app",
153+
Selector: "source=database",
147154
},
148155
},
149156
SyncProviderArgs: []string{"arg1", "arg2"},
@@ -175,10 +182,8 @@ func Test_FLagSourceConfiguration_Merge(t *testing.T) {
175182
Tag: "tag1",
176183
Sources: []Source{
177184
{
178-
Source: "src2",
179-
Provider: SyncProviderFilepath,
180-
HttpSyncBearerToken: "token2",
181-
LogFormat: "log2",
185+
Source: "src2",
186+
Provider: SyncProviderFilepath,
182187
},
183188
},
184189
SyncProviderArgs: []string{"arg3", "arg4"},
@@ -220,16 +225,16 @@ func Test_FLagSourceConfiguration_Merge(t *testing.T) {
220225
Tag: "tag1",
221226
Sources: []Source{
222227
{
223-
Source: "src1",
224-
Provider: SyncProviderKubernetes,
225-
HttpSyncBearerToken: "token1",
226-
LogFormat: "log1",
228+
Source: "src1",
229+
Provider: SyncProviderGrpc,
230+
TLS: true,
231+
CertPath: "etc/cert.ca",
232+
ProviderID: "app",
233+
Selector: "source=database",
227234
},
228235
{
229-
Source: "src2",
230-
Provider: SyncProviderFilepath,
231-
HttpSyncBearerToken: "token2",
232-
LogFormat: "log2",
236+
Source: "src2",
237+
Provider: SyncProviderFilepath,
233238
},
234239
},
235240
SyncProviderArgs: []string{"arg1", "arg2", "arg3", "arg4"},

apis/core/v1alpha2/flagsourceconfiguration_conversion_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ func TestFlagSourceConfiguration_ConvertFrom(t *testing.T) {
4242
Source: "source",
4343
Provider: "provider",
4444
HttpSyncBearerToken: "token",
45-
LogFormat: "log2",
45+
TLS: false,
46+
CertPath: "/tmp/path",
47+
ProviderID: "myapp",
48+
Selector: "source=database",
4649
},
4750
},
4851
EnvVars: []corev1.EnvVar{

apis/core/v1alpha3/flagsourceconfiguration_conversion.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,12 @@ func (src *FlagSourceConfiguration) ConvertTo(dstRaw conversion.Hub) error {
3939
for _, sp := range src.Spec.Sources {
4040
sources = append(sources, v1alpha1.Source{
4141
Source: sp.Source,
42-
HttpSyncBearerToken: sp.HttpSyncBearerToken,
4342
Provider: v1alpha1.SyncProviderType(sp.Provider),
43+
HttpSyncBearerToken: sp.HttpSyncBearerToken,
44+
TLS: sp.TLS,
45+
CertPath: sp.CertPath,
46+
ProviderID: sp.ProviderID,
47+
Selector: sp.Selector,
4448
})
4549
}
4650

@@ -77,8 +81,12 @@ func (dst *FlagSourceConfiguration) ConvertFrom(srcRaw conversion.Hub) error {
7781
for _, sp := range src.Spec.Sources {
7882
sources = append(sources, Source{
7983
Source: sp.Source,
80-
Provider: string(sp.Provider),
84+
Provider: SyncProviderType(sp.Provider),
8185
HttpSyncBearerToken: sp.HttpSyncBearerToken,
86+
TLS: sp.TLS,
87+
CertPath: sp.CertPath,
88+
ProviderID: sp.ProviderID,
89+
Selector: sp.Selector,
8290
})
8391
}
8492

apis/core/v1alpha3/flagsourceconfiguration_conversion_test.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ func TestFlagSourceConfiguration_ConvertFrom(t *testing.T) {
4242
Source: "source",
4343
Provider: "provider",
4444
HttpSyncBearerToken: "token",
45-
LogFormat: "log2",
45+
TLS: true,
46+
CertPath: "etc/cert.ca",
47+
ProviderID: "app",
48+
Selector: "source=database",
4649
},
4750
},
4851
EnvVars: []corev1.EnvVar{
@@ -79,6 +82,10 @@ func TestFlagSourceConfiguration_ConvertFrom(t *testing.T) {
7982
Source: "source",
8083
Provider: "provider",
8184
HttpSyncBearerToken: "token",
85+
TLS: true,
86+
CertPath: "etc/cert.ca",
87+
ProviderID: "app",
88+
Selector: "source=database",
8289
},
8390
},
8491
EnvVars: []corev1.EnvVar{
@@ -148,6 +155,10 @@ func TestFlagSourceConfiguration_ConvertTo(t *testing.T) {
148155
Source: "source",
149156
Provider: "provider",
150157
HttpSyncBearerToken: "token",
158+
TLS: false,
159+
CertPath: "etc/cert.ca",
160+
ProviderID: "app",
161+
Selector: "source=database",
151162
},
152163
},
153164
EnvVars: []corev1.EnvVar{
@@ -184,7 +195,10 @@ func TestFlagSourceConfiguration_ConvertTo(t *testing.T) {
184195
Source: "source",
185196
Provider: "provider",
186197
HttpSyncBearerToken: "token",
187-
LogFormat: "",
198+
TLS: false,
199+
CertPath: "etc/cert.ca",
200+
ProviderID: "app",
201+
Selector: "source=database",
188202
},
189203
},
190204
EnvVars: []corev1.EnvVar{

apis/core/v1alpha3/flagsourceconfiguration_types.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,32 @@ type FlagSourceConfigurationSpec struct {
9191
}
9292

9393
type Source struct {
94+
// Source is a URI of the flag sources
9495
Source string `json:"source"`
96+
97+
// Provider type - kubernetes, http(s), grpc(s) or filepath
9598
// +optional
96-
Provider string `json:"provider"`
99+
Provider SyncProviderType `json:"provider"`
100+
101+
// HttpSyncBearerToken is a bearer token. Used by http(s) sync provider only
97102
// +optional
98103
HttpSyncBearerToken string `json:"httpSyncBearerToken"`
104+
105+
// TLS - Enable/Disable secure TLS connectivity. Currently used only by GRPC sync
106+
// +optional
107+
TLS bool `json:"tls"`
108+
109+
// CertPath is a path of a certificate to be used by grpc TLS connection
110+
// +optional
111+
CertPath string `json:"certPath"`
112+
113+
// ProviderID is an identifier to be used in grpc provider
114+
// +optional
115+
ProviderID string `json:"providerID"`
116+
117+
// Selector is a flag configuration selector used by grpc provider
118+
// +optional
119+
Selector string `json:"selector,omitempty"`
99120
}
100121

101122
// FlagSourceConfigurationStatus defines the observed state of FlagSourceConfiguration

config/crd/bases/core.openfeature.dev_flagsourceconfigurations.yaml

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,16 +194,32 @@ spec:
194194
to be applied to the sidecar
195195
items:
196196
properties:
197-
httpSyncBearerToken:
197+
certPath:
198+
description: CertPath is a path of a certificate to be used
199+
by grpc TLS connection
198200
type: string
199-
logFormat:
200-
description: LogFormat allows for the sidecar log format to
201-
be overridden, defaults to 'json'
201+
httpSyncBearerToken:
202+
description: HttpSyncBearerToken is a bearer token. Used by
203+
http(s) sync provider only
202204
type: string
203205
provider:
206+
description: Provider type - kubernetes, http, grpc or filepath
207+
type: string
208+
providerID:
209+
description: ProviderID is an identifier to be used in grpc
210+
provider
211+
type: string
212+
selector:
213+
description: Selector is a flag configuration selector used
214+
by grpc provider
204215
type: string
205216
source:
217+
description: Source is a URI of the flag sources
206218
type: string
219+
tls:
220+
description: TLS - Enable/Disable secure TLS connectivity. Currently
221+
used only by GRPC sync
222+
type: boolean
207223
required:
208224
- source
209225
type: object
@@ -480,12 +496,33 @@ spec:
480496
configuration to be applied to the sidecar
481497
items:
482498
properties:
499+
certPath:
500+
description: CertPath is a path of a certificate to be used
501+
by grpc TLS connection
502+
type: string
483503
httpSyncBearerToken:
504+
description: HttpSyncBearerToken is a bearer token. Used by
505+
http(s) sync provider only
484506
type: string
485507
provider:
508+
description: Provider type - kubernetes, http(s), grpc(s) or
509+
filepath
510+
type: string
511+
providerID:
512+
description: ProviderID is an identifier to be used in grpc
513+
provider
514+
type: string
515+
selector:
516+
description: Selector is a flag configuration selector used
517+
by grpc provider
486518
type: string
487519
source:
520+
description: Source is a URI of the flag sources
488521
type: string
522+
tls:
523+
description: TLS - Enable/Disable secure TLS connectivity. Currently
524+
used only by GRPC sync
525+
type: boolean
489526
required:
490527
- source
491528
type: object

docs/flag_source_configuration.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,15 @@ The relevant `FlagSourceConfigurations` are passed to the operator by setting th
5757

5858
## Source Fields
5959

60-
| Field | Behavior | Type |
61-
|---------------------|---------------------------------------------------------------------------------------------------------------------------------------|-------------------|
62-
| Source | Defines the URI of the flag source, this can be either a `host:port` or the `namespace/name` of a `FeatureFlagConfiguration` | `string` |
63-
| Provider | Defines the provider to be used, can be set to `kubernetes`, `filepath` or `http`. If not provided the default sync provider is used. | optional `string` |
64-
| HttpSyncBearerToken | Defines the bearer token to be used with a `http` sync. Has no effect if `Provider` is not `http` | optional `string` |
60+
| Field | Behavior | Type |
61+
|---------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------|-------------------|
62+
| Source | Defines the URI of the flag source, this can be either a `host:port` or the `namespace/name` of a `FeatureFlagConfiguration` | `string` |
63+
| Provider | Defines the provider to be used, can be set to `kubernetes`, `filepath`, `http(s)` or `grpc(s)`. If not provided the default sync provider is used. | optional `string` |
64+
| HttpSyncBearerToken | Defines the bearer token to be used with a `http` sync. Has no effect if `Provider` is not `http` | optional `string` |
65+
| TLS | Enable/Disable secure TLS connectivity. Currently used only by GRPC sync | optional `string` |
66+
| CertPath | Defines the certificate path to be used by grpc TLS connectivity. Has no effect on other `Provider` types | optional `string` |
67+
| ProviderID | Defines the identifier for grpc connection. Has no effect on other `Provider` types | optional `string` |
68+
| Selector | Defines the flag configuration selection criteria for grpc connection. Has no effect on other `Provider` types | optional `string` |
6569

6670
> The flagd-proxy provider type is experimental, documentation can be found [here](./kube_flagd_proxy.md)
6771

docs/getting_started.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ kubectl describe pod busybox-curl-7bd5767999-spf7v
120120
Host Port: 0/TCP
121121
Args:
122122
start
123-
--uri
124-
core.openfeature.dev/default/featureflagconfiguration-sample
123+
--sources
124+
- '[{"uri":"default/featureflagconfiguration-sample","provider":"kubernetes"}]'
125125
Environment:
126126
FLAGD_METRICS_PORT: 8014
127127
```

0 commit comments

Comments
 (0)