Skip to content

Commit e380957

Browse files
committed
feat: introduce new CRD for in-process evaluation
Signed-off-by: odubajDT <[email protected]>
1 parent b0b99a7 commit e380957

22 files changed

+1528
-60
lines changed

PROJECT

+8-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ resources:
5656
path: github.com/open-feature/open-feature-operator/apis/core/v1beta1
5757
version: v1beta1
5858
webhooks:
59-
defaulting: false
6059
validation: true
6160
webhookVersion: v1
6261
- api:
@@ -76,4 +75,12 @@ resources:
7675
kind: Flagd
7776
path: github.com/open-feature/open-feature-operator/apis/core/v1beta1
7877
version: v1beta1
78+
- api:
79+
crdVersion: v1
80+
namespaced: true
81+
domain: openfeature.dev
82+
group: core
83+
kind: FeatureFlagInProcessSource
84+
path: github.com/open-feature/open-feature-operator/apis/core/v1beta1
85+
version: v1beta1
7986
version: "3"

apis/core/v1beta1/common/common.go

+30
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,36 @@ const (
1212
SyncProviderFlagdProxy SyncProviderType = "flagd-proxy"
1313
)
1414

15+
const (
16+
MetricPortEnvVar string = "MANAGEMENT_PORT"
17+
PortEnvVar string = "PORT"
18+
HostEnvVar string = "HOST"
19+
TLSEnvVar string = "TLS"
20+
SocketPathEnvVar string = "SOCKET_PATH"
21+
OfflineFlagSourcePathEnvVar string = "OFFLINE_FLAG_SOURCE_PATH"
22+
SelectorEnvVar string = "SOURCE_SELECTOR"
23+
CacheEnvVar string = "CACHE"
24+
CacheMaxSizeEnvVar string = "MAX_CACHE_SIZE"
25+
ResolverEnvVar string = "RESOLVER"
26+
EvaluatorEnvVar string = "EVALUATOR"
27+
ImageEnvVar string = "IMAGE"
28+
VersionEnvVar string = "TAG"
29+
ProviderArgsEnvVar string = "PROVIDER_ARGS"
30+
DefaultSyncProviderEnvVar string = "SYNC_PROVIDER"
31+
LogFormatEnvVar string = "LOG_FORMAT"
32+
ProbesEnabledVar string = "PROBES_ENABLED"
33+
DefaultEnvVarPrefix string = "FLAGD"
34+
DefaultManagementPort int32 = 8014
35+
DefaultPort int32 = 8013
36+
DefaultEvaluator string = "json"
37+
DefaultLogFormat string = "json"
38+
DefaultProbesEnabled bool = true
39+
DefaultTLS bool = false
40+
DefaultHost string = "localhost"
41+
DefaultCache string = "lru"
42+
DefaultCacheMaxSize int32 = 1000
43+
)
44+
1545
func (s SyncProviderType) IsKubernetes() bool {
1646
return s == SyncProviderKubernetes
1747
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
/*
2+
Copyright 2022.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1beta1
18+
19+
import (
20+
"fmt"
21+
22+
"github.com/open-feature/open-feature-operator/apis/core/v1beta1/common"
23+
corev1 "k8s.io/api/core/v1"
24+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25+
)
26+
27+
// FeatureFlagInProcessSourceSpec defines the desired state of FeatureFlagInProcessSource
28+
type FeatureFlagInProcessSourceSpec struct {
29+
// Port defines the port to listen on, defaults to 8013
30+
// +kubebuilder:default:=8013
31+
// +optional
32+
Port int32 `json:"port"`
33+
34+
// SocketPath defines the unix socket path to listen on
35+
// +optional
36+
SocketPath string `json:"socketPath"`
37+
38+
// Host
39+
// +kubebuilder:default:=localhost
40+
// +optional
41+
Host string `json:"host"`
42+
43+
// TLS
44+
// +kubebuilder:default:=false
45+
// +optional
46+
TLS bool `json:"tls"`
47+
48+
// OfflineFlagSourcePath
49+
// +optional
50+
OfflineFlagSourcePath string `json:"offlineFlagSourcePath"`
51+
52+
// Selector
53+
// +optional
54+
Selector string `json:"selector"`
55+
56+
// Cache
57+
// +kubebuilder:default:=lru
58+
// +kubebuilder:validation:Enum:=lru;disabled
59+
// +optional
60+
Cache string `json:"cache"`
61+
62+
// CacheMaxSize
63+
// +kubebuilder:default:=1000
64+
// +optional
65+
CacheMaxSize int `json:"cacheMaxSize"`
66+
67+
//EnvVars
68+
// +optional
69+
EnvVars []corev1.EnvVar `json:"envVars"`
70+
71+
// EnvVarPrefix defines the prefix to be applied to all environment variables applied to the sidecar, default FLAGD
72+
// +optional
73+
// +kubebuilder:default:=FLAGD
74+
EnvVarPrefix string `json:"envVarPrefix"`
75+
}
76+
77+
// FeatureFlagInProcessSourceStatus defines the observed state of FeatureFlagInProcessSource
78+
type FeatureFlagInProcessSourceStatus struct {
79+
}
80+
81+
//+kubebuilder:object:root=true
82+
//+kubebuilder:subresource:status
83+
84+
// FeatureFlagInProcessSource is the Schema for the featureflaginprocesssources API
85+
type FeatureFlagInProcessSource struct {
86+
metav1.TypeMeta `json:",inline"`
87+
metav1.ObjectMeta `json:"metadata,omitempty"`
88+
89+
Spec FeatureFlagInProcessSourceSpec `json:"spec,omitempty"`
90+
Status FeatureFlagInProcessSourceStatus `json:"status,omitempty"`
91+
}
92+
93+
//+kubebuilder:object:root=true
94+
95+
// FeatureFlagInProcessSourceList contains a list of FeatureFlagInProcessSource
96+
type FeatureFlagInProcessSourceList struct {
97+
metav1.TypeMeta `json:",inline"`
98+
metav1.ListMeta `json:"metadata,omitempty"`
99+
Items []FeatureFlagInProcessSource `json:"items"`
100+
}
101+
102+
func init() {
103+
SchemeBuilder.Register(&FeatureFlagInProcessSource{}, &FeatureFlagInProcessSourceList{})
104+
}
105+
106+
func (fc *FeatureFlagInProcessSourceSpec) Merge(new *FeatureFlagInProcessSourceSpec) {
107+
if new == nil {
108+
return
109+
}
110+
if len(new.EnvVars) != 0 {
111+
fc.EnvVars = append(fc.EnvVars, new.EnvVars...)
112+
}
113+
if new.Port != common.DefaultPort {
114+
fc.Port = new.Port
115+
}
116+
if new.SocketPath != "" {
117+
fc.SocketPath = new.SocketPath
118+
}
119+
if new.Host != common.DefaultHost {
120+
fc.Host = new.Host
121+
}
122+
if new.EnvVarPrefix != common.DefaultEnvVarPrefix {
123+
fc.EnvVarPrefix = new.EnvVarPrefix
124+
}
125+
if new.OfflineFlagSourcePath != "" {
126+
fc.OfflineFlagSourcePath = new.OfflineFlagSourcePath
127+
}
128+
if new.Selector != "" {
129+
fc.Selector = new.Selector
130+
}
131+
if new.Cache != common.DefaultCache {
132+
fc.Cache = new.Cache
133+
}
134+
if new.CacheMaxSize != int(common.DefaultCacheMaxSize) {
135+
fc.CacheMaxSize = new.CacheMaxSize
136+
}
137+
if new.TLS != common.DefaultTLS {
138+
fc.TLS = new.TLS
139+
}
140+
}
141+
142+
func (fc *FeatureFlagInProcessSourceSpec) ToEnvVars() []corev1.EnvVar {
143+
envs := []corev1.EnvVar{}
144+
145+
for _, envVar := range fc.EnvVars {
146+
envs = append(envs, corev1.EnvVar{
147+
Name: common.EnvVarKey(fc.EnvVarPrefix, envVar.Name),
148+
Value: envVar.Value,
149+
})
150+
}
151+
152+
envs = append(envs, corev1.EnvVar{
153+
Name: common.EnvVarKey(fc.EnvVarPrefix, common.HostEnvVar),
154+
Value: fc.Host,
155+
})
156+
157+
envs = append(envs, corev1.EnvVar{
158+
Name: common.EnvVarKey(fc.EnvVarPrefix, common.PortEnvVar),
159+
Value: fmt.Sprintf("%d", fc.Port),
160+
})
161+
162+
envs = append(envs, corev1.EnvVar{
163+
Name: common.EnvVarKey(fc.EnvVarPrefix, common.TLSEnvVar),
164+
Value: fmt.Sprintf("%t", fc.TLS),
165+
})
166+
167+
envs = append(envs, corev1.EnvVar{
168+
Name: common.EnvVarKey(fc.EnvVarPrefix, common.SocketPathEnvVar),
169+
Value: fc.SocketPath,
170+
})
171+
172+
envs = append(envs, corev1.EnvVar{
173+
Name: common.EnvVarKey(fc.EnvVarPrefix, common.OfflineFlagSourcePathEnvVar),
174+
Value: fc.OfflineFlagSourcePath,
175+
})
176+
177+
envs = append(envs, corev1.EnvVar{
178+
Name: common.EnvVarKey(fc.EnvVarPrefix, common.SelectorEnvVar),
179+
Value: fc.Selector,
180+
})
181+
182+
envs = append(envs, corev1.EnvVar{
183+
Name: common.EnvVarKey(fc.EnvVarPrefix, common.CacheEnvVar),
184+
Value: fc.Cache,
185+
})
186+
187+
envs = append(envs, corev1.EnvVar{
188+
Name: common.EnvVarKey(fc.EnvVarPrefix, common.CacheMaxSizeEnvVar),
189+
Value: fmt.Sprintf("%d", fc.CacheMaxSize),
190+
})
191+
192+
return envs
193+
}

0 commit comments

Comments
 (0)