Skip to content

Commit

Permalink
feat!: use v1beta1 in operator logic (#539)
Browse files Browse the repository at this point in the history
Signed-off-by: odubajDT <ondrej.dubaj@dynatrace.com>
  • Loading branch information
odubajDT committed Nov 16, 2023
1 parent e3c8b42 commit d234410
Show file tree
Hide file tree
Showing 73 changed files with 880 additions and 5,589 deletions.
4 changes: 2 additions & 2 deletions .github/scripts/create-reports.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ for namespace in $(kubectl get namespaces -o jsonpath='{.items[*].metadata.name}
createResourceReport "$logsDir/$namespace" "$namespace" "Daemonsets" false
createResourceReport "$logsDir/$namespace" "$namespace" "Statefulsets" false
createResourceReport "$logsDir/$namespace" "$namespace" "Jobs" false
createResourceReport "$logsDir/$namespace" "$namespace" "FeatureFlagConfiguration" false
createResourceReport "$logsDir/$namespace" "$namespace" "FlagSourceConfiguration" false
createResourceReport "$logsDir/$namespace" "$namespace" "FeatureFlag" false
createResourceReport "$logsDir/$namespace" "$namespace" "FeatureFlagSource" false

done
4 changes: 2 additions & 2 deletions .github/workflows/pr-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ jobs:
IMG=open-feature-operator-local:${{ github.sha }} make deploy-operator
IMG=open-feature-operator-local:${{ github.sha }} make e2e-test-kuttl
- name: Create reports
if: always()
if: failure()
working-directory: ./.github/scripts
run: ./create-reports.sh

- name: Upload cluster logs
if: always()
if: failure()
uses: actions/upload-artifact@v3
with:
name: e2e-tests
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ testbin/*
*.swo
*~

go.work
go.work.sum
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ COPY main.go main.go
COPY apis/ apis/
COPY webhooks/ webhooks/
COPY controllers/ controllers/
COPY pkg/ pkg/
COPY common/ common/

ARG TARGETOS
ARG TARGETARCH
Expand Down
14 changes: 7 additions & 7 deletions chart/open-feature-operator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,16 @@ OpenFeature Operator's CRDs are templated, and can be updated apart from the ope
helm template openfeature/open-feature-operator -s templates/{CRD} | kubectl apply -f -
```

For the `featureflagconfigurations.core.openfeature.dev` CRD:
For the `featureflags.core.openfeature.dev` CRD:

```sh
helm template openfeature/open-feature-operator -s templates/apiextensions.k8s.io_v1_customresourcedefinition_featureflagconfigurations.core.openfeature.dev.yaml | kubectl apply -f -
helm template openfeature/open-feature-operator -s templates/apiextensions.k8s.io_v1_customresourcedefinition_featureflags.core.openfeature.dev.yaml | kubectl apply -f -
```

For the `flagsourceconfigurations.core.openfeature.dev` CRD:
For the `featureflagsources.core.openfeature.dev` CRD:

```sh
helm template openfeature/open-feature-operator -s templates/apiextensions.k8s.io_v1_customresourcedefinition_flagsourceconfigurations.core.openfeature.dev.yaml | kubectl apply -f -
helm template openfeature/open-feature-operator -s templates/apiextensions.k8s.io_v1_customresourcedefinition_featureflagsources.core.openfeature.dev.yaml | kubectl apply -f -
```

Keep in mind, you can set values as usual during this process:
Expand Down Expand Up @@ -95,10 +95,10 @@ The command removes all the Kubernetes components associated with the chart and
| Name | Description | Value |
| ------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------- |
| `sidecarConfiguration.port` | Sets the value of the `XXX_PORT` environment variable for the injected sidecar. | `8013` |
| `sidecarConfiguration.metricsPort` | Sets the value of the `XXX_METRICS_PORT` environment variable for the injected sidecar. | `8014` |
| `sidecarConfiguration.managementPort` | Sets the value of the `XXX_MANAGEMENT_PORT` environment variable for the injected sidecar. | `8014` |
| `sidecarConfiguration.socketPath` | Sets the value of the `XXX_SOCKET_PATH` environment variable for the injected sidecar. | `""` |
| `sidecarConfiguration.image.repository` | Sets the image for the injected sidecar. | `ghcr.io/open-feature/flagd` |
| `sidecarConfiguration.image.tag` | Sets the version tag for the injected sidecar. | `v0.6.3` |
| `sidecarConfiguration.image.tag` | Sets the version tag for the injected sidecar. | `v0.7.0` |
| `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`. | `""` |
| `sidecarConfiguration.envVarPrefix` | Sets the prefix for all environment variables set in the injected sidecar. | `FLAGD` |
| `sidecarConfiguration.defaultSyncProvider` | Sets the value of the `XXX_SYNC_PROVIDER` environment variable for the injected sidecar container. There are 4 valid sync providers: `kubernetes`, `grpc`, `filepath` and `http`. | `kubernetes` |
Expand All @@ -114,7 +114,7 @@ The command removes all the Kubernetes components associated with the chart and
| Name | Description | Value |
| ------------------------------------------ | ------------------------------------------------------------------------------- | ---------------------------------- |
| `flagdProxyConfiguration.port` | Sets the port to expose the sync API on. | `8015` |
| `flagdProxyConfiguration.metricsPort` | Sets the port to expose the metrics API on. | `8016` |
| `flagdProxyConfiguration.managementPort` | Sets the port to expose the management API on. | `8016` |
| `flagdProxyConfiguration.image.repository` | Sets the image for the flagd-proxy deployment. | `ghcr.io/open-feature/flagd-proxy` |
| `flagdProxyConfiguration.image.tag` | Sets the tag for the flagd-proxy deployment. | `v0.2.8` |
| `flagdProxyConfiguration.debugLogging` | Controls the addition of the `--debug` flag to the container startup arguments. | `false` |
Expand Down
10 changes: 5 additions & 5 deletions chart/open-feature-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ defaultNamespace: open-feature-operator-system
sidecarConfiguration:
## @param sidecarConfiguration.port Sets the value of the `XXX_PORT` environment variable for the injected sidecar.
port: 8013
## @param sidecarConfiguration.metricsPort Sets the value of the `XXX_METRICS_PORT` environment variable for the injected sidecar.
metricsPort: 8014
## @param sidecarConfiguration.managementPort Sets the value of the `XXX_MANAGEMENT_PORT` environment variable for the injected sidecar.
managementPort: 8014
## @param sidecarConfiguration.socketPath Sets the value of the `XXX_SOCKET_PATH` environment variable for the injected sidecar.
socketPath: ""
image:
# these fields must remain in the same order, renovate uses a regex to update the tag value
## @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.
Expand All @@ -40,8 +40,8 @@ sidecarConfiguration:
flagdProxyConfiguration:
## @param flagdProxyConfiguration.port Sets the port to expose the sync API on.
port: 8015
## @param flagdProxyConfiguration.metricsPort Sets the port to expose the metrics API on.
metricsPort: 8016
## @param flagdProxyConfiguration.managementPort Sets the port to expose the management API on.
managementPort: 8016
image:
## @param flagdProxyConfiguration.image.repository Sets the image for the flagd-proxy deployment.
repository: "ghcr.io/open-feature/flagd-proxy"
Expand Down
22 changes: 11 additions & 11 deletions controllers/common/common.go → common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ import (
"fmt"
"time"

"github.com/open-feature/open-feature-operator/apis/core/v1alpha1"
api "github.com/open-feature/open-feature-operator/apis/core/v1beta1"
appsV1 "k8s.io/api/apps/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
)

const (
ReconcileErrorInterval = 10 * time.Second
ReconcileSuccessInterval = 120 * time.Second
FinalizerName = "featureflagconfiguration.core.openfeature.dev/finalizer"
OpenFeatureAnnotationPath = "spec.template.metadata.annotations.openfeature.dev/openfeature.dev"
FlagSourceConfigurationAnnotation = "flagsourceconfiguration"
OpenFeatureAnnotationRoot = "openfeature.dev"
ReconcileErrorInterval = 10 * time.Second
ReconcileSuccessInterval = 120 * time.Second
FinalizerName = "featureflag.core.openfeature.dev/finalizer"
OpenFeatureAnnotationPath = "spec.template.metadata.annotations.openfeature.dev/openfeature.dev"
FeatureFlagSourceAnnotation = "featureflagsource"
OpenFeatureAnnotationRoot = "openfeature.dev"
)

func FlagSourceConfigurationIndex(o client.Object) []string {
func FeatureFlagSourceIndex(o client.Object) []string {
deployment, ok := o.(*appsV1.Deployment)
if !ok {
return []string{
Expand All @@ -33,7 +33,7 @@ func FlagSourceConfigurationIndex(o client.Object) []string {
"false",
}
}
if _, ok := deployment.Spec.Template.ObjectMeta.Annotations[fmt.Sprintf("openfeature.dev/%s", FlagSourceConfigurationAnnotation)]; ok {
if _, ok := deployment.Spec.Template.ObjectMeta.Annotations[fmt.Sprintf("openfeature.dev/%s", FeatureFlagSourceAnnotation)]; ok {
return []string{
"true",
}
Expand All @@ -43,8 +43,8 @@ func FlagSourceConfigurationIndex(o client.Object) []string {
}
}

func FindFlagConfig(ctx context.Context, c client.Client, namespace string, name string) (*v1alpha1.FeatureFlagConfiguration, error) {
ffConfig := &v1alpha1.FeatureFlagConfiguration{}
func FindFlagConfig(ctx context.Context, c client.Client, namespace string, name string) (*api.FeatureFlag, error) {
ffConfig := &api.FeatureFlag{}
if err := c.Get(ctx, client.ObjectKey{Name: name, Namespace: namespace}, ffConfig); err != nil {
return nil, err
}
Expand Down
64 changes: 60 additions & 4 deletions controllers/common/common_test.go → common/common_test.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
package common

import (
"context"
"fmt"
"testing"

api "github.com/open-feature/open-feature-operator/apis/core/v1beta1"
"github.com/stretchr/testify/require"
appsV1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes/scheme"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
)

func TestFlagSourceConfigurationIndex(t *testing.T) {
func TestFeatureFlagSourceIndex(t *testing.T) {
tests := []struct {
name string
obj client.Object
Expand Down Expand Up @@ -49,7 +53,7 @@ func TestFlagSourceConfigurationIndex(t *testing.T) {
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
fmt.Sprintf("openfeature.dev/%s", FlagSourceConfigurationAnnotation): "true",
fmt.Sprintf("openfeature.dev/%s", FeatureFlagSourceAnnotation): "true",
},
},
},
Expand All @@ -61,7 +65,7 @@ func TestFlagSourceConfigurationIndex(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
out := FlagSourceConfigurationIndex(tt.obj)
out := FeatureFlagSourceIndex(tt.obj)
require.Equal(t, tt.out, out)
})

Expand Down Expand Up @@ -102,8 +106,60 @@ func TestSharedOwnership(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := SharedOwnership(tt.owner1, tt.owner2); got != tt.want {
t.Errorf("podOwnerIsOwner() = %v, want %v", got, tt.want)
t.Errorf("SharedOwnership() = %v, want %v", got, tt.want)
}
})
}
}

func TestFindFlagConfig(t *testing.T) {
ff := &api.FeatureFlag{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Namespace: "default",
},
}

tests := []struct {
name string
ns string
obj *api.FeatureFlag
want *api.FeatureFlag
wantErr bool
}{
{
name: "test",
ns: "default",
obj: ff,
want: ff,
wantErr: false,
},
{
name: "non-existing",
ns: "default",
obj: ff,
want: nil,
wantErr: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := api.AddToScheme(scheme.Scheme)
require.Nil(t, err)
fakeClient := fake.NewClientBuilder().WithScheme(scheme.Scheme).WithObjects(tt.obj).Build()

got, err := FindFlagConfig(context.TODO(), fakeClient, tt.ns, tt.name)

if (err != nil) != tt.wantErr {
t.Errorf("FindFlagConfig() = expected error %t, got %v", tt.wantErr, err)
}

if !tt.wantErr {
require.Equal(t, tt.want.Name, got.Name)
require.Equal(t, tt.want.Namespace, got.Namespace)
}

})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ const (
ClusterRoleBindingName string = "open-feature-operator-flagd-kubernetes-sync"
AllowKubernetesSyncAnnotation = "allowkubernetessync"
OpenFeatureAnnotationPrefix = "openfeature.dev"
OpenFeatureAnnotationPath = "metadata.annotations.openfeature.dev"
SourceConfigParam = "--sources"
ProbeReadiness = "/readyz"
ProbeLiveness = "/healthz"
ProbeInitialDelay = 5
FeatureFlagSourceAnnotation = "featureflagsource"
EnabledAnnotation = "enabled"
)
File renamed without changes.
65 changes: 65 additions & 0 deletions common/flagdinjector/fake/flagdinjector_mock.go

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

Loading

0 comments on commit d234410

Please sign in to comment.