Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: introduce new CRD for in-process evaluation #632

Merged
merged 27 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
62b6622
feat: introduce new CRD for in-process evaluation
odubajDT May 15, 2024
ba87395
rename newly introduces CRD
odubajDT May 15, 2024
b2966e6
regenerate docs
odubajDT May 15, 2024
1e1a6ba
rename files
odubajDT May 15, 2024
164e679
pr review
odubajDT May 15, 2024
6c0e34c
more tests + genericduplicates removal
odubajDT May 15, 2024
91edcbf
polish tests
odubajDT May 15, 2024
9814410
polish merging functions
odubajDT May 15, 2024
9a6a22b
pr review
odubajDT May 16, 2024
8d0f86c
more error prone
odubajDT May 16, 2024
d77d1f9
polish
odubajDT May 16, 2024
a298d84
add validation for cache
odubajDT May 16, 2024
7dca3c7
fix missing initialization
odubajDT May 16, 2024
88d400a
remove flakyness
odubajDT May 16, 2024
d6bb2d1
reorder
odubajDT May 16, 2024
2cae707
Apply suggestions from code review
odubajDT May 16, 2024
87dce6c
Apply suggestions from code review
odubajDT May 17, 2024
97554fd
Update apis/core/v1beta1/common/common_test.go
odubajDT May 17, 2024
5506fd0
change default port of in-process evaluation to 8015
odubajDT May 22, 2024
f72e6ad
expose configurable parameters via helm chart values
odubajDT May 23, 2024
c2adeb0
fix linter
odubajDT May 23, 2024
1f62262
adapt e2e test to use chainsaw
odubajDT May 23, 2024
f8f6837
Merge branch 'main' into poc-inprocess-crd
toddbaert May 23, 2024
34e509f
Merge branch 'main' into poc-inprocess-crd
odubajDT May 23, 2024
46f8744
rename to inprocessconfiguration
odubajDT May 24, 2024
cc098ea
adapted condition in webhook
odubajDT May 24, 2024
49172d0
Update webhooks/pod_webhook.go
odubajDT May 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ resources:
path: github.com/open-feature/open-feature-operator/apis/core/v1beta1
version: v1beta1
webhooks:
defaulting: false
validation: true
webhookVersion: v1
- api:
Expand All @@ -76,4 +75,12 @@ resources:
kind: Flagd
path: github.com/open-feature/open-feature-operator/apis/core/v1beta1
version: v1beta1
- api:
crdVersion: v1
namespaced: true
domain: openfeature.dev
group: core
kind: FeatureFlagInProcessConfiguration
path: github.com/open-feature/open-feature-operator/apis/core/v1beta1
version: v1beta1
version: "3"
71 changes: 70 additions & 1 deletion apis/core/v1beta1/common/common.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package common

import "fmt"
import (
"fmt"

corev1 "k8s.io/api/core/v1"
)

type SyncProviderType string

Expand All @@ -12,6 +16,39 @@ const (
SyncProviderFlagdProxy SyncProviderType = "flagd-proxy"
)

const (
ManagementPortEnvVar string = "MANAGEMENT_PORT"
PortEnvVar string = "PORT"
HostEnvVar string = "HOST"
TLSEnvVar string = "TLS"
SocketPathEnvVar string = "SOCKET_PATH"
OfflineFlagSourcePathEnvVar string = "OFFLINE_FLAG_SOURCE_PATH"
SelectorEnvVar string = "SOURCE_SELECTOR"
CacheEnvVar string = "CACHE"
CacheMaxSizeEnvVar string = "MAX_CACHE_SIZE"
ResolverEnvVar string = "RESOLVER"
odubajDT marked this conversation as resolved.
Show resolved Hide resolved
EvaluatorEnvVar string = "EVALUATOR"
ImageEnvVar string = "IMAGE"
VersionEnvVar string = "TAG"
ProviderArgsEnvVar string = "PROVIDER_ARGS"
DefaultSyncProviderEnvVar string = "SYNC_PROVIDER"
LogFormatEnvVar string = "LOG_FORMAT"
ProbesEnabledVar string = "PROBES_ENABLED"
DefaultEnvVarPrefix string = "FLAGD"
DefaultManagementPort int32 = 8014
DefaultRPCPort int32 = 8013
DefaultInProcessPort int32 = 8015
DefaultEvaluator string = "json"
DefaultLogFormat string = "json"
DefaultProbesEnabled bool = true
DefaultTLS bool = false
DefaultHost string = "localhost"
DefaultCache string = "lru"
DefaultCacheMaxSize int32 = 1000
InProcessResolverType string = "in-process"
RPCResolverType string = "rpc"
)

func (s SyncProviderType) IsKubernetes() bool {
return s == SyncProviderKubernetes
}
Expand Down Expand Up @@ -55,3 +92,35 @@ func FeatureFlagConfigurationId(namespace, name string) string {
func FeatureFlagConfigMapKey(namespace, name string) string {
return fmt.Sprintf("%s.flagd.json", FeatureFlagConfigurationId(namespace, name))
}

func RemoveDuplicateEnvVars(input []corev1.EnvVar) []corev1.EnvVar {
out := make([]corev1.EnvVar, 0, len(input))
for i := len(input) - 1; i >= 0; i-- {
if !isEnvVarNamePresent(out, input[i]) {
out = append(out, input[i])
}
}
return out
}

func isEnvVarNamePresent(slice []corev1.EnvVar, item corev1.EnvVar) bool {
for _, i := range slice {
if i.Name == item.Name {
return true
}
}
return false
}

func RemoveDuplicatesFromSlice[T comparable](input []T) []T {
seen := make(map[T]bool)
result := []T{}

for _, item := range input {
if _, ok := seen[item]; !ok {
seen[item] = true
result = append(result, item)
}
}
return result
}
112 changes: 112 additions & 0 deletions apis/core/v1beta1/common/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"
)

func Test_FeatureFlagSource_SyncProvider(t *testing.T) {
Expand Down Expand Up @@ -34,3 +35,114 @@ func Test_FLagSourceConfiguration_FeatureFlagConfigurationId(t *testing.T) {
func Test_FLagSourceConfiguration_FeatureFlagConfigMapKey(t *testing.T) {
require.Equal(t, "pre_suf.flagd.json", FeatureFlagConfigMapKey("pre", "suf"))
}

func Test_RemoveDuplicateEnvVars(t *testing.T) {
input1 := []corev1.EnvVar{
{
Name: "key1",
Value: "val1",
},
{
Name: "key2",
Value: "val2",
},
{
Name: "key1",
Value: "val3",
},
}
input2 := []corev1.EnvVar{
{
Name: "key1",
Value: "val1",
},
{
Name: "key2",
Value: "val2",
},
{
Name: "key3",
Value: "val3",
},
}
input3 := []corev1.EnvVar{
{
Name: "key1",
Value: "val1",
},
{
Name: "key2",
Value: "val2",
},
{
Name: "key1",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: "secret",
},
},
},
},
}

out1 := RemoveDuplicateEnvVars(input1)
require.Len(t, out1, 2)
require.Contains(t, out1, corev1.EnvVar{
Name: "key1",
Value: "val3",
})
require.Contains(t, out1, corev1.EnvVar{
Name: "key2",
Value: "val2",
})

out2 := RemoveDuplicateEnvVars(input2)
require.Len(t, out2, 3)
require.Contains(t, out2, corev1.EnvVar{
Name: "key1",
Value: "val1",
})
require.Contains(t, out2, corev1.EnvVar{
Name: "key2",
Value: "val2",
})
require.Contains(t, out2, corev1.EnvVar{
Name: "key3",
Value: "val3",
})

out3 := RemoveDuplicateEnvVars(input3)
require.Len(t, out3, 2)
require.Contains(t, out3, corev1.EnvVar{
Name: "key1",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: "secret",
},
},
},
})
require.Contains(t, out3, corev1.EnvVar{
Name: "key2",
Value: "val2",
})
}

func Test_RRemoveDuplicatesFromSlice(t *testing.T) {
input1 := []string{
"some", "input", "duplicate", "some",
}
input2 := []int{
1, 2, 3, 4, 2,
}

require.Equal(t, RemoveDuplicatesFromSlice(input1), []string{
"some", "input", "duplicate",
})

require.Equal(t, RemoveDuplicatesFromSlice(input2), []int{
1, 2, 3, 4,
})
}
Loading
Loading