Skip to content

Commit bc09d91

Browse files
authored
added the sync provider and reworked, implemented the injection code … (#44)
* added the sync provider and reworked, implemented the injection code into flagd Signed-off-by: Alex Jones <[email protected]> * Adding comments Signed-off-by: Alex Jones <[email protected]> * removed controller update Signed-off-by: Alex Jones <[email protected]> * lowercasing flagd Signed-off-by: Alex Jones <[email protected]> * lowercasing flagd Signed-off-by: Alex Jones <[email protected]>
1 parent 73117a9 commit bc09d91

File tree

8 files changed

+81
-29
lines changed

8 files changed

+81
-29
lines changed

apis/core/v1alpha1/featureflagconfiguration_types.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,20 @@ type FeatureFlagConfigurationSpec struct {
3131
// Important: Run "make" to regenerate code after modifying this file
3232
// +optional
3333
// +nullable
34-
Provider *FeatureFlagProvider `json:"provider"`
34+
ServiceProvider *FeatureFlagServiceProvider `json:"serviceProvider"`
35+
// +optional
36+
// +nullable
37+
SyncProvider *FeatureFlagSyncProvider `json:"syncProvider"`
3538
// FeatureFlagSpec is the json representation of the feature flag
3639
FeatureFlagSpec string `json:"featureFlagSpec,omitempty"`
3740
}
3841

39-
type FeatureFlagProvider struct {
40-
// +kubebuilder:validation:Enum=flagD
42+
type FeatureFlagSyncProvider struct {
43+
// +kubebuilder:validation:Enum=filepath
44+
Name string `json:"name"`
45+
}
46+
type FeatureFlagServiceProvider struct {
47+
// +kubebuilder:validation:Enum=flagd
4148
Name string `json:"name"`
4249
// +optional
4350
// +nullable

apis/core/v1alpha1/zz_generated.deepcopy.go

Lines changed: 27 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ spec:
4141
description: FeatureFlagSpec is the json representation of the feature
4242
flag
4343
type: string
44-
provider:
44+
serviceProvider:
4545
description: 'INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
4646
Important: Run "make" to regenerate code after modifying this file'
4747
nullable: true
@@ -109,7 +109,17 @@ spec:
109109
type: object
110110
name:
111111
enum:
112-
- flagD
112+
- flagd
113+
type: string
114+
required:
115+
- name
116+
type: object
117+
syncProvider:
118+
nullable: true
119+
properties:
120+
name:
121+
enum:
122+
- filepath
113123
type: string
114124
required:
115125
- name

config/samples/crds/custom_provider.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ kind: FeatureFlagConfiguration
33
metadata:
44
name: featureflagconfiguration-sample
55
spec:
6-
provider:
7-
name: "flagD"
6+
serviceProvider:
7+
name: "flagd"
88
credentials:
99
name: "sample-provider-secret"
1010
namespace: "default"

controllers/featureflagconfiguration_controller.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,13 @@ func (r *FeatureFlagConfigurationReconciler) Reconcile(ctx context.Context, req
105105
}
106106

107107
// Check the provider on the FeatureFlagConfiguration
108-
if ffconf.Spec.Provider == nil {
109-
r.Log.Info("No provider specified for FeatureFlagConfiguration, using FlagD")
110-
ffconf.Spec.Provider = &corev1alpha1.FeatureFlagProvider{
108+
if ffconf.Spec.ServiceProvider == nil {
109+
r.Log.Info("No service provider specified for FeatureFlagConfiguration, using FlagD")
110+
ffconf.Spec.ServiceProvider = &corev1alpha1.FeatureFlagServiceProvider{
111111
Name: "flagD",
112112
}
113113
if err := r.Update(ctx, ffconf); err != nil {
114-
r.Log.Error(err, "Failed to update FeatureFlagConfiguration Provider")
114+
r.Log.Error(err, "Failed to update FeatureFlagConfiguration service provider")
115115
return r.finishReconcile(err, false)
116116
}
117117
}

schemas

webhooks/featureflagconfiguration_webhook.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ func (m *FeatureFlagConfigurationValidator) Handle(ctx context.Context, req admi
4848
}
4949
}
5050

51-
if config.Spec.Provider != nil && config.Spec.Provider.Credentials != nil {
51+
if config.Spec.ServiceProvider != nil && config.Spec.ServiceProvider.Credentials != nil {
5252
// Check the provider and whether it has an existing secret
5353
providerKeySecret := corev1.Secret{}
54-
if err := m.Client.Get(ctx, client.ObjectKey{Name: config.Spec.Provider.Credentials.Name,
55-
Namespace: config.Spec.Provider.Credentials.Namespace}, &providerKeySecret); errors.IsNotFound(err) {
54+
if err := m.Client.Get(ctx, client.ObjectKey{Name: config.Spec.ServiceProvider.Credentials.Name,
55+
Namespace: config.Spec.ServiceProvider.Credentials.Namespace}, &providerKeySecret); errors.IsNotFound(err) {
5656
return admission.Denied("credentials secret not found")
5757
}
5858
}

webhooks/pod_webhook.go

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ func (m *PodMutator) Handle(ctx context.Context, req admission.Request) admissio
8484
}
8585
}
8686

87-
marshaledPod, err := m.injectSidecar(pod, val)
87+
// Check to see whether the FeatureFlagConfiguration has service or sync overrides
88+
ff := m.getFeatureFlag(ctx, val, req.Namespace)
89+
marshaledPod, err := m.injectSidecar(pod, val, &ff)
8890
if err != nil {
8991
return admission.Errored(http.StatusInternalServerError, err)
9092
}
@@ -136,7 +138,7 @@ func (m *PodMutator) getFeatureFlag(ctx context.Context, name string, namespace
136138
return ffConfig
137139
}
138140

139-
func (m *PodMutator) injectSidecar(pod *corev1.Pod, configMap string) ([]byte, error) {
141+
func (m *PodMutator) injectSidecar(pod *corev1.Pod, configMap string, featureFlag *corev1alpha1.FeatureFlagConfiguration) ([]byte, error) {
140142
m.Log.V(1).Info(fmt.Sprintf("Creating sidecar for pod %s/%s", pod.Namespace, pod.Name))
141143
// Inject the agent
142144
pod.Spec.Volumes = append(pod.Spec.Volumes, corev1.Volume{
@@ -149,12 +151,25 @@ func (m *PodMutator) injectSidecar(pod *corev1.Pod, configMap string) ([]byte, e
149151
},
150152
},
151153
})
154+
155+
commandSequence := []string{
156+
"start", "--uri", "/etc/flagd/config.json",
157+
}
158+
// FlagD is the default provider name externally
159+
if featureFlag.Spec.ServiceProvider != nil && featureFlag.Spec.ServiceProvider.Name != "flagd" {
160+
commandSequence = append(commandSequence, "--service-provider")
161+
commandSequence = append(commandSequence, "http")
162+
}
163+
// Adds the sync provider if it is set
164+
if featureFlag.Spec.SyncProvider != nil && featureFlag.Spec.SyncProvider.Name != "" {
165+
commandSequence = append(commandSequence, "--sync-provider")
166+
commandSequence = append(commandSequence, featureFlag.Spec.SyncProvider.Name)
167+
}
168+
152169
pod.Spec.Containers = append(pod.Spec.Containers, corev1.Container{
153-
Name: "flagd",
154-
Image: "ghcr.io/open-feature/flagd:" + FlagDTag,
155-
Args: []string{
156-
"start", "--uri", "/etc/flagd/config.json",
157-
},
170+
Name: "flagd",
171+
Image: "ghcr.io/open-feature/flagd:" + FlagDTag,
172+
Args: commandSequence,
158173
ImagePullPolicy: FlagDImagePullPolicy,
159174
VolumeMounts: []corev1.VolumeMount{
160175
{

0 commit comments

Comments
 (0)