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 <ondrej.dubaj@dynatrace.com>
  • Loading branch information
odubajDT committed Nov 16, 2023
1 parent 1856918 commit e17e66b
Show file tree
Hide file tree
Showing 74 changed files with 1,422 additions and 5,503 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: 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
4 changes: 4 additions & 0 deletions apis/core/v1alpha1/featureflagconfiguration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,11 @@ 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
},
}
}
Expand Down
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/common/utils"
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: utils.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{
utils.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/common/utils"
"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: utils.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: utils.TrueVal(),
}, ff.GetReference())

name := "cmname"
namespace := "cmnamespace"
references := []v1.OwnerReference{
{
APIVersion: "ver",
Kind: "kind",
Name: "ffconf1",
UID: types.UID("5"),
Controller: utils.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 e17e66b

Please sign in to comment.