Skip to content

Commit

Permalink
updating openfeature tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
Mauricio Salatino committed Jun 9, 2023
1 parent dd886e1 commit aaa3ce1
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 16 deletions.
21 changes: 5 additions & 16 deletions openfeature/README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
# Openfeature for Feature Flagging

On this tutorial we will be writing a small application that consume feature flags that are managed by OpenFeature, a CNCF initiative for feature flags backed up by multiple vendors.
On this short tutorial we will enable our application to use Feature Flags by using Open Feature `flagd`. This enable each of the application services (including the Frontend) to consume and evaluate feature flags, in this case defined inside a Kubernertes configMap.

## Installation

Based on the documentation that you can find in github
https://github.com/open-feature/open-feature-operator/blob/main/docs/installation.md


Prerequisites (CertManager):
```
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.10.1/cert-manager.yaml
kubectl wait --for=condition=Available=True deploy --all -n 'cert-manager'
```

Installing the OpenFeature K8s Operator with Helm:
We will deploy a `flagd` Proxy which is in charge of mounting a Kubernetes `ConfigMap` that contains the Feature Flag definitions.
Our application then can interact with this proxy to consume and evaluate the value of different feature flags.
Notice that this file also contains the `ConfigMap` with the feature flags.

```
helm repo add openfeature https://open-feature.github.io/open-feature-operator/
helm repo update
helm upgrade --install openfeature openfeature/open-feature-operator
kubectl apply flagd.yaml
```

121 changes: 121 additions & 0 deletions openfeature/flagd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: flagd
labels:
app: flagd
spec:
replicas: 1
selector:
matchLabels:
app: flagd
template:
metadata:
labels:
app: flagd
spec:
containers:
- name: flagd
image: ghcr.io/open-feature/flagd:v0.5.3
args: ["start", "-f", "file:etc/config/flag-config.json"]
ports:
- containerPort: 8013
volumeMounts:
- name: flag-config-volume
mountPath: /etc/config
volumes:
- name: flag-config-volume
configMap:
name: flag-configuration
---
apiVersion: v1
kind: Service
metadata:
name: flagd
spec:
selector:
app: flagd
ports:
- protocol: TCP
port: 8013
targetPort: 8013
---
apiVersion: v1
kind: ConfigMap
metadata:
name: flag-configuration
namespace: default
data:
flag-config.json: |
{
"flags": {
"myBoolFlag": {
"state": "ENABLED",
"variants": {
"on": true,
"off": false
},
"defaultVariant": "on"
},
"myStringFlag": {
"state": "ENABLED",
"variants": {
"key1": "val1",
"key2": "val2"
},
"defaultVariant": "key1"
},
"myFloatFlag": {
"state": "ENABLED",
"variants": {
"one": 1.23,
"two": 2.34
},
"defaultVariant": "one"
},
"myIntFlag": {
"state": "ENABLED",
"variants": {
"one": 1,
"two": 2
},
"defaultVariant": "one"
},
"myObjectFlag": {
"state": "ENABLED",
"variants": {
"object1": {
"key": "val"
},
"object2": {
"key": true
}
},
"defaultVariant": "object1"
},
"isColorYellow": {
"state": "ENABLED",
"variants": {
"on": true,
"off": false
},
"defaultVariant": "off",
"targeting": {
"if": [
{
"==": [
{
"var": [
"color"
]
},
"yellow"
]
},
"on",
"off"
]
}
}
}
}

0 comments on commit aaa3ce1

Please sign in to comment.