From 946a73c8c476c8545d20d995d8e0c5591d1f7bd4 Mon Sep 17 00:00:00 2001 From: odubajDT Date: Thu, 16 Nov 2023 07:46:54 +0100 Subject: [PATCH] fix after rebase Signed-off-by: odubajDT --- .gitignore | 1 + Makefile | 2 +- .../featureflagconfiguration_types.go | 4 - .../featureflagconfiguration_types_test.go | 3 +- .../v1alpha1/flagsourceconfiguration_types.go | 4 +- .../flagsourceconfiguration_types_test.go | 2 +- apis/core/v1beta1/common.go | 11 - apis/core/v1beta1/common/common.go | 57 +++++ apis/core/v1beta1/common/common_test.go | 28 +++ apis/core/v1beta1/featureflag_types.go | 6 +- apis/core/v1beta1/featureflag_types_test.go | 8 +- apis/core/v1beta1/featureflagsource_types.go | 70 ++---- .../v1beta1/featureflagsource_types_test.go | 205 ++++++++---------- chart/open-feature-operator/values.yaml | 2 +- .../kuttl/fsconfig-file-sync/00-install.yaml | 2 +- .../kuttl/fsconfig-file-sync/01-assert.yaml | 2 +- 16 files changed, 216 insertions(+), 191 deletions(-) delete mode 100644 apis/core/v1beta1/common.go create mode 100644 apis/core/v1beta1/common/common.go create mode 100644 apis/core/v1beta1/common/common_test.go diff --git a/.gitignore b/.gitignore index cfd1841c7..07eea48dc 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,4 @@ testbin/* *.swo *~ +go.work diff --git a/Makefile b/Makefile index 6f2145991..e1a4a6f61 100644 --- a/Makefile +++ b/Makefile @@ -200,7 +200,7 @@ CRDOC ?= $(LOCALBIN)/crdoc KUSTOMIZE_VERSION ?= v4.5.7 # renovate: datasource=github-releases depName=kubernetes-sigs/controller-tools CONTROLLER_TOOLS_VERSION ?= v0.10.0 -CRDOC_VERSION ?= v0.6.2 +CRDOC_VERSION ?= v0.7.0 KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" .PHONY: kustomize diff --git a/apis/core/v1alpha1/featureflagconfiguration_types.go b/apis/core/v1alpha1/featureflagconfiguration_types.go index 75189e20b..ea9438f4c 100644 --- a/apis/core/v1alpha1/featureflagconfiguration_types.go +++ b/apis/core/v1alpha1/featureflagconfiguration_types.go @@ -129,11 +129,7 @@ func (ff *FeatureFlagConfiguration) GenerateConfigMap(name string, namespace str OwnerReferences: references, }, Data: map[string]string{ -<<<<<<< HEAD common.FeatureFlagConfigurationConfigMapKey(namespace, name): ff.Spec.FeatureFlagSpec, -======= - utils.FeatureFlagConfigMapKey(namespace, name): ff.Spec.FeatureFlagSpec, ->>>>>>> feat: use v1beta1 in operator logic }, } } diff --git a/apis/core/v1alpha1/featureflagconfiguration_types_test.go b/apis/core/v1alpha1/featureflagconfiguration_types_test.go index 23dac2ce6..c5cb1a9a9 100644 --- a/apis/core/v1alpha1/featureflagconfiguration_types_test.go +++ b/apis/core/v1alpha1/featureflagconfiguration_types_test.go @@ -2,12 +2,11 @@ package v1alpha1 import ( "github.com/open-feature/open-feature-operator/apis/core/v1alpha1/common" - "testing" - "github.com/stretchr/testify/require" corev1 "k8s.io/api/core/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" + "testing" ) func Test_FeatureFlagConfiguration(t *testing.T) { diff --git a/apis/core/v1alpha1/flagsourceconfiguration_types.go b/apis/core/v1alpha1/flagsourceconfiguration_types.go index a949cce4b..b8809edd6 100644 --- a/apis/core/v1alpha1/flagsourceconfiguration_types.go +++ b/apis/core/v1alpha1/flagsourceconfiguration_types.go @@ -18,11 +18,11 @@ package v1alpha1 import ( "fmt" - "github.com/open-feature/open-feature-operator/apis/core/v1alpha1/common" "os" "strconv" "strings" + "github.com/open-feature/open-feature-operator/apis/core/v1alpha1/common" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -49,7 +49,7 @@ const ( defaultEvaluator string = "json" defaultImage string = "ghcr.io/open-feature/flagd" // renovate: datasource=github-tags depName=open-feature/flagd/flagd - defaultTag string = "v0.6.3" + defaultTag string = "v0.7.0" defaultLogFormat string = "json" defaultProbesEnabled bool = true SyncProviderKubernetes SyncProviderType = "kubernetes" diff --git a/apis/core/v1alpha1/flagsourceconfiguration_types_test.go b/apis/core/v1alpha1/flagsourceconfiguration_types_test.go index ff7fb8639..57ddbeebb 100644 --- a/apis/core/v1alpha1/flagsourceconfiguration_types_test.go +++ b/apis/core/v1alpha1/flagsourceconfiguration_types_test.go @@ -1,9 +1,9 @@ package v1alpha1 import ( - "github.com/open-feature/open-feature-operator/apis/core/v1alpha1/common" "testing" + "github.com/open-feature/open-feature-operator/apis/core/v1alpha1/common" "github.com/stretchr/testify/require" v1 "k8s.io/api/core/v1" ) diff --git a/apis/core/v1beta1/common.go b/apis/core/v1beta1/common.go deleted file mode 100644 index c67656d3c..000000000 --- a/apis/core/v1beta1/common.go +++ /dev/null @@ -1,11 +0,0 @@ -package v1beta1 - -type SyncProviderType string - -const ( - SyncProviderKubernetes SyncProviderType = "kubernetes" - SyncProviderFilepath SyncProviderType = "file" - SyncProviderHttp SyncProviderType = "http" - SyncProviderGrpc SyncProviderType = "grpc" - SyncProviderFlagdProxy SyncProviderType = "flagd-proxy" -) diff --git a/apis/core/v1beta1/common/common.go b/apis/core/v1beta1/common/common.go new file mode 100644 index 000000000..2f2e2d872 --- /dev/null +++ b/apis/core/v1beta1/common/common.go @@ -0,0 +1,57 @@ +package common + +import "fmt" + +type SyncProviderType string + +const ( + SyncProviderKubernetes SyncProviderType = "kubernetes" + SyncProviderFilepath SyncProviderType = "file" + SyncProviderHttp SyncProviderType = "http" + SyncProviderGrpc SyncProviderType = "grpc" + SyncProviderFlagdProxy SyncProviderType = "flagd-proxy" +) + +func (s SyncProviderType) IsKubernetes() bool { + return s == SyncProviderKubernetes +} + +func (s SyncProviderType) IsHttp() bool { + return s == SyncProviderHttp +} + +func (s SyncProviderType) IsFilepath() bool { + return s == SyncProviderFilepath +} + +func (s SyncProviderType) IsGrpc() bool { + return s == SyncProviderGrpc +} + +func (s SyncProviderType) IsFlagdProxy() bool { + return s == SyncProviderFlagdProxy +} + +func TrueVal() *bool { + b := true + return &b +} + +func FalseVal() *bool { + b := false + return &b +} + +func EnvVarKey(prefix string, suffix string) string { + return fmt.Sprintf("%s_%s", prefix, suffix) +} + +// unique string used to create unique volume mount and file name +func FeatureFlagConfigurationId(namespace, name string) string { + return fmt.Sprintf("%s_%s", namespace, name) +} + +// unique key (and filename) for configMap data +func FeatureFlagConfigMapKey(namespace, name string) string { + return fmt.Sprintf("%s.flagd.json", FeatureFlagConfigurationId(namespace, name)) +} diff --git a/apis/core/v1beta1/common/common_test.go b/apis/core/v1beta1/common/common_test.go new file mode 100644 index 000000000..b9095f83c --- /dev/null +++ b/apis/core/v1beta1/common/common_test.go @@ -0,0 +1,28 @@ +package common + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func Test_FeatureFlagSource_SyncProvider(t *testing.T) { + k := SyncProviderKubernetes + f := SyncProviderFilepath + h := SyncProviderHttp + g := SyncProviderGrpc + + require.True(t, k.IsKubernetes()) + require.True(t, f.IsFilepath()) + require.True(t, h.IsHttp()) + require.True(t, g.IsGrpc()) + + require.False(t, f.IsKubernetes()) + require.False(t, h.IsFilepath()) + require.False(t, k.IsGrpc()) + require.False(t, g.IsHttp()) +} + +func Test_FLagSourceConfiguration_envVarKey(t *testing.T) { + require.Equal(t, "pre_suf", EnvVarKey("pre", "suf")) +} diff --git a/apis/core/v1beta1/featureflag_types.go b/apis/core/v1beta1/featureflag_types.go index 522ca3d04..bc76d881d 100644 --- a/apis/core/v1beta1/featureflag_types.go +++ b/apis/core/v1beta1/featureflag_types.go @@ -19,7 +19,7 @@ package v1beta1 import ( "encoding/json" - "github.com/open-feature/open-feature-operator/common/utils" + "github.com/open-feature/open-feature-operator/apis/core/v1beta1/common" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -93,7 +93,7 @@ func (ff *FeatureFlag) GetReference() metav1.OwnerReference { Kind: ff.Kind, Name: ff.Name, UID: ff.UID, - Controller: utils.TrueVal(), + Controller: common.TrueVal(), } } @@ -112,7 +112,7 @@ func (ff *FeatureFlag) GenerateConfigMap(name string, namespace string, referenc OwnerReferences: references, }, Data: map[string]string{ - utils.FeatureFlagConfigMapKey(namespace, name): string(b), + common.FeatureFlagConfigMapKey(namespace, name): string(b), }, }, nil } diff --git a/apis/core/v1beta1/featureflag_types_test.go b/apis/core/v1beta1/featureflag_types_test.go index fb7af9a37..d5bcc6514 100644 --- a/apis/core/v1beta1/featureflag_types_test.go +++ b/apis/core/v1beta1/featureflag_types_test.go @@ -3,7 +3,7 @@ package v1beta1 import ( "testing" - "github.com/open-feature/open-feature-operator/common/utils" + "github.com/open-feature/open-feature-operator/apis/core/v1beta1/common" "github.com/stretchr/testify/require" corev1 "k8s.io/api/core/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -21,7 +21,7 @@ func Test_FeatureFlag(t *testing.T) { Kind: "kind", Name: "ffconf1", UID: types.UID("5"), - Controller: utils.TrueVal(), + Controller: common.TrueVal(), }, }, }, @@ -37,7 +37,7 @@ func Test_FeatureFlag(t *testing.T) { Kind: ff.Kind, Name: ff.Name, UID: ff.UID, - Controller: utils.TrueVal(), + Controller: common.TrueVal(), }, ff.GetReference()) name := "cmname" @@ -48,7 +48,7 @@ func Test_FeatureFlag(t *testing.T) { Kind: "kind", Name: "ffconf1", UID: types.UID("5"), - Controller: utils.TrueVal(), + Controller: common.TrueVal(), }, } diff --git a/apis/core/v1beta1/featureflagsource_types.go b/apis/core/v1beta1/featureflagsource_types.go index 93494ee54..ecbca0ab8 100644 --- a/apis/core/v1beta1/featureflagsource_types.go +++ b/apis/core/v1beta1/featureflagsource_types.go @@ -22,7 +22,7 @@ import ( "strconv" "strings" - "github.com/open-feature/open-feature-operator/common/utils" + "github.com/open-feature/open-feature-operator/apis/core/v1beta1/common" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -47,7 +47,7 @@ const ( defaultEvaluator string = "json" defaultImage string = "ghcr.io/open-feature/flagd" // renovate: datasource=github-tags depName=open-feature/flagd/flagd - defaultTag string = "v0.6.3" + defaultTag string = "v0.7.0" defaultLogFormat string = "json" defaultProbesEnabled bool = true ) @@ -93,7 +93,7 @@ type FeatureFlagSourceSpec struct { // DefaultSyncProvider defines the default sync provider // +optional - DefaultSyncProvider SyncProviderType `json:"defaultSyncProvider"` + DefaultSyncProvider common.SyncProviderType `json:"defaultSyncProvider"` // LogFormat allows for the sidecar log format to be overridden, defaults to 'json' // +optional @@ -131,7 +131,7 @@ type Source struct { // Provider type - kubernetes, http(s), grpc(s) or filepath // +optional - Provider SyncProviderType `json:"provider"` + Provider common.SyncProviderType `json:"provider"` // HttpSyncBearerToken is a bearer token. Used by http(s) sync provider only // +optional @@ -185,26 +185,6 @@ func init() { SchemeBuilder.Register(&FeatureFlagSource{}, &FeatureFlagSourceList{}) } -func (s SyncProviderType) IsKubernetes() bool { - return s == SyncProviderKubernetes -} - -func (s SyncProviderType) IsHttp() bool { - return s == SyncProviderHttp -} - -func (s SyncProviderType) IsFilepath() bool { - return s == SyncProviderFilepath -} - -func (s SyncProviderType) IsGrpc() bool { - return s == SyncProviderGrpc -} - -func (s SyncProviderType) IsFlagdProxy() bool { - return s == SyncProviderFlagdProxy -} - //nolint:gocyclo func NewFeatureFlagSourceSpec() (*FeatureFlagSourceSpec, error) { fsc := &FeatureFlagSourceSpec{ @@ -217,11 +197,11 @@ func NewFeatureFlagSourceSpec() (*FeatureFlagSourceSpec, error) { Sources: []Source{}, EnvVars: []corev1.EnvVar{}, SyncProviderArgs: []string{}, - DefaultSyncProvider: SyncProviderKubernetes, + DefaultSyncProvider: common.SyncProviderKubernetes, EnvVarPrefix: defaultSidecarEnvVarPrefix, LogFormat: defaultLogFormat, RolloutOnChange: nil, - DebugLogging: utils.FalseVal(), + DebugLogging: common.FalseVal(), OtelCollectorUri: "", } @@ -229,7 +209,7 @@ func NewFeatureFlagSourceSpec() (*FeatureFlagSourceSpec, error) { probes := defaultProbesEnabled fsc.ProbesEnabled = &probes - if metricsPort := os.Getenv(envVarKey(InputConfigurationEnvVarPrefix, SidecarMetricPortEnvVar)); metricsPort != "" { + if metricsPort := os.Getenv(common.EnvVarKey(InputConfigurationEnvVarPrefix, SidecarMetricPortEnvVar)); metricsPort != "" { metricsPortI, err := strconv.Atoi(metricsPort) if err != nil { return fsc, fmt.Errorf("unable to parse metrics port value %s to int32: %w", metricsPort, err) @@ -237,7 +217,7 @@ func NewFeatureFlagSourceSpec() (*FeatureFlagSourceSpec, error) { fsc.MetricsPort = int32(metricsPortI) } - if port := os.Getenv(envVarKey(InputConfigurationEnvVarPrefix, SidecarPortEnvVar)); port != "" { + if port := os.Getenv(common.EnvVarKey(InputConfigurationEnvVarPrefix, SidecarPortEnvVar)); port != "" { portI, err := strconv.Atoi(port) if err != nil { return fsc, fmt.Errorf("unable to parse sidecar port value %s to int32: %w", port, err) @@ -245,31 +225,31 @@ func NewFeatureFlagSourceSpec() (*FeatureFlagSourceSpec, error) { fsc.Port = int32(portI) } - if socketPath := os.Getenv(envVarKey(InputConfigurationEnvVarPrefix, SidecarSocketPathEnvVar)); socketPath != "" { + if socketPath := os.Getenv(common.EnvVarKey(InputConfigurationEnvVarPrefix, SidecarSocketPathEnvVar)); socketPath != "" { fsc.SocketPath = socketPath } - if evaluator := os.Getenv(envVarKey(InputConfigurationEnvVarPrefix, SidecarEvaluatorEnvVar)); evaluator != "" { + if evaluator := os.Getenv(common.EnvVarKey(InputConfigurationEnvVarPrefix, SidecarEvaluatorEnvVar)); evaluator != "" { fsc.Evaluator = evaluator } - if image := os.Getenv(envVarKey(InputConfigurationEnvVarPrefix, SidecarImageEnvVar)); image != "" { + if image := os.Getenv(common.EnvVarKey(InputConfigurationEnvVarPrefix, SidecarImageEnvVar)); image != "" { fsc.Image = image } - if tag := os.Getenv(envVarKey(InputConfigurationEnvVarPrefix, SidecarVersionEnvVar)); tag != "" { + if tag := os.Getenv(common.EnvVarKey(InputConfigurationEnvVarPrefix, SidecarVersionEnvVar)); tag != "" { fsc.Tag = tag } - if syncProviderArgs := os.Getenv(envVarKey(InputConfigurationEnvVarPrefix, SidecarProviderArgsEnvVar)); syncProviderArgs != "" { + if syncProviderArgs := os.Getenv(common.EnvVarKey(InputConfigurationEnvVarPrefix, SidecarProviderArgsEnvVar)); syncProviderArgs != "" { fsc.SyncProviderArgs = strings.Split(syncProviderArgs, ",") // todo: add documentation for this } - if syncProvider := os.Getenv(envVarKey(InputConfigurationEnvVarPrefix, SidecarDefaultSyncProviderEnvVar)); syncProvider != "" { - fsc.DefaultSyncProvider = SyncProviderType(syncProvider) + if syncProvider := os.Getenv(common.EnvVarKey(InputConfigurationEnvVarPrefix, SidecarDefaultSyncProviderEnvVar)); syncProvider != "" { + fsc.DefaultSyncProvider = common.SyncProviderType(syncProvider) } - if logFormat := os.Getenv(envVarKey(InputConfigurationEnvVarPrefix, SidecarLogFormatEnvVar)); logFormat != "" { + if logFormat := os.Getenv(common.EnvVarKey(InputConfigurationEnvVarPrefix, SidecarLogFormatEnvVar)); logFormat != "" { fsc.LogFormat = logFormat } @@ -277,7 +257,7 @@ func NewFeatureFlagSourceSpec() (*FeatureFlagSourceSpec, error) { fsc.EnvVarPrefix = envVarPrefix } - if probesEnabled := os.Getenv(envVarKey(InputConfigurationEnvVarPrefix, SidecarProbesEnabledVar)); probesEnabled != "" { + if probesEnabled := os.Getenv(common.EnvVarKey(InputConfigurationEnvVarPrefix, SidecarProbesEnabledVar)); probesEnabled != "" { b, err := strconv.ParseBool(probesEnabled) if err != nil { return fsc, fmt.Errorf("unable to parse sidecar probes enabled %s to boolean: %w", probesEnabled, err) @@ -348,49 +328,45 @@ func (fc *FeatureFlagSourceSpec) ToEnvVars() []corev1.EnvVar { for _, envVar := range fc.EnvVars { envs = append(envs, corev1.EnvVar{ - Name: envVarKey(fc.EnvVarPrefix, envVar.Name), + Name: common.EnvVarKey(fc.EnvVarPrefix, envVar.Name), Value: envVar.Value, }) } if fc.MetricsPort != DefaultMetricPort { envs = append(envs, corev1.EnvVar{ - Name: envVarKey(fc.EnvVarPrefix, SidecarMetricPortEnvVar), + Name: common.EnvVarKey(fc.EnvVarPrefix, SidecarMetricPortEnvVar), Value: fmt.Sprintf("%d", fc.MetricsPort), }) } if fc.Port != defaultPort { envs = append(envs, corev1.EnvVar{ - Name: envVarKey(fc.EnvVarPrefix, SidecarPortEnvVar), + Name: common.EnvVarKey(fc.EnvVarPrefix, SidecarPortEnvVar), Value: fmt.Sprintf("%d", fc.Port), }) } if fc.Evaluator != defaultEvaluator { envs = append(envs, corev1.EnvVar{ - Name: envVarKey(fc.EnvVarPrefix, SidecarEvaluatorEnvVar), + Name: common.EnvVarKey(fc.EnvVarPrefix, SidecarEvaluatorEnvVar), Value: fc.Evaluator, }) } if fc.SocketPath != defaultSocketPath { envs = append(envs, corev1.EnvVar{ - Name: envVarKey(fc.EnvVarPrefix, SidecarSocketPathEnvVar), + Name: common.EnvVarKey(fc.EnvVarPrefix, SidecarSocketPathEnvVar), Value: fc.SocketPath, }) } if fc.LogFormat != defaultLogFormat { envs = append(envs, corev1.EnvVar{ - Name: envVarKey(fc.EnvVarPrefix, SidecarLogFormatEnvVar), + Name: common.EnvVarKey(fc.EnvVarPrefix, SidecarLogFormatEnvVar), Value: fc.LogFormat, }) } return envs } - -func envVarKey(prefix string, suffix string) string { - return fmt.Sprintf("%s_%s", prefix, suffix) -} diff --git a/apis/core/v1beta1/featureflagsource_types_test.go b/apis/core/v1beta1/featureflagsource_types_test.go index dfb2decef..0a62c366b 100644 --- a/apis/core/v1beta1/featureflagsource_types_test.go +++ b/apis/core/v1beta1/featureflagsource_types_test.go @@ -3,86 +3,11 @@ package v1beta1 import ( "testing" - "github.com/open-feature/open-feature-operator/common/utils" + "github.com/open-feature/open-feature-operator/apis/core/v1beta1/common" "github.com/stretchr/testify/require" v1 "k8s.io/api/core/v1" ) -func Test_FeatureFlagSource_SyncProvider(t *testing.T) { - k := SyncProviderKubernetes - f := SyncProviderFilepath - h := SyncProviderHttp - g := SyncProviderGrpc - - require.True(t, k.IsKubernetes()) - require.True(t, f.IsFilepath()) - require.True(t, h.IsHttp()) - require.True(t, g.IsGrpc()) - - require.False(t, f.IsKubernetes()) - require.False(t, h.IsFilepath()) - require.False(t, k.IsGrpc()) - require.False(t, g.IsHttp()) -} - -func Test_FLagSourceConfiguration_envVarKey(t *testing.T) { - require.Equal(t, "pre_suf", envVarKey("pre", "suf")) -} - -func Test_FLagSourceConfiguration_ToEnvVars(t *testing.T) { - ff := FeatureFlagSource{ - Spec: FeatureFlagSourceSpec{ - EnvVars: []v1.EnvVar{ - { - Name: "env1", - Value: "val1", - }, - { - Name: "env2", - Value: "val2", - }, - }, - EnvVarPrefix: "PRE", - MetricsPort: 22, - Port: 33, - Evaluator: "evaluator", - SocketPath: "socket-path", - LogFormat: "log", - }, - } - expected := []v1.EnvVar{ - { - Name: "PRE_env1", - Value: "val1", - }, - { - Name: "PRE_env2", - Value: "val2", - }, - { - Name: "PRE_METRICS_PORT", - Value: "22", - }, - { - Name: "PRE_PORT", - Value: "33", - }, - { - Name: "PRE_EVALUATOR", - Value: "evaluator", - }, - { - Name: "PRE_SOCKET_PATH", - Value: "socket-path", - }, - { - Name: "PRE_LOG_FORMAT", - Value: "log", - }, - } - require.Equal(t, expected, ff.Spec.ToEnvVars()) -} - func Test_FLagSourceConfiguration_Merge(t *testing.T) { ff_old := &FeatureFlagSource{ Spec: FeatureFlagSourceSpec{ @@ -107,7 +32,7 @@ func Test_FLagSourceConfiguration_Merge(t *testing.T) { Sources: []Source{ { Source: "src1", - Provider: SyncProviderGrpc, + Provider: common.SyncProviderGrpc, TLS: true, CertPath: "etc/cert.ca", ProviderID: "app", @@ -115,10 +40,10 @@ func Test_FLagSourceConfiguration_Merge(t *testing.T) { }, }, SyncProviderArgs: []string{"arg1", "arg2"}, - DefaultSyncProvider: SyncProviderKubernetes, - RolloutOnChange: utils.TrueVal(), - ProbesEnabled: utils.TrueVal(), - DebugLogging: utils.TrueVal(), + DefaultSyncProvider: common.SyncProviderKubernetes, + RolloutOnChange: common.TrueVal(), + ProbesEnabled: common.TrueVal(), + DebugLogging: common.TrueVal(), OtelCollectorUri: "", }, } @@ -148,7 +73,7 @@ func Test_FLagSourceConfiguration_Merge(t *testing.T) { Sources: []Source{ { Source: "src1", - Provider: SyncProviderGrpc, + Provider: common.SyncProviderGrpc, TLS: true, CertPath: "etc/cert.ca", ProviderID: "app", @@ -156,10 +81,10 @@ func Test_FLagSourceConfiguration_Merge(t *testing.T) { }, }, SyncProviderArgs: []string{"arg1", "arg2"}, - DefaultSyncProvider: SyncProviderKubernetes, - RolloutOnChange: utils.TrueVal(), - ProbesEnabled: utils.TrueVal(), - DebugLogging: utils.TrueVal(), + DefaultSyncProvider: common.SyncProviderKubernetes, + RolloutOnChange: common.TrueVal(), + ProbesEnabled: common.TrueVal(), + DebugLogging: common.TrueVal(), OtelCollectorUri: "", }, }, ff_old) @@ -187,14 +112,14 @@ func Test_FLagSourceConfiguration_Merge(t *testing.T) { Sources: []Source{ { Source: "src2", - Provider: SyncProviderFilepath, + Provider: common.SyncProviderFilepath, }, }, SyncProviderArgs: []string{"arg3", "arg4"}, - DefaultSyncProvider: SyncProviderFilepath, - RolloutOnChange: utils.FalseVal(), - ProbesEnabled: utils.FalseVal(), - DebugLogging: utils.FalseVal(), + DefaultSyncProvider: common.SyncProviderFilepath, + RolloutOnChange: common.FalseVal(), + ProbesEnabled: common.FalseVal(), + DebugLogging: common.FalseVal(), OtelCollectorUri: "", }, } @@ -232,7 +157,7 @@ func Test_FLagSourceConfiguration_Merge(t *testing.T) { Sources: []Source{ { Source: "src1", - Provider: SyncProviderGrpc, + Provider: common.SyncProviderGrpc, TLS: true, CertPath: "etc/cert.ca", ProviderID: "app", @@ -240,14 +165,14 @@ func Test_FLagSourceConfiguration_Merge(t *testing.T) { }, { Source: "src2", - Provider: SyncProviderFilepath, + Provider: common.SyncProviderFilepath, }, }, SyncProviderArgs: []string{"arg1", "arg2", "arg3", "arg4"}, - DefaultSyncProvider: SyncProviderFilepath, - RolloutOnChange: utils.FalseVal(), - ProbesEnabled: utils.FalseVal(), - DebugLogging: utils.FalseVal(), + DefaultSyncProvider: common.SyncProviderFilepath, + RolloutOnChange: common.FalseVal(), + ProbesEnabled: common.FalseVal(), + DebugLogging: common.FalseVal(), OtelCollectorUri: "", }, }, ff_old) @@ -255,17 +180,17 @@ func Test_FLagSourceConfiguration_Merge(t *testing.T) { func Test_FLagSourceConfiguration_NewFeatureFlagSourceSpec(t *testing.T) { //happy path - t.Setenv(envVarKey(InputConfigurationEnvVarPrefix, SidecarMetricPortEnvVar), "22") - t.Setenv(envVarKey(InputConfigurationEnvVarPrefix, SidecarPortEnvVar), "33") - t.Setenv(envVarKey(InputConfigurationEnvVarPrefix, SidecarSocketPathEnvVar), "val1") - t.Setenv(envVarKey(InputConfigurationEnvVarPrefix, SidecarEvaluatorEnvVar), "val2") - t.Setenv(envVarKey(InputConfigurationEnvVarPrefix, SidecarImageEnvVar), "val3") - t.Setenv(envVarKey(InputConfigurationEnvVarPrefix, SidecarVersionEnvVar), "val4") - t.Setenv(envVarKey(InputConfigurationEnvVarPrefix, SidecarProviderArgsEnvVar), "val11,val22") - t.Setenv(envVarKey(InputConfigurationEnvVarPrefix, SidecarDefaultSyncProviderEnvVar), "kubernetes") - t.Setenv(envVarKey(InputConfigurationEnvVarPrefix, SidecarLogFormatEnvVar), "val5") + t.Setenv(common.EnvVarKey(InputConfigurationEnvVarPrefix, SidecarMetricPortEnvVar), "22") + t.Setenv(common.EnvVarKey(InputConfigurationEnvVarPrefix, SidecarPortEnvVar), "33") + t.Setenv(common.EnvVarKey(InputConfigurationEnvVarPrefix, SidecarSocketPathEnvVar), "val1") + t.Setenv(common.EnvVarKey(InputConfigurationEnvVarPrefix, SidecarEvaluatorEnvVar), "val2") + t.Setenv(common.EnvVarKey(InputConfigurationEnvVarPrefix, SidecarImageEnvVar), "val3") + t.Setenv(common.EnvVarKey(InputConfigurationEnvVarPrefix, SidecarVersionEnvVar), "val4") + t.Setenv(common.EnvVarKey(InputConfigurationEnvVarPrefix, SidecarProviderArgsEnvVar), "val11,val22") + t.Setenv(common.EnvVarKey(InputConfigurationEnvVarPrefix, SidecarDefaultSyncProviderEnvVar), "kubernetes") + t.Setenv(common.EnvVarKey(InputConfigurationEnvVarPrefix, SidecarLogFormatEnvVar), "val5") t.Setenv(SidecarEnvVarPrefix, "val6") - t.Setenv(envVarKey(InputConfigurationEnvVarPrefix, SidecarProbesEnabledVar), "true") + t.Setenv(common.EnvVarKey(InputConfigurationEnvVarPrefix, SidecarProbesEnabledVar), "true") fs, err := NewFeatureFlagSourceSpec() @@ -280,24 +205,78 @@ func Test_FLagSourceConfiguration_NewFeatureFlagSourceSpec(t *testing.T) { Sources: []Source{}, EnvVars: []v1.EnvVar{}, SyncProviderArgs: []string{"val11", "val22"}, - DefaultSyncProvider: SyncProviderKubernetes, + DefaultSyncProvider: common.SyncProviderKubernetes, EnvVarPrefix: "val6", LogFormat: "val5", - ProbesEnabled: utils.TrueVal(), - DebugLogging: utils.FalseVal(), + ProbesEnabled: common.TrueVal(), + DebugLogging: common.FalseVal(), OtelCollectorUri: "", }, fs) //error paths - t.Setenv(envVarKey(InputConfigurationEnvVarPrefix, SidecarProbesEnabledVar), "blah") + t.Setenv(common.EnvVarKey(InputConfigurationEnvVarPrefix, SidecarProbesEnabledVar), "blah") _, err = NewFeatureFlagSourceSpec() require.NotNil(t, err) - t.Setenv(envVarKey(InputConfigurationEnvVarPrefix, SidecarPortEnvVar), "blah") + t.Setenv(common.EnvVarKey(InputConfigurationEnvVarPrefix, SidecarPortEnvVar), "blah") _, err = NewFeatureFlagSourceSpec() require.NotNil(t, err) - t.Setenv(envVarKey(InputConfigurationEnvVarPrefix, SidecarMetricPortEnvVar), "blah") + t.Setenv(common.EnvVarKey(InputConfigurationEnvVarPrefix, SidecarMetricPortEnvVar), "blah") _, err = NewFeatureFlagSourceSpec() require.NotNil(t, err) } + +func Test_FLagSourceConfiguration_ToEnvVars(t *testing.T) { + ff := FeatureFlagSource{ + Spec: FeatureFlagSourceSpec{ + EnvVars: []v1.EnvVar{ + { + Name: "env1", + Value: "val1", + }, + { + Name: "env2", + Value: "val2", + }, + }, + EnvVarPrefix: "PRE", + MetricsPort: 22, + Port: 33, + Evaluator: "evaluator", + SocketPath: "socket-path", + LogFormat: "log", + }, + } + expected := []v1.EnvVar{ + { + Name: "PRE_env1", + Value: "val1", + }, + { + Name: "PRE_env2", + Value: "val2", + }, + { + Name: "PRE_METRICS_PORT", + Value: "22", + }, + { + Name: "PRE_PORT", + Value: "33", + }, + { + Name: "PRE_EVALUATOR", + Value: "evaluator", + }, + { + Name: "PRE_SOCKET_PATH", + Value: "socket-path", + }, + { + Name: "PRE_LOG_FORMAT", + Value: "log", + }, + } + require.Equal(t, expected, ff.Spec.ToEnvVars()) +} diff --git a/chart/open-feature-operator/values.yaml b/chart/open-feature-operator/values.yaml index b414a6a3f..4fd679f68 100644 --- a/chart/open-feature-operator/values.yaml +++ b/chart/open-feature-operator/values.yaml @@ -16,7 +16,7 @@ sidecarConfiguration: ## @param sidecarConfiguration.image.repository Sets the image for the injected sidecar. repository: "ghcr.io/open-feature/flagd" ## @param sidecarConfiguration.image.tag Sets the version tag for the injected sidecar. - tag: v0.6.3 + tag: v0.7.0 ## @param 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`. providerArgs: "" ## @param sidecarConfiguration.envVarPrefix Sets the prefix for all environment variables set in the injected sidecar. diff --git a/test/e2e/kuttl/fsconfig-file-sync/00-install.yaml b/test/e2e/kuttl/fsconfig-file-sync/00-install.yaml index 11d02f270..b249c99ff 100644 --- a/test/e2e/kuttl/fsconfig-file-sync/00-install.yaml +++ b/test/e2e/kuttl/fsconfig-file-sync/00-install.yaml @@ -8,7 +8,7 @@ spec: evaluator: json defaultSyncProvider: file # renovate: datasource=github-tags depName=open-feature/flagd/flagd - tag: v0.6.3 + tag: v0.7.0 sources: - source: end-to-end-test provider: file diff --git a/test/e2e/kuttl/fsconfig-file-sync/01-assert.yaml b/test/e2e/kuttl/fsconfig-file-sync/01-assert.yaml index ee5efbed5..747459483 100644 --- a/test/e2e/kuttl/fsconfig-file-sync/01-assert.yaml +++ b/test/e2e/kuttl/fsconfig-file-sync/01-assert.yaml @@ -13,4 +13,4 @@ spec: - name: open-feature-e2e-test image: nginx:stable-alpine - name: flagd # this part verifies flagd injection happened - image: ghcr.io/open-feature/flagd:v0.6.3 + image: ghcr.io/open-feature/flagd:v0.7.0