Skip to content

Commit 1e0c27e

Browse files
authored
Merge pull request #29 from toddbaert/embed-schema-update-samples
Add submodule for schemas, embed in utils
2 parents 99a1745 + b2a1bf2 commit 1e0c27e

File tree

11 files changed

+100
-130
lines changed

11 files changed

+100
-130
lines changed

.github/workflows/build-oci.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
21
name: ci
32

43
on:
54
push:
6-
branches:
7-
- main
5+
branches:
6+
- main
87

98
env:
109
REGISTRY: ghcr.io
@@ -16,20 +15,22 @@ jobs:
1615
steps:
1716
- name: Checkout
1817
uses: actions/checkout@v3
19-
18+
with:
19+
submodules: recursive
20+
2021
- name: Log in to the Container registry
2122
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
2223
with:
2324
registry: ${{ env.REGISTRY }}
2425
username: ${{ github.actor }}
2526
password: ${{ secrets.GITHUB_TOKEN }}
26-
27+
2728
- name: Extract metadata (tags, labels) for Docker
2829
id: meta
2930
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
3031
with:
31-
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
32-
32+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
33+
3334
- name: Set up QEMU
3435
uses: docker/setup-qemu-action@master
3536
with:

.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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,5 @@ root@nginx:/# curl localhost:8080
7373

7474
#### Run the example
7575

76-
1. `kubectl apply -f config/samples/crds/featureflagconfiguration.yaml`
77-
1. `kubectl apply -f config/samples/pod.yaml`
76+
1. Apply the end-to-end example: `kubectl apply -f config/samples/end-to-end.yaml`
77+
1. Update the value of the `defaultVariant` field in the custom resource instance in `config/samples/end-to-end.yaml` and re-apply to update the flag value!

config/manager/kustomization.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
resources:
2-
- manager.yaml
2+
- manager.yaml
33

44
generatorOptions:
55
disableNameSuffixHash: true
66

77
configMapGenerator:
8-
- files:
9-
- controller_manager_config.yaml
10-
name: manager-config
8+
- files:
9+
- controller_manager_config.yaml
10+
name: manager-config
1111
apiVersion: kustomize.config.k8s.io/v1beta1
1212
kind: Kustomization
1313
images:
14-
- name: controller
15-
newName: controller
16-
newTag: latest
14+
- name: controller
15+
newName: controller
16+
newTag: latest

config/samples/end-to-end.yaml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# A basic flag custom resource
2+
3+
apiVersion: core.openfeature.dev/v1alpha1
4+
kind: FeatureFlagConfiguration
5+
metadata:
6+
name: end-to-end
7+
spec:
8+
featureFlagSpec: |
9+
{
10+
"booleanFlags": {
11+
"new-welcome-message": {
12+
"state": "enabled",
13+
"variants": {
14+
"enabled": true,
15+
"disabled": false
16+
},
17+
"defaultVariant": "enabled",
18+
"rules": []
19+
}
20+
}
21+
}
22+
23+
---
24+
# Deployment of a demo-app using our custom resource
25+
26+
apiVersion: apps/v1
27+
kind: Deployment
28+
metadata:
29+
name: openfeature-nest-example-deployment
30+
labels:
31+
app: openfeature-nest-example
32+
spec:
33+
replicas: 3
34+
selector:
35+
matchLabels:
36+
app: openfeature-nest-example
37+
template:
38+
metadata:
39+
labels:
40+
app: openfeature-nest-example
41+
annotations:
42+
openfeature.dev: "enabled"
43+
openfeature.dev/featureflagconfiguration: "end-to-end"
44+
spec:
45+
containers:
46+
- name: openfeature-nest-example
47+
image: ghcr.io/open-feature/open-feature-nest-example:latest
48+
ports:
49+
- containerPort: 3000
50+
51+
---
52+
# Service exposed using NodePort
53+
54+
apiVersion: v1
55+
kind: Service
56+
metadata:
57+
name: openfeature-nest-example-service
58+
spec:
59+
type: NodePort
60+
selector:
61+
app: openfeature-nest-example
62+
ports:
63+
# By default and for convenience, the `targetPort` is set to the same value as the `port` field.
64+
- port: 30000
65+
targetPort: 3000
66+
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)