Skip to content

Commit 7cba7e1

Browse files
feat: default sync provider configuration (#320)
Signed-off-by: James Milligan <[email protected]>
1 parent b04928b commit 7cba7e1

File tree

12 files changed

+112
-59
lines changed

12 files changed

+112
-59
lines changed

apis/core/v1alpha1/featureflagconfiguration_types.go

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ type FlagDSpec struct {
5353
}
5454

5555
type FeatureFlagSyncProvider struct {
56-
Name string `json:"name"`
56+
Name SyncProviderType `json:"name"`
5757
// +optional
5858
// +nullable
5959
HttpSyncConfiguration *HttpSyncConfiguration `json:"httpSyncConfiguration"`
@@ -67,18 +67,6 @@ type HttpSyncConfiguration struct {
6767
BearerToken string `json:"bearerToken,omitempty"`
6868
}
6969

70-
func (ffsp FeatureFlagSyncProvider) IsKubernetes() bool {
71-
return ffsp.Name == "kubernetes"
72-
}
73-
74-
func (ffsp FeatureFlagSyncProvider) IsHttp() bool {
75-
return ffsp.Name == "http"
76-
}
77-
78-
func (ffsp FeatureFlagSyncProvider) IsFilepath() bool {
79-
return ffsp.Name == "filepath"
80-
}
81-
8270
type FeatureFlagServiceProvider struct {
8371
// +kubebuilder:validation:Enum=flagd
8472
Name string `json:"name"`

apis/core/v1alpha1/flagsourceconfiguration_types.go

Lines changed: 54 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,30 @@ import (
2626
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2727
)
2828

29+
type SyncProviderType string
30+
2931
const (
30-
SidecarEnvVarPrefix string = "SIDECAR_ENV_VAR_PREFIX"
31-
SidecarMetricPortEnvVar string = "METRICS_PORT"
32-
SidecarPortEnvVar string = "PORT"
33-
SidecarSocketPathEnvVar string = "SOCKET_PATH"
34-
SidecarEvaluatorEnvVar string = "EVALUATOR"
35-
SidecarImageEnvVar string = "IMAGE"
36-
SidecarVersionEnvVar string = "TAG"
37-
SidecarProviderArgsEnvVar string = "PROVIDER_ARGS"
38-
defaultSidecarEnvVarPrefix string = "FLAGD"
39-
InputConfigurationEnvVarPrefix string = "SIDECAR"
40-
defaultMetricPort int32 = 8014
41-
defaultPort int32 = 8013
42-
defaultSocketPath string = ""
43-
defaultEvaluator string = "json"
44-
defaultImage string = "ghcr.io/open-feature/flagd"
45-
defaultTag string = "v0.3.1"
32+
SidecarEnvVarPrefix string = "SIDECAR_ENV_VAR_PREFIX"
33+
SidecarMetricPortEnvVar string = "METRICS_PORT"
34+
SidecarPortEnvVar string = "PORT"
35+
SidecarSocketPathEnvVar string = "SOCKET_PATH"
36+
SidecarEvaluatorEnvVar string = "EVALUATOR"
37+
SidecarImageEnvVar string = "IMAGE"
38+
SidecarVersionEnvVar string = "TAG"
39+
SidecarProviderArgsEnvVar string = "PROVIDER_ARGS"
40+
SidecarDefaultSyncProviderEnvVar string = "SYNC_PROVIDER"
41+
defaultSidecarEnvVarPrefix string = "FLAGD"
42+
InputConfigurationEnvVarPrefix string = "SIDECAR"
43+
defaultMetricPort int32 = 8014
44+
defaultPort int32 = 8013
45+
defaultSocketPath string = ""
46+
defaultEvaluator string = "json"
47+
defaultImage string = "ghcr.io/open-feature/flagd"
48+
defaultTag string = "v0.3.1"
49+
SyncProviderKubernetes SyncProviderType = "kubernetes"
50+
SyncProviderFilepath SyncProviderType = "filepath"
51+
SyncProviderHttp SyncProviderType = "http"
52+
defaultSyncProvider = SyncProviderKubernetes
4653
)
4754

4855
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
@@ -80,17 +87,22 @@ type FlagSourceConfigurationSpec struct {
8087
// Tag to be appended to the sidecar image, defaults to 'main'
8188
// +optional
8289
Tag string `json:"tag"`
90+
91+
// DefaultSyncProvider defines the default sync provider
92+
// +optional
93+
DefaultSyncProvider SyncProviderType `json:"defaultSyncProvider"`
8394
}
8495

8596
func NewFlagSourceConfigurationSpec() (*FlagSourceConfigurationSpec, error) {
8697
fsc := &FlagSourceConfigurationSpec{
87-
MetricsPort: defaultMetricPort,
88-
Port: defaultPort,
89-
SocketPath: defaultSocketPath,
90-
SyncProviderArgs: []string{},
91-
Evaluator: defaultEvaluator,
92-
Image: defaultImage,
93-
Tag: defaultTag,
98+
MetricsPort: defaultMetricPort,
99+
Port: defaultPort,
100+
SocketPath: defaultSocketPath,
101+
SyncProviderArgs: []string{},
102+
Evaluator: defaultEvaluator,
103+
Image: defaultImage,
104+
Tag: defaultTag,
105+
DefaultSyncProvider: SyncProviderKubernetes,
94106
}
95107

96108
if metricsPort := os.Getenv(fmt.Sprintf("%s_%s", InputConfigurationEnvVarPrefix, SidecarMetricPortEnvVar)); metricsPort != "" {
@@ -129,6 +141,10 @@ func NewFlagSourceConfigurationSpec() (*FlagSourceConfigurationSpec, error) {
129141
fsc.SyncProviderArgs = strings.Split(syncProviderArgs, ",") // todo: add documentation for this
130142
}
131143

144+
if syncProvider := os.Getenv(fmt.Sprintf("%s_%s", InputConfigurationEnvVarPrefix, SidecarDefaultSyncProviderEnvVar)); syncProvider != "" {
145+
fsc.DefaultSyncProvider = SyncProviderType(syncProvider)
146+
}
147+
132148
return fsc, nil
133149
}
134150

@@ -157,6 +173,9 @@ func (fc *FlagSourceConfigurationSpec) Merge(new *FlagSourceConfigurationSpec) {
157173
if new.SyncProviderArgs != nil && len(new.SyncProviderArgs) > 0 {
158174
fc.SyncProviderArgs = append(fc.SyncProviderArgs, new.SyncProviderArgs...)
159175
}
176+
if new.DefaultSyncProvider != "" {
177+
fc.DefaultSyncProvider = new.DefaultSyncProvider
178+
}
160179
}
161180

162181
func (fc *FlagSourceConfigurationSpec) ToEnvVars() []corev1.EnvVar {
@@ -229,3 +248,15 @@ type FlagSourceConfigurationList struct {
229248
func init() {
230249
SchemeBuilder.Register(&FlagSourceConfiguration{}, &FlagSourceConfigurationList{})
231250
}
251+
252+
func (s SyncProviderType) IsKubernetes() bool {
253+
return s == SyncProviderKubernetes
254+
}
255+
256+
func (s SyncProviderType) IsHttp() bool {
257+
return s == SyncProviderHttp
258+
}
259+
260+
func (s SyncProviderType) IsFilepath() bool {
261+
return s == SyncProviderFilepath
262+
}

apis/core/v1alpha2/featureflagconfiguration_conversion.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (src *FeatureFlagConfiguration) ConvertTo(dstRaw conversion.Hub) error {
4343
}
4444

4545
if src.Spec.SyncProvider != nil {
46-
dst.Spec.SyncProvider = &v1alpha1.FeatureFlagSyncProvider{Name: src.Spec.SyncProvider.Name}
46+
dst.Spec.SyncProvider = &v1alpha1.FeatureFlagSyncProvider{Name: v1alpha1.SyncProviderType(src.Spec.SyncProvider.Name)}
4747
if src.Spec.SyncProvider.HttpSyncConfiguration != nil {
4848
dst.Spec.SyncProvider.HttpSyncConfiguration = &v1alpha1.HttpSyncConfiguration{
4949
Target: src.Spec.SyncProvider.HttpSyncConfiguration.Target,
@@ -79,7 +79,7 @@ func (dst *FeatureFlagConfiguration) ConvertFrom(srcRaw conversion.Hub) error {
7979

8080
if src.Spec.SyncProvider != nil {
8181
dst.Spec.SyncProvider = &FeatureFlagSyncProvider{
82-
Name: src.Spec.SyncProvider.Name,
82+
Name: string(src.Spec.SyncProvider.Name),
8383
}
8484
if src.Spec.SyncProvider.HttpSyncConfiguration != nil {
8585
dst.Spec.SyncProvider.HttpSyncConfiguration = &HttpSyncConfiguration{

apis/core/v1alpha2/flagsourceconfiguration_conversion.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,14 @@ func (src *FlagSourceConfiguration) ConvertTo(dstRaw conversion.Hub) error {
3333

3434
dst.ObjectMeta = src.ObjectMeta
3535
dst.Spec = v1alpha1.FlagSourceConfigurationSpec{
36-
MetricsPort: src.Spec.MetricsPort,
37-
Port: src.Spec.Port,
38-
SocketPath: src.Spec.SocketPath,
39-
SyncProviderArgs: src.Spec.SyncProviderArgs,
40-
Evaluator: src.Spec.Evaluator,
41-
Image: src.Spec.Image,
42-
Tag: src.Spec.Tag,
36+
MetricsPort: src.Spec.MetricsPort,
37+
Port: src.Spec.Port,
38+
SocketPath: src.Spec.SocketPath,
39+
SyncProviderArgs: src.Spec.SyncProviderArgs,
40+
Evaluator: src.Spec.Evaluator,
41+
Image: src.Spec.Image,
42+
Tag: src.Spec.Tag,
43+
DefaultSyncProvider: v1alpha1.SyncProviderType(src.Spec.DefaultSyncProvider),
4344
}
4445
return nil
4546
}
@@ -49,13 +50,14 @@ func (dst *FlagSourceConfiguration) ConvertFrom(srcRaw conversion.Hub) error {
4950

5051
dst.ObjectMeta = src.ObjectMeta
5152
dst.Spec = FlagSourceConfigurationSpec{
52-
MetricsPort: src.Spec.MetricsPort,
53-
Port: src.Spec.Port,
54-
SocketPath: src.Spec.SocketPath,
55-
SyncProviderArgs: src.Spec.SyncProviderArgs,
56-
Evaluator: src.Spec.Evaluator,
57-
Image: src.Spec.Image,
58-
Tag: src.Spec.Tag,
53+
MetricsPort: src.Spec.MetricsPort,
54+
Port: src.Spec.Port,
55+
SocketPath: src.Spec.SocketPath,
56+
SyncProviderArgs: src.Spec.SyncProviderArgs,
57+
Evaluator: src.Spec.Evaluator,
58+
Image: src.Spec.Image,
59+
Tag: src.Spec.Tag,
60+
DefaultSyncProvider: string(src.Spec.DefaultSyncProvider),
5961
}
6062
return nil
6163
}

apis/core/v1alpha2/flagsourceconfiguration_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ type FlagSourceConfigurationSpec struct {
5555
// Tag to be appended to the sidecar image, defaults to 'main'
5656
// +optional
5757
Tag string `json:"tag"`
58+
59+
// DefaultSyncProvider defines the default sync provider
60+
// +optional
61+
DefaultSyncProvider string `json:"defaultSyncProvider"`
5862
}
5963

6064
// FlagSourceConfigurationStatus defines the observed state of FlagSourceConfiguration

chart/open-feature-operator/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ The command removes all the Kubernetes components associated with the chart and
4949
| `sidecarConfiguration.port` | 8013 | Sets the value of the `XXX_PORT` environment variable for the injected sidecar container.|
5050
| `sidecarConfiguration.metricsPort` | 8014 | Sets the value of the `XXX_METRICS_PORT` environment variable for the injected sidecar container.|
5151
| `sidecarConfiguration.socketPath` | `""` | Sets the value of the `XXX_SOCKET_PATH` environment variable for the injected sidecar container.|
52-
| `sidecarConfiguration.repository` | `ghcr.io/open-feature/flagd` | Sets the image for the injected sidecar container. |
53-
| `sidecarConfiguration.tag` | current flagd version: `v0.3.2` | Sets the version tag for the injected sidecar container. |
52+
| `sidecarConfiguration.image.repository` | `ghcr.io/open-feature/flagd` | Sets the image for the injected sidecar container. |
53+
| `sidecarConfiguration.image.tag` | current flagd version: `v0.3.2` | Sets the version tag for the injected sidecar container. |
5454
| `sidecarConfiguration.providerArgs` | `""` | Used to append arguments to the sidecar startup command. This value is a comma separated string of key values separated by '=', e.g. `key=value,key2=value2` results in the appending of `--sync-provider-args key=value --sync-provider-args key2=value2` |
55+
| `sidecarConfiguration.defaultSyncProvider` | `kubernetes` | Sets the value of the `XXX_SYNC_PROVIDER` environment variable for the injected sidecar container. There are 3 valid sync providers: `kubernetes`, `filepath` and `http` |
5556

5657
### Operator resource configuration
5758
<!-- x-release-please-start-version -->

chart/open-feature-operator/templates/rendered.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,9 @@ spec:
607607
description: FlagSourceConfigurationSpec defines the desired state of
608608
FlagSourceConfiguration
609609
properties:
610+
defaultSyncProvider:
611+
description: DefaultSyncProvider defines the default sync provider
612+
type: string
610613
evaluator:
611614
description: Evaluator sets an evaluator, defaults to 'json'
612615
type: string
@@ -668,6 +671,9 @@ spec:
668671
description: FlagSourceConfigurationSpec defines the desired state of
669672
FlagSourceConfiguration
670673
properties:
674+
defaultSyncProvider:
675+
description: DefaultSyncProvider defines the default sync provider
676+
type: string
671677
evaluator:
672678
description: Evaluator sets an evaluator, defaults to 'json'
673679
type: string
@@ -1035,6 +1041,8 @@ spec:
10351041
value: '{{ .Values.sidecarConfiguration.providerArgs }}'
10361042
- name: SIDECAR_ENV_VAR_PREFIX
10371043
value: '{{ .Values.sidecarConfiguration.envVarPrefix }}'
1044+
- name: SIDECAR_SYNC_PROVIDER
1045+
value: '{{ .Values.sidecarConfiguration.defaultSyncProvider }}'
10381046
image: '{{ .Values.controllerManager.manager.image.repository }}:{{ .Values.controllerManager.manager.image.tag
10391047
}}'
10401048
imagePullPolicy: IfNotPresent

chart/open-feature-operator/values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ sidecarConfiguration:
1111
tag: v0.3.2
1212
providerArgs: ""
1313
envVarPrefix: "FLAGD"
14+
defaultSyncProvider: kubernetes
1415

1516
controllerManager:
1617
kubeRbacProxy:

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ spec:
3939
description: FlagSourceConfigurationSpec defines the desired state of
4040
FlagSourceConfiguration
4141
properties:
42+
defaultSyncProvider:
43+
description: DefaultSyncProvider defines the default sync provider
44+
type: string
4245
evaluator:
4346
description: Evaluator sets an evaluator, defaults to 'json'
4447
type: string
@@ -100,6 +103,9 @@ spec:
100103
description: FlagSourceConfigurationSpec defines the desired state of
101104
FlagSourceConfiguration
102105
properties:
106+
defaultSyncProvider:
107+
description: DefaultSyncProvider defines the default sync provider
108+
type: string
103109
evaluator:
104110
description: Evaluator sets an evaluator, defaults to 'json'
105111
type: string

config/overlays/helm/manager.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ spec:
3232
value: "{{ .Values.sidecarConfiguration.providerArgs }}"
3333
- name: SIDECAR_ENV_VAR_PREFIX
3434
value: "{{ .Values.sidecarConfiguration.envVarPrefix }}"
35+
- name: SIDECAR_SYNC_PROVIDER
36+
value: "{{ .Values.sidecarConfiguration.defaultSyncProvider }}"
3537
- name: kube-rbac-proxy
3638
image: "{{ .Values.controllerManager.kubeRbacProxy.image.repository }}:{{ .Values.controllerManager.kubeRbacProxy.image.tag }}"
3739
resources:

0 commit comments

Comments
 (0)