Skip to content

Commit 2b1d89f

Browse files
authored
Merge pull request #74 from open-feature/feat/envs
feat: Env support
2 parents ac541e2 + 618cdfc commit 2b1d89f

File tree

9 files changed

+325
-9
lines changed

9 files changed

+325
-9
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
config/manager/manager.yaml
22
config/manager/kustomization.yaml
3+
schemas
34
.vscode
45
open-feature-operator
56
of-agent

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ High level architecture is as follows:
2828

2929
When wishing to leverage feature flagging within the local pod, the following steps are required:
3030

31-
1. Create a new feature flag custom resource e.g.
31+
1. Create a new feature flag custom resource.
32+
33+
_See [here](config/samples/crds/custom_provider.yaml) for additional custom resource parameters_
3234

3335
```
3436
apiVersion: core.openfeature.dev/v1alpha1
@@ -52,7 +54,7 @@ spec:
5254
}
5355
```
5456

55-
2. Reference the CR within the pod spec annotations
57+
1. Reference the CR within the pod spec annotations
5658

5759
```
5860
apiVersion: v1

apis/core/v1alpha1/featureflagconfiguration_types.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ type FeatureFlagConfigurationSpec struct {
4343
}
4444

4545
type FlagDSpec struct {
46-
Port string `json:"port"`
46+
// +optional
47+
Envs []corev1.EnvVar `json:"envs"`
4748
}
4849

4950
type FeatureFlagSyncProvider struct {

apis/core/v1alpha1/zz_generated.deepcopy.go

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/core.openfeature.dev_featureflagconfigurations.yaml

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,119 @@ spec:
4141
description: FeatureFlagSpec is the json representation of the feature
4242
flag
4343
type: string
44+
flagDSpec:
45+
nullable: true
46+
properties:
47+
envs:
48+
items:
49+
description: EnvVar represents an environment variable present
50+
in a Container.
51+
properties:
52+
name:
53+
description: Name of the environment variable. Must be a
54+
C_IDENTIFIER.
55+
type: string
56+
value:
57+
description: 'Variable references $(VAR_NAME) are expanded
58+
using the previously defined environment variables in
59+
the container and any service environment variables. If
60+
a variable cannot be resolved, the reference in the input
61+
string will be unchanged. Double $$ are reduced to a single
62+
$, which allows for escaping the $(VAR_NAME) syntax: i.e.
63+
"$$(VAR_NAME)" will produce the string literal "$(VAR_NAME)".
64+
Escaped references will never be expanded, regardless
65+
of whether the variable exists or not. Defaults to "".'
66+
type: string
67+
valueFrom:
68+
description: Source for the environment variable's value.
69+
Cannot be used if value is not empty.
70+
properties:
71+
configMapKeyRef:
72+
description: Selects a key of a ConfigMap.
73+
properties:
74+
key:
75+
description: The key to select.
76+
type: string
77+
name:
78+
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
79+
TODO: Add other useful fields. apiVersion, kind,
80+
uid?'
81+
type: string
82+
optional:
83+
description: Specify whether the ConfigMap or its
84+
key must be defined
85+
type: boolean
86+
required:
87+
- key
88+
type: object
89+
fieldRef:
90+
description: 'Selects a field of the pod: supports metadata.name,
91+
metadata.namespace, `metadata.labels[''<KEY>'']`,
92+
`metadata.annotations[''<KEY>'']`, spec.nodeName,
93+
spec.serviceAccountName, status.hostIP, status.podIP,
94+
status.podIPs.'
95+
properties:
96+
apiVersion:
97+
description: Version of the schema the FieldPath
98+
is written in terms of, defaults to "v1".
99+
type: string
100+
fieldPath:
101+
description: Path of the field to select in the
102+
specified API version.
103+
type: string
104+
required:
105+
- fieldPath
106+
type: object
107+
resourceFieldRef:
108+
description: 'Selects a resource of the container: only
109+
resources limits and requests (limits.cpu, limits.memory,
110+
limits.ephemeral-storage, requests.cpu, requests.memory
111+
and requests.ephemeral-storage) are currently supported.'
112+
properties:
113+
containerName:
114+
description: 'Container name: required for volumes,
115+
optional for env vars'
116+
type: string
117+
divisor:
118+
anyOf:
119+
- type: integer
120+
- type: string
121+
description: Specifies the output format of the
122+
exposed resources, defaults to "1"
123+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
124+
x-kubernetes-int-or-string: true
125+
resource:
126+
description: 'Required: resource to select'
127+
type: string
128+
required:
129+
- resource
130+
type: object
131+
secretKeyRef:
132+
description: Selects a key of a secret in the pod's
133+
namespace
134+
properties:
135+
key:
136+
description: The key of the secret to select from. Must
137+
be a valid secret key.
138+
type: string
139+
name:
140+
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
141+
TODO: Add other useful fields. apiVersion, kind,
142+
uid?'
143+
type: string
144+
optional:
145+
description: Specify whether the Secret or its key
146+
must be defined
147+
type: boolean
148+
required:
149+
- key
150+
type: object
151+
type: object
152+
required:
153+
- name
154+
type: object
155+
type: array
156+
type: object
44157
serviceProvider:
45158
description: 'INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
46159
Important: Run "make" to regenerate code after modifying this file'

config/samples/crds/custom_provider.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ kind: FeatureFlagConfiguration
33
metadata:
44
name: featureflagconfiguration-sample
55
spec:
6+
flagDSpec:
7+
envs:
8+
- name: FOO
9+
value: BAR
610
serviceProvider:
711
name: "flagd"
812
credentials:

config/samples/crds/featureflagconfiguration.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,9 @@ kind: FeatureFlagConfiguration
33
metadata:
44
name: featureflagconfiguration-sample
55
spec:
6+
flagDSpec:
7+
envs:
8+
- name: FOO
9+
value: BAR
610
featureFlagSpec: |
711
{}

pkg/utils/flagd-definitions.json

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"title": "flagd Flag Configuration",
4+
"description": "Defines flags for use in flagd, including typed variants and rules",
5+
"type": "object",
6+
"properties": {
7+
"flags": {
8+
"type": "object",
9+
"$comment": "flag objects are one of the 4 flag types defined in $defs",
10+
"additionalProperties": false,
11+
"patternProperties": {
12+
"^.{1,}$": {
13+
"oneOf": [
14+
{
15+
"title": "Boolean flag",
16+
"description": "A flag associated with boolean values",
17+
"$ref": "#/$defs/booleanFlag"
18+
},
19+
{
20+
"title": "String flag",
21+
"description": "A flag associated with string values",
22+
"$ref": "#/$defs/stringFlag"
23+
},
24+
{
25+
"title": "Numeric flag",
26+
"description": "A flag associated with numeric values",
27+
"$ref": "#/$defs/numberFlag"
28+
},
29+
{
30+
"title": "Object flag",
31+
"description": "A flag associated with arbitrary object values",
32+
"$ref": "#/$defs/objectFlag"
33+
}
34+
],
35+
"unevaluatedProperties": false
36+
}
37+
}
38+
}
39+
},
40+
"$defs": {
41+
"flag": {
42+
"title": "Flag base",
43+
"description": "Base object for all flags",
44+
"properties": {
45+
"state": {
46+
"title:": "Flag state",
47+
"description": "Indicates whether the flag is functional. Disabled flags are treated as if they don't exist",
48+
"type": "string",
49+
"enum": [
50+
"ENABLED",
51+
"DISABLED"
52+
]
53+
},
54+
"defaultVariant": {
55+
"title": "Default variant",
56+
"description": "The variant to serve if no dynamic targeting applies",
57+
"type": "string"
58+
},
59+
"targeting": {
60+
"type": "object",
61+
"title": "Targeting Logic",
62+
"description": "JsonLogic expressions to be used for dynamic evaluation. The \"context\" is passed as the data. Rules must resolve one of the defined variants, or the \"defaultVariant\" will be used."
63+
}
64+
},
65+
"required": [
66+
"state",
67+
"defaultVariant"
68+
]
69+
},
70+
"booleanVariants": {
71+
"type": "object",
72+
"properties": {
73+
"variants": {
74+
"additionalProperties": false,
75+
"patternProperties": {
76+
"^.{1,}$": {
77+
"type": "boolean"
78+
}
79+
},
80+
"default": {
81+
"on": true,
82+
"off": false
83+
}
84+
}
85+
}
86+
},
87+
"stringVariants": {
88+
"type": "object",
89+
"properties": {
90+
"variants": {
91+
"additionalProperties": false,
92+
"patternProperties": {
93+
"^.{1,}$": {
94+
"type": "string"
95+
}
96+
}
97+
}
98+
}
99+
},
100+
"numberVariants": {
101+
"type": "object",
102+
"properties": {
103+
"variants": {
104+
"additionalProperties": false,
105+
"patternProperties": {
106+
"^.{1,}$": {
107+
"type": "number"
108+
}
109+
}
110+
}
111+
}
112+
},
113+
"objectVariants": {
114+
"type": "object",
115+
"properties": {
116+
"variants": {
117+
"additionalProperties": false,
118+
"patternProperties": {
119+
"^.{1,}$": {
120+
"type": "object"
121+
}
122+
}
123+
}
124+
}
125+
},
126+
"$comment": "Merge the variants with the base flag to build our typed flags",
127+
"booleanFlag": {
128+
"allOf": [
129+
{
130+
"$ref": "#/$defs/flag"
131+
},
132+
{
133+
"$ref": "#/$defs/booleanVariants"
134+
}
135+
]
136+
},
137+
"stringFlag": {
138+
"allOf": [
139+
{
140+
"$ref": "#/$defs/flag"
141+
},
142+
{
143+
"$ref": "#/$defs/stringVariants"
144+
}
145+
]
146+
},
147+
"numberFlag": {
148+
"allOf": [
149+
{
150+
"$ref": "#/$defs/flag"
151+
},
152+
{
153+
"$ref": "#/$defs/numberVariants"
154+
}
155+
]
156+
},
157+
"objectFlag": {
158+
"allOf": [
159+
{
160+
"$ref": "#/$defs/flag"
161+
},
162+
{
163+
"$ref": "#/$defs/objectVariants"
164+
}
165+
]
166+
}
167+
}
168+
}

0 commit comments

Comments
 (0)