Skip to content

Commit

Permalink
feat: introduce debugLogging parameter to FlagSourceConfiguration CRD (
Browse files Browse the repository at this point in the history
…#434)

Signed-off-by: odubajDT <ondrej.dubaj@dynatrace.com>
  • Loading branch information
odubajDT authored Apr 6, 2023
1 parent f24b6c4 commit 26ae125
Show file tree
Hide file tree
Showing 16 changed files with 175 additions and 30 deletions.
11 changes: 10 additions & 1 deletion apis/core/v1alpha1/flagsourceconfiguration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"strconv"
"strings"

"github.com/open-feature/open-feature-operator/pkg/utils"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down Expand Up @@ -119,9 +120,13 @@ type FlagSourceConfigurationSpec struct {
// +optional
RolloutOnChange *bool `json:"rolloutOnChange"`

// ProbesEnabled defines whether to enable liveness and readiness probes of flagd sidecar. Default true(enabled)
// ProbesEnabled defines whether to enable liveness and readiness probes of flagd sidecar. Default true (enabled).
// +optional
ProbesEnabled *bool `json:"probesEnabled"`

// DebugLogging defines whether to enable --debug flag of flagd sidecar. Default false (disabled).
// +optional
DebugLogging *bool `json:"debugLogging"`
}

type Source struct {
Expand Down Expand Up @@ -197,6 +202,7 @@ func NewFlagSourceConfigurationSpec() (*FlagSourceConfigurationSpec, error) {
EnvVarPrefix: defaultSidecarEnvVarPrefix,
LogFormat: defaultLogFormat,
RolloutOnChange: nil,
DebugLogging: utils.FalseVal(),
}

// set default value derived from constant default
Expand Down Expand Up @@ -308,6 +314,9 @@ func (fc *FlagSourceConfigurationSpec) Merge(new *FlagSourceConfigurationSpec) {
if new.ProbesEnabled != nil {
fc.ProbesEnabled = new.ProbesEnabled
}
if new.DebugLogging != nil {
fc.DebugLogging = new.DebugLogging
}
}

func (fc *FlagSourceConfigurationSpec) ToEnvVars() []corev1.EnvVar {
Expand Down
5 changes: 5 additions & 0 deletions apis/core/v1alpha1/flagsourceconfiguration_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func Test_FLagSourceConfiguration_Merge(t *testing.T) {
DefaultSyncProvider: SyncProviderKubernetes,
RolloutOnChange: utils.TrueVal(),
ProbesEnabled: utils.TrueVal(),
DebugLogging: utils.TrueVal(),
},
}

Expand Down Expand Up @@ -157,6 +158,7 @@ func Test_FLagSourceConfiguration_Merge(t *testing.T) {
DefaultSyncProvider: SyncProviderKubernetes,
RolloutOnChange: utils.TrueVal(),
ProbesEnabled: utils.TrueVal(),
DebugLogging: utils.TrueVal(),
},
}, ff_old)

Expand Down Expand Up @@ -190,6 +192,7 @@ func Test_FLagSourceConfiguration_Merge(t *testing.T) {
DefaultSyncProvider: SyncProviderFilepath,
RolloutOnChange: utils.FalseVal(),
ProbesEnabled: utils.FalseVal(),
DebugLogging: utils.FalseVal(),
},
}

Expand Down Expand Up @@ -241,6 +244,7 @@ func Test_FLagSourceConfiguration_Merge(t *testing.T) {
DefaultSyncProvider: SyncProviderFilepath,
RolloutOnChange: utils.FalseVal(),
ProbesEnabled: utils.FalseVal(),
DebugLogging: utils.FalseVal(),
},
}, ff_old)
}
Expand Down Expand Up @@ -276,6 +280,7 @@ func Test_FLagSourceConfiguration_NewFlagSourceConfigurationSpec(t *testing.T) {
EnvVarPrefix: "val6",
LogFormat: "val5",
ProbesEnabled: utils.TrueVal(),
DebugLogging: utils.FalseVal(),
}, fs)

//error paths
Expand Down
5 changes: 5 additions & 0 deletions apis/core/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions apis/core/v1alpha2/flagsourceconfiguration_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/open-feature/open-feature-operator/apis/core/v1alpha1"
"github.com/open-feature/open-feature-operator/apis/core/v1alpha2/common"
"github.com/open-feature/open-feature-operator/pkg/utils"
"sigs.k8s.io/controller-runtime/pkg/conversion"
)

Expand All @@ -47,6 +48,7 @@ func (src *FlagSourceConfiguration) ConvertTo(dstRaw conversion.Hub) error {
LogFormat: src.Spec.LogFormat,
DefaultSyncProvider: v1alpha1.SyncProviderType(src.Spec.DefaultSyncProvider),
ProbesEnabled: src.Spec.ProbesEnabled,
DebugLogging: utils.FalseVal(),
}
return nil
}
Expand Down
3 changes: 3 additions & 0 deletions apis/core/v1alpha2/flagsourceconfiguration_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/open-feature/open-feature-operator/apis/core/v1alpha1"
"github.com/open-feature/open-feature-operator/apis/core/v1alpha2/common"
"github.com/open-feature/open-feature-operator/pkg/utils"
"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -63,6 +64,7 @@ func TestFlagSourceConfiguration_ConvertFrom(t *testing.T) {
EnvVarPrefix: "pre",
RolloutOnChange: &tt,
SyncProviderArgs: []string{"provider", "arg"},
DebugLogging: utils.FalseVal(),
},
},
wantErr: false,
Expand Down Expand Up @@ -152,6 +154,7 @@ func TestFlagSourceConfiguration_ConvertTo(t *testing.T) {
EnvVarPrefix: "",
RolloutOnChange: nil,
SyncProviderArgs: []string{"provider", "arg"},
DebugLogging: utils.FalseVal(),
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion apis/core/v1alpha2/flagsourceconfiguration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ type FlagSourceConfigurationSpec struct {
// +optional
LogFormat string `json:"logFormat"`

// ProbesEnabled defines whether to enable liveness and readiness probes of flagd sidecar. Default true(enabled)
// ProbesEnabled defines whether to enable liveness and readiness probes of flagd sidecar. Default true (enabled).
// +optional
ProbesEnabled *bool `json:"probesEnabled"`
}
Expand Down
2 changes: 2 additions & 0 deletions apis/core/v1alpha3/flagsourceconfiguration_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func (src *FlagSourceConfiguration) ConvertTo(dstRaw conversion.Hub) error {
EnvVarPrefix: src.Spec.EnvVarPrefix,
RolloutOnChange: src.Spec.RolloutOnChange,
ProbesEnabled: src.Spec.ProbesEnabled,
DebugLogging: src.Spec.DebugLogging,
}
return nil
}
Expand Down Expand Up @@ -104,6 +105,7 @@ func (dst *FlagSourceConfiguration) ConvertFrom(srcRaw conversion.Hub) error {
EnvVarPrefix: src.Spec.EnvVarPrefix,
RolloutOnChange: src.Spec.RolloutOnChange,
ProbesEnabled: src.Spec.ProbesEnabled,
DebugLogging: src.Spec.DebugLogging,
}
return nil
}
5 changes: 5 additions & 0 deletions apis/core/v1alpha3/flagsourceconfiguration_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/open-feature/open-feature-operator/apis/core/v1alpha1"
"github.com/open-feature/open-feature-operator/apis/core/v1alpha3/common"
"github.com/open-feature/open-feature-operator/pkg/utils"
"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -62,6 +63,7 @@ func TestFlagSourceConfiguration_ConvertFrom(t *testing.T) {
LogFormat: "log",
EnvVarPrefix: "pre",
RolloutOnChange: &tt,
DebugLogging: utils.FalseVal(),
},
},
wantErr: false,
Expand Down Expand Up @@ -102,6 +104,7 @@ func TestFlagSourceConfiguration_ConvertFrom(t *testing.T) {
LogFormat: "log",
EnvVarPrefix: "pre",
RolloutOnChange: &tt,
DebugLogging: utils.FalseVal(),
},
},
},
Expand Down Expand Up @@ -175,6 +178,7 @@ func TestFlagSourceConfiguration_ConvertTo(t *testing.T) {
LogFormat: "log",
EnvVarPrefix: "pre",
RolloutOnChange: &tt,
DebugLogging: utils.FalseVal(),
},
},
wantErr: false,
Expand Down Expand Up @@ -215,6 +219,7 @@ func TestFlagSourceConfiguration_ConvertTo(t *testing.T) {
LogFormat: "log",
EnvVarPrefix: "pre",
RolloutOnChange: &tt,
DebugLogging: utils.FalseVal(),
},
},
},
Expand Down
6 changes: 5 additions & 1 deletion apis/core/v1alpha3/flagsourceconfiguration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,13 @@ type FlagSourceConfigurationSpec struct {
// +optional
RolloutOnChange *bool `json:"rolloutOnChange"`

// ProbesEnabled defines whether to enable liveness and readiness probes of flagd sidecar. Default true(enabled)
// ProbesEnabled defines whether to enable liveness and readiness probes of flagd sidecar. Default true (enabled).
// +optional
ProbesEnabled *bool `json:"probesEnabled"`

// DebugLogging defines whether to enable --debug flag of flagd sidecar. Default false (disabled).
// +optional
DebugLogging *bool `json:"debugLogging"`
}

type Source struct {
Expand Down
5 changes: 5 additions & 0 deletions apis/core/v1alpha3/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ spec:
description: FlagSourceConfigurationSpec defines the desired state of
FlagSourceConfiguration
properties:
debugLogging:
description: DebugLogging defines whether to enable --debug flag of
flagd sidecar. Default false (disabled).
type: boolean
defaultSyncProvider:
description: DefaultSyncProvider defines the default sync provider
type: string
Expand Down Expand Up @@ -179,7 +183,7 @@ spec:
type: integer
probesEnabled:
description: ProbesEnabled defines whether to enable liveness and
readiness probes of flagd sidecar. Default true(enabled)
readiness probes of flagd sidecar. Default true (enabled).
type: boolean
rolloutOnChange:
description: RolloutOnChange dictates whether annotated deployments
Expand Down Expand Up @@ -294,7 +298,7 @@ spec:
type: integer
probesEnabled:
description: ProbesEnabled defines whether to enable liveness and
readiness probes of flagd sidecar. Default true(enabled)
readiness probes of flagd sidecar. Default true (enabled).
type: boolean
socketPath:
description: SocketPath defines the unix socket path to listen on
Expand Down Expand Up @@ -341,6 +345,10 @@ spec:
description: FlagSourceConfigurationSpec defines the desired state of
FlagSourceConfiguration
properties:
debugLogging:
description: DebugLogging defines whether to enable --debug flag of
flagd sidecar. Default false (disabled).
type: boolean
defaultSyncProvider:
description: DefaultSyncProvider defines the default sync provider
type: string
Expand Down Expand Up @@ -481,7 +489,7 @@ spec:
type: integer
probesEnabled:
description: ProbesEnabled defines whether to enable liveness and
readiness probes of flagd sidecar. Default true(enabled)
readiness probes of flagd sidecar. Default true (enabled).
type: boolean
rolloutOnChange:
description: RolloutOnChange dictates whether annotated deployments
Expand Down
2 changes: 2 additions & 0 deletions docs/flag_source_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ spec:
- name: MY_ENV_VAR
value: my-env-value
probesEnabled: true
debugLogging: false
```
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.
Expand All @@ -54,6 +55,7 @@ The relevant `FlagSourceConfigurations` are passed to the operator by setting th
| DefaultSyncProvider | Defines the default provider to be used, can be set to `kubernetes`, `filepath`, `http` or `flagd-proxy` (experimental). | optional `string` | `kubernetes` |
| RolloutOnChange | When set to true the operator will trigger a restart of any `Deployments` within the `FlagSourceConfiguration` reconcile loop, updating the injected sidecar with the latest configuration. | optional `boolean` | `false` |
| 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 | optional `boolean` | `true` |
| DebugLogging | Enable or disable `--debug` flag of flagd sidecar | optional `boolean` | `false` |

## Source Fields

Expand Down
6 changes: 3 additions & 3 deletions test/e2e/kuttl/flagd-disabled/01-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ metadata:
status:
phase: Running
spec:
containers:
- name: open-feature-e2e-test
image: nginx:stable-alpine
containers:
- name: open-feature-e2e-test
image: nginx:stable-alpine
10 changes: 5 additions & 5 deletions test/e2e/kuttl/inject-flagd/01-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ metadata:
status:
phase: Running
spec:
containers:
- name: open-feature-e2e-test
image: nginx:stable-alpine
- name: flagd # this part verifies flagd injection happened
image: ghcr.io/open-feature/flagd:v0.5.0
containers:
- name: open-feature-e2e-test
image: nginx:stable-alpine
- name: flagd # this part verifies flagd injection happened
image: ghcr.io/open-feature/flagd:v0.5.0
Loading

0 comments on commit 26ae125

Please sign in to comment.