Skip to content

Commit

Permalink
feat: use v1beta1 in operator logic
Browse files Browse the repository at this point in the history
Signed-off-by: odubajDT <[email protected]>
  • Loading branch information
odubajDT committed Nov 16, 2023
1 parent cdc4af4 commit 8f23a04
Show file tree
Hide file tree
Showing 80 changed files with 1,443 additions and 5,550 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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions apis/core/v1alpha1/featureflagconfiguration_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions apis/core/v1alpha1/flagsourceconfiguration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion apis/core/v1alpha1/flagsourceconfiguration_types_test.go
Original file line number Diff line number Diff line change
@@ -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"
)
Expand Down
22 changes: 13 additions & 9 deletions apis/core/v1beta1/common/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ import (
"github.com/stretchr/testify/require"
)

func Test_FLagSourceConfiguration_EnvVarKey(t *testing.T) {
require.Equal(t, "pre_suf", EnvVarKey("pre", "suf"))
}

func Test_FLagSourceConfiguration_FeatureFlagConfigurationId(t *testing.T) {
require.Equal(t, "pre_suf", FeatureFlagConfigurationId("pre", "suf"))
}

func Test_FLagSourceConfiguration_FeatureFlagConfigMapKey(t *testing.T) {
require.Equal(t, "pre_suf.flagd.json", FeatureFlagConfigMapKey("pre", "suf"))
}

func Test_FeatureFlagSource_SyncProvider(t *testing.T) {
k := SyncProviderKubernetes
f := SyncProviderFilepath
Expand All @@ -23,14 +35,6 @@ func Test_FeatureFlagSource_SyncProvider(t *testing.T) {
require.False(t, g.IsHttp())
}

func Test_FLagSourceConfiguration_EnvVarKey(t *testing.T) {
func Test_FLagSourceConfiguration_envVarKey(t *testing.T) {
require.Equal(t, "pre_suf", EnvVarKey("pre", "suf"))
}

func Test_FLagSourceConfiguration_FeatureFlagConfigurationId(t *testing.T) {
require.Equal(t, "pre_suf", FeatureFlagConfigurationId("pre", "suf"))
}

func Test_FLagSourceConfiguration_FeatureFlagConfigMapKey(t *testing.T) {
require.Equal(t, "pre_suf.flagd.json", FeatureFlagConfigMapKey("pre", "suf"))
}
33 changes: 33 additions & 0 deletions apis/core/v1beta1/featureflag_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package v1beta1
import (
"encoding/json"

"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"
)

Expand Down Expand Up @@ -61,6 +63,7 @@ type FeatureFlagStatus struct {
//+kubebuilder:resource:shortName="ffc"
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:storageversion

// FeatureFlag is the Schema for the featureflags API
type FeatureFlag struct {
Expand All @@ -83,3 +86,33 @@ type FeatureFlagList struct {
func init() {
SchemeBuilder.Register(&FeatureFlag{}, &FeatureFlagList{})
}

func (ff *FeatureFlag) GetReference() metav1.OwnerReference {
return metav1.OwnerReference{
APIVersion: ff.APIVersion,
Kind: ff.Kind,
Name: ff.Name,
UID: ff.UID,
Controller: common.TrueVal(),
}
}

func (ff *FeatureFlag) GenerateConfigMap(name string, namespace string, references []metav1.OwnerReference) (*corev1.ConfigMap, error) {
b, err := json.Marshal(ff.Spec.FlagSpec)
if err != nil {
return nil, err
}
return &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
Annotations: map[string]string{
"openfeature.dev/featureflag": name,
},
OwnerReferences: references,
},
Data: map[string]string{
common.FeatureFlagConfigMapKey(namespace, name): string(b),
},
}, nil
}
70 changes: 70 additions & 0 deletions apis/core/v1beta1/featureflag_types_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package v1beta1

import (
"testing"

"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"
"k8s.io/apimachinery/pkg/types"
)

func Test_FeatureFlag(t *testing.T) {
ff := FeatureFlag{
ObjectMeta: v1.ObjectMeta{
Name: "ffconf1",
Namespace: "test",
OwnerReferences: []v1.OwnerReference{
{
APIVersion: "ver",
Kind: "kind",
Name: "ffconf1",
UID: types.UID("5"),
Controller: common.TrueVal(),
},
},
},
Spec: FeatureFlagSpec{
FlagSpec: FlagSpec{
Flags: map[string]Flag{},
},
},
}

require.Equal(t, v1.OwnerReference{
APIVersion: ff.APIVersion,
Kind: ff.Kind,
Name: ff.Name,
UID: ff.UID,
Controller: common.TrueVal(),
}, ff.GetReference())

name := "cmname"
namespace := "cmnamespace"
references := []v1.OwnerReference{
{
APIVersion: "ver",
Kind: "kind",
Name: "ffconf1",
UID: types.UID("5"),
Controller: common.TrueVal(),
},
}

cm, _ := ff.GenerateConfigMap(name, namespace, references)

require.Equal(t, corev1.ConfigMap{
ObjectMeta: v1.ObjectMeta{
Name: name,
Namespace: namespace,
Annotations: map[string]string{
"openfeature.dev/featureflag": name,
},
OwnerReferences: references,
},
Data: map[string]string{
"cmnamespace_cmname.flagd.json": "{\"flags\":{}}",
},
}, *cm)
}
Loading

0 comments on commit 8f23a04

Please sign in to comment.