diff --git a/apis/core/v1alpha1/flagsourceconfiguration_types.go b/apis/core/v1alpha1/flagsourceconfiguration_types.go index 6e7dde2e2..d745336db 100644 --- a/apis/core/v1alpha1/flagsourceconfiguration_types.go +++ b/apis/core/v1alpha1/flagsourceconfiguration_types.go @@ -128,6 +128,10 @@ type FlagSourceConfigurationSpec struct { // DebugLogging defines whether to enable --debug flag of flagd sidecar. Default false (disabled). // +optional DebugLogging *bool `json:"debugLogging"` + + // OtelCollectorUri defines whether to enable --otel-collector-uri flag of flagd sidecar. Default false (disabled). + // +optional + OtelCollectorUri string `json:"otelCollectorUri"` } type Source struct { @@ -204,6 +208,7 @@ func NewFlagSourceConfigurationSpec() (*FlagSourceConfigurationSpec, error) { LogFormat: defaultLogFormat, RolloutOnChange: nil, DebugLogging: utils.FalseVal(), + OtelCollectorUri: "", } // set default value derived from constant default @@ -318,6 +323,9 @@ func (fc *FlagSourceConfigurationSpec) Merge(new *FlagSourceConfigurationSpec) { if new.DebugLogging != nil { fc.DebugLogging = new.DebugLogging } + if new.OtelCollectorUri != "" { + fc.OtelCollectorUri = new.OtelCollectorUri + } } func (fc *FlagSourceConfigurationSpec) ToEnvVars() []corev1.EnvVar { diff --git a/apis/core/v1alpha1/flagsourceconfiguration_types_test.go b/apis/core/v1alpha1/flagsourceconfiguration_types_test.go index 6521701b4..a3d2b9295 100644 --- a/apis/core/v1alpha1/flagsourceconfiguration_types_test.go +++ b/apis/core/v1alpha1/flagsourceconfiguration_types_test.go @@ -119,6 +119,7 @@ func Test_FLagSourceConfiguration_Merge(t *testing.T) { RolloutOnChange: utils.TrueVal(), ProbesEnabled: utils.TrueVal(), DebugLogging: utils.TrueVal(), + OtelCollectorUri: "", }, } @@ -159,6 +160,7 @@ func Test_FLagSourceConfiguration_Merge(t *testing.T) { RolloutOnChange: utils.TrueVal(), ProbesEnabled: utils.TrueVal(), DebugLogging: utils.TrueVal(), + OtelCollectorUri: "", }, }, ff_old) @@ -193,6 +195,7 @@ func Test_FLagSourceConfiguration_Merge(t *testing.T) { RolloutOnChange: utils.FalseVal(), ProbesEnabled: utils.FalseVal(), DebugLogging: utils.FalseVal(), + OtelCollectorUri: "", }, } @@ -245,6 +248,7 @@ func Test_FLagSourceConfiguration_Merge(t *testing.T) { RolloutOnChange: utils.FalseVal(), ProbesEnabled: utils.FalseVal(), DebugLogging: utils.FalseVal(), + OtelCollectorUri: "", }, }, ff_old) } @@ -281,6 +285,7 @@ func Test_FLagSourceConfiguration_NewFlagSourceConfigurationSpec(t *testing.T) { LogFormat: "val5", ProbesEnabled: utils.TrueVal(), DebugLogging: utils.FalseVal(), + OtelCollectorUri: "", }, fs) //error paths diff --git a/apis/core/v1alpha2/flagsourceconfiguration_conversion.go b/apis/core/v1alpha2/flagsourceconfiguration_conversion.go index 74cde0290..256af0cd9 100644 --- a/apis/core/v1alpha2/flagsourceconfiguration_conversion.go +++ b/apis/core/v1alpha2/flagsourceconfiguration_conversion.go @@ -49,6 +49,7 @@ func (src *FlagSourceConfiguration) ConvertTo(dstRaw conversion.Hub) error { DefaultSyncProvider: v1alpha1.SyncProviderType(src.Spec.DefaultSyncProvider), ProbesEnabled: src.Spec.ProbesEnabled, DebugLogging: utils.FalseVal(), + OtelCollectorUri: src.Spec.OtelCollectorUri, } return nil } diff --git a/apis/core/v1alpha2/flagsourceconfiguration_conversion_test.go b/apis/core/v1alpha2/flagsourceconfiguration_conversion_test.go index 89e0f5e03..3d1e449c9 100644 --- a/apis/core/v1alpha2/flagsourceconfiguration_conversion_test.go +++ b/apis/core/v1alpha2/flagsourceconfiguration_conversion_test.go @@ -65,6 +65,7 @@ func TestFlagSourceConfiguration_ConvertFrom(t *testing.T) { RolloutOnChange: &tt, SyncProviderArgs: []string{"provider", "arg"}, DebugLogging: utils.FalseVal(), + OtelCollectorUri: "", }, }, wantErr: false, @@ -155,6 +156,7 @@ func TestFlagSourceConfiguration_ConvertTo(t *testing.T) { RolloutOnChange: nil, SyncProviderArgs: []string{"provider", "arg"}, DebugLogging: utils.FalseVal(), + OtelCollectorUri: "", }, }, }, diff --git a/apis/core/v1alpha2/flagsourceconfiguration_types.go b/apis/core/v1alpha2/flagsourceconfiguration_types.go index 7a46d919e..0913c8317 100644 --- a/apis/core/v1alpha2/flagsourceconfiguration_types.go +++ b/apis/core/v1alpha2/flagsourceconfiguration_types.go @@ -67,6 +67,10 @@ type FlagSourceConfigurationSpec struct { // ProbesEnabled defines whether to enable liveness and readiness probes of flagd sidecar. Default true (enabled). // +optional ProbesEnabled *bool `json:"probesEnabled"` + + // OtelCollectorUri defines whether to enable --otel-collector-uri flag of flagd sidecar. Default false (disabled). + // +optional + OtelCollectorUri string `json:"otelCollectorUri"` } // FlagSourceConfigurationStatus defines the observed state of FlagSourceConfiguration diff --git a/apis/core/v1alpha3/flagsourceconfiguration_conversion.go b/apis/core/v1alpha3/flagsourceconfiguration_conversion.go index f87dc6248..b7f75d662 100644 --- a/apis/core/v1alpha3/flagsourceconfiguration_conversion.go +++ b/apis/core/v1alpha3/flagsourceconfiguration_conversion.go @@ -63,6 +63,7 @@ func (src *FlagSourceConfiguration) ConvertTo(dstRaw conversion.Hub) error { RolloutOnChange: src.Spec.RolloutOnChange, ProbesEnabled: src.Spec.ProbesEnabled, DebugLogging: src.Spec.DebugLogging, + OtelCollectorUri: src.Spec.OtelCollectorUri, } return nil } @@ -106,6 +107,7 @@ func (dst *FlagSourceConfiguration) ConvertFrom(srcRaw conversion.Hub) error { RolloutOnChange: src.Spec.RolloutOnChange, ProbesEnabled: src.Spec.ProbesEnabled, DebugLogging: src.Spec.DebugLogging, + OtelCollectorUri: src.Spec.OtelCollectorUri, } return nil } diff --git a/apis/core/v1alpha3/flagsourceconfiguration_conversion_test.go b/apis/core/v1alpha3/flagsourceconfiguration_conversion_test.go index 974b5c688..445360098 100644 --- a/apis/core/v1alpha3/flagsourceconfiguration_conversion_test.go +++ b/apis/core/v1alpha3/flagsourceconfiguration_conversion_test.go @@ -64,6 +64,7 @@ func TestFlagSourceConfiguration_ConvertFrom(t *testing.T) { EnvVarPrefix: "pre", RolloutOnChange: &tt, DebugLogging: utils.FalseVal(), + OtelCollectorUri: "", }, }, wantErr: false, @@ -220,6 +221,7 @@ func TestFlagSourceConfiguration_ConvertTo(t *testing.T) { EnvVarPrefix: "pre", RolloutOnChange: &tt, DebugLogging: utils.FalseVal(), + OtelCollectorUri: "", }, }, }, diff --git a/apis/core/v1alpha3/flagsourceconfiguration_types.go b/apis/core/v1alpha3/flagsourceconfiguration_types.go index 879af7e34..56413e113 100644 --- a/apis/core/v1alpha3/flagsourceconfiguration_types.go +++ b/apis/core/v1alpha3/flagsourceconfiguration_types.go @@ -92,6 +92,10 @@ type FlagSourceConfigurationSpec struct { // DebugLogging defines whether to enable --debug flag of flagd sidecar. Default false (disabled). // +optional DebugLogging *bool `json:"debugLogging"` + + // OtelCollectorUri defines whether to enable --otel-collector-uri flag of flagd sidecar. Default false (disabled). + // +optional + OtelCollectorUri string `json:"otelCollectorUri"` } type Source struct { diff --git a/chart/open-feature-operator/README.md b/chart/open-feature-operator/README.md index 72aea9664..9f2ee1334 100644 --- a/chart/open-feature-operator/README.md +++ b/chart/open-feature-operator/README.md @@ -106,6 +106,7 @@ The command removes all the Kubernetes components associated with the chart and | `sidecarConfiguration.logFormat` | Sets the value of the `XXX_LOG_FORMAT` environment variable for the injected sidecar container. There are 2 valid log formats: `json` and `console`. | `json` | | `sidecarConfiguration.probesEnabled` | Enable or Disable Liveness and Readiness probes of the flagd sidecar. When enabled, HTTP probes( paths - `/readyz`, `/healthz`) are set with an initial delay of 5 seconds. | `true` | | `sidecarConfiguration.debugLogging` | Controls the addition of the `--debug` flag to the container startup arguments. | `false` | +| `sidecarConfiguration.otelCollectorUri` | Otel exporter uri. | `""` | ### Flagd-proxy configuration @@ -128,7 +129,7 @@ The command removes all the Kubernetes components associated with the chart and | `controllerManager.kubeRbacProxy.resources.requests.cpu` | Sets cpu resource requests for kube-rbac-proxy. | `5m` | | `controllerManager.kubeRbacProxy.resources.requests.memory` | Sets memory resource requests for kube-rbac-proxy. | `64Mi` | | `controllerManager.manager.image.repository` | Sets the image for the operator. | `ghcr.io/open-feature/open-feature-operator` | -| `controllerManager.manager.image.tag` | Sets the version tag for the operator. | `v0.2.34` | +| `controllerManager.manager.image.tag` | Sets the version tag for the operator. | `v0.2.35` | | `controllerManager.manager.resources.limits.cpu` | Sets cpu resource limits for operator. | `500m` | | `controllerManager.manager.resources.limits.memory` | Sets memory resource limits for operator. | `128Mi` | | `controllerManager.manager.resources.requests.cpu` | Sets cpu resource requests for operator. | `10m` | diff --git a/chart/open-feature-operator/values.yaml b/chart/open-feature-operator/values.yaml index c9f9b0515..a54897333 100644 --- a/chart/open-feature-operator/values.yaml +++ b/chart/open-feature-operator/values.yaml @@ -31,6 +31,8 @@ sidecarConfiguration: probesEnabled: true ## @param sidecarConfiguration.debugLogging Controls the addition of the `--debug` flag to the container startup arguments. debugLogging: false + ## @param sidecarConfiguration.otelCollectorUri Otel exporter uri. + otelCollectorUri: "" ## @section Flagd-proxy configuration flagdProxyConfiguration: diff --git a/config/crd/bases/core.openfeature.dev_featureflagconfigurations.yaml b/config/crd/bases/core.openfeature.dev_featureflagconfigurations.yaml index 5d49b916f..dfb0ed59d 100644 --- a/config/crd/bases/core.openfeature.dev_featureflagconfigurations.yaml +++ b/config/crd/bases/core.openfeature.dev_featureflagconfigurations.yaml @@ -57,7 +57,15 @@ spec: C_IDENTIFIER. type: string value: - description: 'Variable references. More info: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#envvar-v1-core ' + description: 'Variable references $(VAR_NAME) are expanded + using the previously defined environment variables in + the container and any service environment variables. If + a variable cannot be resolved, the reference in the input + string will be unchanged. Double $$ are reduced to a single + $, which allows for escaping the $(VAR_NAME) syntax: i.e. + "$$(VAR_NAME)" will produce the string literal "$(VAR_NAME)". + Escaped references will never be expanded, regardless + of whether the variable exists or not. Defaults to "".' type: string valueFrom: description: Source for the environment variable's value. @@ -330,7 +338,15 @@ spec: C_IDENTIFIER. type: string value: - description: 'Variable references. More info: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#envvar-v1-core' + description: 'Variable references $(VAR_NAME) are expanded + using the previously defined environment variables in + the container and any service environment variables. If + a variable cannot be resolved, the reference in the input + string will be unchanged. Double $$ are reduced to a single + $, which allows for escaping the $(VAR_NAME) syntax: i.e. + "$$(VAR_NAME)" will produce the string literal "$(VAR_NAME)". + Escaped references will never be expanded, regardless + of whether the variable exists or not. Defaults to "".' type: string valueFrom: description: Source for the environment variable's value. diff --git a/config/crd/bases/core.openfeature.dev_flagsourceconfigurations.yaml b/config/crd/bases/core.openfeature.dev_flagsourceconfigurations.yaml index 0df0c81fe..9fce17478 100644 --- a/config/crd/bases/core.openfeature.dev_flagsourceconfigurations.yaml +++ b/config/crd/bases/core.openfeature.dev_flagsourceconfigurations.yaml @@ -62,7 +62,15 @@ spec: description: Name of the environment variable. Must be a C_IDENTIFIER. type: string value: - description: 'Variable references. More info: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#envvar-v1-core' + description: 'Variable references $(VAR_NAME) are expanded using + the previously defined environment variables in the container + and any service environment variables. If a variable cannot + be resolved, the reference in the input string will be unchanged. + Double $$ are reduced to a single $, which allows for escaping + the $(VAR_NAME) syntax: i.e. "$$(VAR_NAME)" will produce the + string literal "$(VAR_NAME)". Escaped references will never + be expanded, regardless of whether the variable exists or + not. Defaults to "".' type: string valueFrom: description: Source for the environment variable's value. Cannot @@ -169,6 +177,10 @@ spec: to 8014 format: int32 type: integer + otelCollectorUri: + description: OtelCollectorUri defines whether to enable --otel-collector-uri + flag of flagd sidecar. Default false (disabled). + type: string port: description: Port defines the port to listen on, defaults to 8013 format: int32 @@ -284,6 +296,10 @@ spec: to 8013 format: int32 type: integer + otelCollectorUri: + description: OtelCollectorUri defines whether to enable --otel-collector-uri + flag of flagd sidecar. Default false (disabled). + type: string port: description: Port defines the port to listen on, defaults to 8014 format: int32 @@ -360,7 +376,15 @@ spec: description: Name of the environment variable. Must be a C_IDENTIFIER. type: string value: - description: 'Variable references. More info: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#envvar-v1-core' + description: 'Variable references $(VAR_NAME) are expanded using + the previously defined environment variables in the container + and any service environment variables. If a variable cannot + be resolved, the reference in the input string will be unchanged. + Double $$ are reduced to a single $, which allows for escaping + the $(VAR_NAME) syntax: i.e. "$$(VAR_NAME)" will produce the + string literal "$(VAR_NAME)". Escaped references will never + be expanded, regardless of whether the variable exists or + not. Defaults to "".' type: string valueFrom: description: Source for the environment variable's value. Cannot @@ -467,6 +491,10 @@ spec: to 8014 format: int32 type: integer + otelCollectorUri: + description: OtelCollectorUri defines whether to enable --otel-collector-uri + flag of flagd sidecar. Default false (disabled). + type: string port: description: Port defines the port to listen on, defaults to 8013 format: int32 diff --git a/controllers/common/flagd-injector.go b/controllers/common/flagd-injector.go index b1cff5948..f0fa4facb 100644 --- a/controllers/common/flagd-injector.go +++ b/controllers/common/flagd-injector.go @@ -89,6 +89,21 @@ func (fi *FlagdContainerInjector) InjectFlagd( ) } + // set --otel-collector-uri flag if enabled + if flagSourceConfig.OtelCollectorUri != "" { + flagdContainer.Args = append( + flagdContainer.Args, + "--metrics-exporter", + "otel", + ) + + flagdContainer.Args = append( + flagdContainer.Args, + "--otel-collector-uri", + flagSourceConfig.OtelCollectorUri, + ) + } + addFlagdContainer(podSpec, flagdContainer) return nil diff --git a/controllers/common/flagd-injector_test.go b/controllers/common/flagd-injector_test.go index c34980219..b4613b5c7 100644 --- a/controllers/common/flagd-injector_test.go +++ b/controllers/common/flagd-injector_test.go @@ -98,6 +98,45 @@ func TestFlagdContainerInjector_InjectDefaultSyncProvider_WithDebugLogging(t *te require.Equal(t, expectedDeployment, deployment) } +func TestFlagdContainerInjector_InjectDefaultSyncProvider_WithOtelCollectorUri(t *testing.T) { + + namespace, fakeClient := initContainerInjectionTestEnv() + + fi := &FlagdContainerInjector{ + Client: fakeClient, + Logger: testr.New(t), + FlagdProxyConfig: getProxyConfig(), + FlagDResourceRequirements: getResourceRequirements(), + } + + deployment := appsV1.Deployment{ + ObjectMeta: metav1.ObjectMeta{ + Name: "my-deployment", + Namespace: namespace, + }, + Spec: appsV1.DeploymentSpec{}, + } + + flagSourceConfig := getFlagSourceConfigSpec() + + flagSourceConfig.DefaultSyncProvider = v1alpha1.SyncProviderGrpc + + flagSourceConfig.OtelCollectorUri = "localhost:4317" + + flagSourceConfig.Sources = []v1alpha1.Source{{}} + + err := fi.InjectFlagd(context.Background(), &deployment.ObjectMeta, &deployment.Spec.Template.Spec, flagSourceConfig) + require.Nil(t, err) + + expectedDeployment := getExpectedDeployment(namespace) + + expectedDeployment.Annotations = nil + + expectedDeployment.Spec.Template.Spec.Containers[0].Args = []string{"start", "--sources", "[{\"uri\":\"\",\"provider\":\"grpc\"}]", "--metrics-exporter", "otel", "--otel-collector-uri", "localhost:4317"} + + require.Equal(t, expectedDeployment, deployment) +} + func TestFlagdContainerInjector_InjectDefaultSyncProvider_WithSyncProviderArgs(t *testing.T) { namespace, fakeClient := initContainerInjectionTestEnv() diff --git a/docs/crds.md b/docs/crds.md index 57c9f836b..f252a2702 100644 --- a/docs/crds.md +++ b/docs/crds.md @@ -182,7 +182,7 @@ EnvVar represents an environment variable present in a Container. value string - Variable references. More info: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#envvar-v1-core
+ Variable references $(VAR_NAME) are expanded using the previously defined environment variables in the container and any service environment variables. If a variable cannot be resolved, the reference in the input string will be unchanged. Double $$ are reduced to a single $, which allows for escaping the $(VAR_NAME) syntax: i.e. "$$(VAR_NAME)" will produce the string literal "$(VAR_NAME)". Escaped references will never be expanded, regardless of whether the variable exists or not. Defaults to "".
false @@ -710,6 +710,13 @@ FlagSourceConfigurationSpec defines the desired state of FlagSourceConfiguration Format: int32
false + + otelCollectorUri + string + + OtelCollectorUri defines whether to enable --otel-collector-uri flag of flagd sidecar. Default false (disabled).
+ + false port integer @@ -854,7 +861,7 @@ EnvVar represents an environment variable present in a Container. value string - Variable references. More info: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#envvar-v1-core
+ Variable references $(VAR_NAME) are expanded using the previously defined environment variables in the container and any service environment variables. If a variable cannot be resolved, the reference in the input string will be unchanged. Double $$ are reduced to a single $, which allows for escaping the $(VAR_NAME) syntax: i.e. "$$(VAR_NAME)" will produce the string literal "$(VAR_NAME)". Escaped references will never be expanded, regardless of whether the variable exists or not. Defaults to "".
false @@ -1323,7 +1330,7 @@ EnvVar represents an environment variable present in a Container. value string - Variable references. More info: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#envvar-v1-core
+ Variable references $(VAR_NAME) are expanded using the previously defined environment variables in the container and any service environment variables. If a variable cannot be resolved, the reference in the input string will be unchanged. Double $$ are reduced to a single $, which allows for escaping the $(VAR_NAME) syntax: i.e. "$$(VAR_NAME)" will produce the string literal "$(VAR_NAME)". Escaped references will never be expanded, regardless of whether the variable exists or not. Defaults to "".
false @@ -1823,6 +1830,13 @@ FlagSourceConfigurationSpec defines the desired state of FlagSourceConfiguration Format: int32
false + + otelCollectorUri + string + + OtelCollectorUri defines whether to enable --otel-collector-uri flag of flagd sidecar. Default false (disabled).
+ + false port integer @@ -2007,6 +2021,13 @@ FlagSourceConfigurationSpec defines the desired state of FlagSourceConfiguration Format: int32
false + + otelCollectorUri + string + + OtelCollectorUri defines whether to enable --otel-collector-uri flag of flagd sidecar. Default false (disabled).
+ + false port integer @@ -2151,7 +2172,7 @@ EnvVar represents an environment variable present in a Container. value string - Variable references. More info: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#envvar-v1-core
+ Variable references $(VAR_NAME) are expanded using the previously defined environment variables in the container and any service environment variables. If a variable cannot be resolved, the reference in the input string will be unchanged. Double $$ are reduced to a single $, which allows for escaping the $(VAR_NAME) syntax: i.e. "$$(VAR_NAME)" will produce the string literal "$(VAR_NAME)". Escaped references will never be expanded, regardless of whether the variable exists or not. Defaults to "".
false diff --git a/docs/flag_source_configuration.md b/docs/flag_source_configuration.md index 221db376a..1b93161f1 100644 --- a/docs/flag_source_configuration.md +++ b/docs/flag_source_configuration.md @@ -84,14 +84,15 @@ sources: `FlagSourceConfiguration` further allows to provide configurations to the injected flagd sidecar. Table given below is non-exhaustive list of overriding options, -| Configuration | Explanation | Default | -|---------------|-------------------------------|----------------------------| -| port | Flag evaluation endpoint port | 8013 | -| metricsPort | Metrics port | 8014 | -| evaluator | Evaluator to use | json | -| image | flagD image | ghcr.io/open-feature/flagd | -| tag | flagD image tag | Latest tag | -| probesEnabled | Enable/Disable health probes | true | +| Configuration | Explanation | Default | +|------------------|-------------------------------|----------------------------| +| port | Flag evaluation endpoint port | 8013 | +| metricsPort | Metrics port | 8014 | +| evaluator | Evaluator to use | json | +| image | flagD image | ghcr.io/open-feature/flagd | +| tag | flagD image tag | Latest tag | +| probesEnabled | Enable/Disable health probes | true | +| otelCollectorUri | Otel exporter uri | | ## Merging of configurations @@ -133,6 +134,7 @@ spec: value: my-env-value probesEnabled: true debugLogging: false + otelCollectorUri: http://localhost:4317 ``` The relevant `FlagSourceConfigurations` are passed to the operator by setting the `openfeature.dev/flagsourceconfiguration` annotation, and is responsible for providing the full configuration of the injected sidecar.