Skip to content

Commit

Permalink
pr review
Browse files Browse the repository at this point in the history
Signed-off-by: odubajDT <[email protected]>
  • Loading branch information
odubajDT committed Nov 14, 2023
1 parent 08a0899 commit efce742
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
20 changes: 10 additions & 10 deletions core/pkg/sync/kubernetes/kubernetes_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,7 @@ func (k *Sync) fetch(ctx context.Context) (string, error) {
}

k.logger.Debug(fmt.Sprintf("resource %s served from the informer cache", k.URI))
b, err := json.Marshal(configuration.Spec.FlagSpec)
if err != nil {
return "", fmt.Errorf("failed to marshall FlagSpec: %s", err.Error())
}
return string(b), nil
return marshallFeatureFlagSpec(configuration)
}

// fallback to API access - this is an informer cache miss. Could happen at the startup where cache is not filled
Expand All @@ -210,11 +206,7 @@ func (k *Sync) fetch(ctx context.Context) (string, error) {
}

k.logger.Debug(fmt.Sprintf("resource %s served from API server", k.URI))
b, err := json.Marshal(ff.Spec.FlagSpec)
if err != nil {
return "", fmt.Errorf("failed to marshall FlagSpec: %s", err.Error())
}
return string(b), nil
return marshallFeatureFlagSpec(&ff)
}

func (k *Sync) notify(ctx context.Context, c chan<- INotify) {
Expand Down Expand Up @@ -358,3 +350,11 @@ func k8sClusterConfig() (*rest.Config, error) {

return clusterConfig, nil
}

func marshallFeatureFlagSpec(ff *v1beta1.FeatureFlag) (string, error) {
b, err := json.Marshal(ff.Spec.FlagSpec)
if err != nil {
return "", fmt.Errorf("failed to marshall FlagSpec: %s", err.Error())
}
return string(b), nil
}
18 changes: 18 additions & 0 deletions core/pkg/sync/kubernetes/kubernetes_sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/open-feature/flagd/core/pkg/logger"
"github.com/open-feature/flagd/core/pkg/sync"
"github.com/open-feature/open-feature-operator/apis/core/v1beta1"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zapcore"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
Expand Down Expand Up @@ -912,3 +913,20 @@ type MockInformer struct {
func (m MockInformer) GetStore() cache.Store {
return &m.fakeStore
}

func TestMeasure(t *testing.T) {
res, err := marshallFeatureFlagSpec(&v1beta1.FeatureFlag{
Spec: v1beta1.FeatureFlagSpec{
FlagSpec: v1beta1.FlagSpec{
Flags: map[string]v1beta1.Flag{
"flag": {
DefaultVariant: "kubernetes",
},
},
},
},
})

require.Nil(t, err)
require.Equal(t, "{\"flags\":{\"flag\":{\"state\":\"\",\"variants\":null,\"defaultVariant\":\"kubernetes\"}}}", res)
}

0 comments on commit efce742

Please sign in to comment.