Skip to content

Commit 069112c

Browse files
committed
Add submodule for schemas, embed in utils
1 parent 99a1745 commit 069112c

File tree

11 files changed

+79
-114
lines changed

11 files changed

+79
-114
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ testbin/*
2525
*.swp
2626
*.swo
2727
*~
28+
29+
# copied schema file
30+
pkg/utils/flagd-definitions.json

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "schemas"]
2+
path = schemas
3+
url = https://github.com/open-feature/schemas

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ COPY apis/ apis/
1717
COPY webhooks/ webhooks/
1818
COPY controllers/ controllers/
1919
COPY pkg/ pkg/
20+
COPY schemas/json-schema/flagd-definitions.json pkg/utils/flagd-definitions.json
2021

2122
# Build
2223
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -a -o manager main.go

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and Cust
4545

4646
.PHONY: generate
4747
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
48+
cp schemas/json-schema/flagd-definitions.json pkg/utils/flagd-definitions.json
4849
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
4950

5051
.PHONY: fmt

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,11 @@ root@nginx:/# curl localhost:8080
7373

7474
#### Run the example
7575

76+
<<<<<<< HEAD
7677
1. `kubectl apply -f config/samples/crds/featureflagconfiguration.yaml`
7778
1. `kubectl apply -f config/samples/pod.yaml`
79+
=======
80+
1. Add our CR: `kubectl apply -f config/samples/end-to-end/crd/end-to-end.yml`
81+
1. Add test deployment: `kubectl apply -f config/samples/end-to-end/deployment/openfeature-nest-example.yml`
82+
1. Add service (optional): `kubectl apply -f config/samples/end-to-end/service/openfeature-nest-example.yml`
83+
>>>>>>> 5f8ddf3 (Add submodule for schemas, embed in utils)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: core.openfeature.dev/v1alpha1
2+
kind: FeatureFlagConfiguration
3+
metadata:
4+
name: end-to-end
5+
spec:
6+
featureFlagSpec: |
7+
{
8+
"booleanFlags": {
9+
"new-welcome-message": {
10+
"state": "enabled",
11+
"variants": {
12+
"enabled": true,
13+
"disabled": false
14+
},
15+
"defaultVariant": "enabled",
16+
"rules": []
17+
}
18+
}
19+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: openfeature-nest-example-deployment
5+
labels:
6+
app: openfeature-nest-example
7+
spec:
8+
replicas: 3
9+
selector:
10+
matchLabels:
11+
app: openfeature-nest-example
12+
template:
13+
metadata:
14+
labels:
15+
app: openfeature-nest-example
16+
annotations:
17+
openfeature.dev: "enabled"
18+
openfeature.dev/featureflagconfiguration: "end-to-end"
19+
spec:
20+
containers:
21+
- name: openfeature-nest-example
22+
image: toddbaert/openfeature-nest-example:latest
23+
ports:
24+
- containerPort: 3000
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: openfeature-nest-example-service
5+
spec:
6+
type: NodePort
7+
selector:
8+
app: openfeature-nest-example
9+
ports:
10+
# By default and for convenience, the `targetPort` is set to the same value as the `port` field.
11+
- port: 30000
12+
targetPort: 3000
13+
nodePort: 30000

pkg/utils/schema.go

Lines changed: 7 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,10 @@
11
package utils
22

3-
/*
4-
This is a temporary reference of the Open Feature schema
5-
https://github.com/open-feature/playground/blob/main/schemas/flag.schema.json
6-
*/
3+
import _ "embed"
4+
5+
//go:embed flagd-definitions.json
6+
var schema string
7+
78
func GetSchema() string {
8-
return `
9-
{
10-
"$schema": "https://json-schema.org/draft/2020-12/schema",
11-
"$id": "https://openfeature.dev/flag.schema.json",
12-
"title": "OpenFeature Feature Flags",
13-
"type": "object",
14-
"patternProperties": {
15-
"^[A-Za-z]+$": {
16-
"description": "The flag key that uniquely represents the flag.",
17-
"type": "object",
18-
"properties": {
19-
"name": {
20-
"type": "string"
21-
},
22-
"description": {
23-
"type": "string"
24-
},
25-
"returnType": {
26-
"type": "string",
27-
"enum": ["boolean", "string", "number", "object"],
28-
"default": "boolean"
29-
},
30-
"variants": {
31-
"type": "object",
32-
"patternProperties": {
33-
"^[A-Za-z]+$": {
34-
"properties": {
35-
"value": {
36-
"type": ["string", "number", "boolean", "object"]
37-
}
38-
}
39-
},
40-
"additionalProperties": false
41-
},
42-
"minProperties": 2,
43-
"default": { "enabled": true, "disabled": false }
44-
},
45-
"defaultVariant": {
46-
"type": "string",
47-
"default": "enabled"
48-
},
49-
"state": {
50-
"type": "string",
51-
"enum": ["enabled", "disabled"],
52-
"default": "enabled"
53-
},
54-
"rules": {
55-
"type": "array",
56-
"items": {
57-
"$ref": "#/$defs/rule"
58-
},
59-
"default": []
60-
}
61-
},
62-
"required": ["state"],
63-
"additionalProperties": false
64-
}
65-
},
66-
"additionalProperties": false,
67-
68-
"$defs": {
69-
"rule": {
70-
"type": "object",
71-
"description": "A rule that ",
72-
"properties": {
73-
"action": {
74-
"description": "The action that should be taken if at least one condition evaluates to true.",
75-
"type": "object",
76-
"properties": {
77-
"variant": {
78-
"type": "string",
79-
"description": "The variant that should be return if one of the conditions evaluates to true."
80-
}
81-
},
82-
"required": ["variant"],
83-
"additionalProperties": false
84-
},
85-
"conditions": {
86-
"type": "array",
87-
"description": "The conditions that should that be evaluated.",
88-
"items": {
89-
"type": "object",
90-
"properties": {
91-
"context": {
92-
"type": "string",
93-
"description": "The context key that should be evaluated in this condition"
94-
},
95-
"op": {
96-
"type": "string",
97-
"description": "The operation that should be performed",
98-
"enum": ["equals", "starts_with", "ends_with"]
99-
},
100-
"value": {
101-
"type": "string",
102-
"description": "The value that should be evaluated"
103-
}
104-
},
105-
"required": ["context", "op", "value"],
106-
"additionalProperties": false
107-
}
108-
}
109-
},
110-
"required": ["action", "conditions"],
111-
"additionalProperties": false
112-
}
113-
}
114-
}
115-
`
116-
}
9+
return schema
10+
}

schemas

Submodule schemas added at 680beaa

0 commit comments

Comments
 (0)