-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(flagD): support zero downtime during upgrades (#731)
<!-- Please use this template for your pull request. --> <!-- Please use the sections that you need and delete other sections --> ## This PR <!-- add the description of the PR here --> - implements graceful shutdown of flagD, which leads to zero-downtime -> this means disabling the readiness probes and sending a shutdown event to all connected SDKs - create example manifests for deploying flagD as a standalone Deployment - create Makefile entry to deploy flagD to cluster - create ZD test with README description how to run - create Makefile entry to run ZD test ### Related Issues <!-- add here the GitHub issue that this PR resolves if applicable --> Fixes #728 ### Follow-up Tasks - running ZD test as part of CI #732 --------- Signed-off-by: odubajDT <[email protected]>
- Loading branch information
Showing
10 changed files
with
258 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
labels: | ||
app: flagd | ||
name: flagd | ||
spec: | ||
replicas: 1 | ||
strategy: | ||
type: RollingUpdate | ||
rollingUpdate: | ||
maxSurge: 1 | ||
maxUnavailable: 0 | ||
selector: | ||
matchLabels: | ||
app: flagd | ||
template: | ||
metadata: | ||
labels: | ||
app.kubernetes.io/name: flagd | ||
app: flagd | ||
spec: | ||
containers: | ||
- name: flagd | ||
image: ${IMG} | ||
volumeMounts: | ||
- name: config-volume | ||
mountPath: /etc/flagd | ||
readinessProbe: | ||
httpGet: | ||
path: /readyz | ||
port: 8014 | ||
initialDelaySeconds: 5 | ||
periodSeconds: 5 | ||
livenessProbe: | ||
httpGet: | ||
path: /healthz | ||
port: 8014 | ||
initialDelaySeconds: 5 | ||
periodSeconds: 60 | ||
ports: | ||
- containerPort: 8013 | ||
args: | ||
- start | ||
- --uri | ||
- file:/etc/flagd/config.json | ||
- --debug | ||
volumes: | ||
- name: config-volume | ||
configMap: | ||
name: open-feature-flags | ||
items: | ||
- key: flags | ||
path: config.json | ||
--- | ||
# ConfigMap for Flagd OpenFeatuer provider | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: open-feature-flags | ||
data: | ||
flags: | | ||
{ | ||
"flags": { | ||
"myStringFlag": { | ||
"state": "ENABLED", | ||
"variants": { | ||
"key1": "val1", | ||
"key2": "val2" | ||
}, | ||
"defaultVariant": "key1" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: flagd-svc | ||
spec: | ||
selector: | ||
app.kubernetes.io/name: flagd | ||
ports: | ||
- port: 8013 | ||
targetPort: 8013 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# FlagD Zero downtime test | ||
|
||
## How to run | ||
|
||
Clone this repository and run the following command to deploy a standalone flagD: | ||
|
||
```shell | ||
IMG=your-flagd-image make deploy-dev-env | ||
``` | ||
|
||
This will create a flagd deployment `flagd-dev` namespace. | ||
|
||
To run the test, execute: | ||
|
||
```shell | ||
IMG=your-flagd-image IMG_ZD=your-flagd-image2 make run-zd-test | ||
``` | ||
|
||
Please be aware, you need to build your two custom images with different tags for flagD first. | ||
|
||
To build your images using Docker execute: | ||
|
||
```shell | ||
docker build . -t image-name:tag -f flagd/build.Dockerfile | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: test-zd | ||
spec: | ||
containers: | ||
- name: test-zd | ||
image: curlimages/curl:8.1.2 | ||
# yamllint disable rule:line-length | ||
command: | ||
- 'sh' | ||
- '-c' | ||
- | | ||
for i in $(seq 1 3000); do | ||
curl -H 'Cache-Control: no-cache, no-store' -X POST flagd-svc.$FLAGD_DEV_NAMESPACE.svc.cluster.local:8013/schema.v1.Service/ResolveString?$RANDOM -d '{"flagKey":"myStringFlag","context":{}}' -H "Content-Type: application/json" > ~/out.txt | ||
if ! grep -q "val1" ~/out.txt | ||
then | ||
cat ~/out.txt | ||
echo "\n\nCannot fetch data from flagD, exiting...\n\n" | ||
exit 1 | ||
fi | ||
sleep 1 | ||
done | ||
exit 0 | ||
# yamllint enable rule:line-length |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/bin/sh | ||
|
||
set -eu | ||
|
||
# Store the flagD image to a helper variable | ||
IMG_ORIGINAL=$IMG | ||
|
||
# Create pod requesting the values from flagD | ||
envsubst < test/zero-downtime/test-pod.yaml | kubectl apply -f - -n $ZD_TEST_NAMESPACE | ||
|
||
for count in 1 2 3; | ||
do | ||
# Update the flagD deployment with the second image | ||
IMG=$IMG_ZD | ||
envsubst < config/deployments/flagd/deployment.yaml | kubectl apply -f - -n $FLAGD_DEV_NAMESPACE | ||
kubectl wait --for=condition=available deployment/flagd -n $FLAGD_DEV_NAMESPACE --timeout=30s | ||
|
||
# Wait until the client pod executes curl requests agains flagD | ||
sleep 20 | ||
|
||
# Update the flagDT deployment back to original image | ||
IMG=$IMG_ORIGINAL | ||
envsubst < config/deployments/flagd/deployment.yaml | kubectl apply -f - -n $FLAGD_DEV_NAMESPACE | ||
kubectl wait --for=condition=available deployment/flagd -n $FLAGD_DEV_NAMESPACE --timeout=30s | ||
|
||
# Wait until the client pod executes curl requests agains flagD | ||
sleep 20 | ||
done | ||
|
||
# Pod will fail only when it fails to get a proper response from curl (that means we do not have zero downtime) | ||
# If it is still running, the last curl request was successfull. | ||
kubectl wait --for=condition=ready pod/test-zd -n $ZD_TEST_NAMESPACE --timeout=30s | ||
|
||
# If curl request once not successful and another curl request was, pod might be in a ready state again. | ||
# Therefore we need to check that the restart count is equal to zero -> this means every request provided valid data. | ||
restart_count=$(kubectl get pods test-zd -o=jsonpath='{.status.containerStatuses[0].restartCount}' -n $ZD_TEST_NAMESPACE) | ||
if [ "$restart_count" -ne 0 ]; then | ||
echo "Restart count of the test-zd pod is not equal to zero." | ||
exit 1 | ||
fi | ||
|
||
# Cleanup only when the test passed | ||
kubectl delete ns $ZD_TEST_NAMESPACE --ignore-not-found=true | ||
|
7df8d39
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible performance regression was detected for benchmark 'Go Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold
1.30
.BenchmarkResolveBooleanValue/test_staticBoolFlag - ns/op
2687
ns/op1579
ns/op1.70
BenchmarkResolveBooleanValue/test_targetingBoolFlag - ns/op
14814
ns/op10661
ns/op1.39
BenchmarkResolveStringValue/test_staticStringFlag - ns/op
2152
ns/op1640
ns/op1.31
BenchmarkResolveStringValue/test_targetingStringFlag - ns/op
15188
ns/op10955
ns/op1.39
BenchmarkResolveFloatValue/test:_targetingFloatFlag - ns/op
15707
ns/op11127
ns/op1.41
BenchmarkResolveFloatValue/test:_staticObjectFlag - ns/op
1940
ns/op1485
ns/op1.31
BenchmarkResolveFloatValue/test:_disabledFlag - ns/op
2176
ns/op1663
ns/op1.31
BenchmarkResolveIntValue/test_staticIntFlag - ns/op
2055
ns/op1579
ns/op1.30
BenchmarkResolveIntValue/test_targetingNumberFlag - ns/op
13777
ns/op9888
ns/op1.39
BenchmarkResolveObjectValue/test_staticObjectFlag - ns/op
6936
ns/op5196
ns/op1.33
BenchmarkResolveObjectValue/test_targetingObjectFlag - ns/op
20114
ns/op14467
ns/op1.39
BenchmarkFlag_Evaluation_ResolveString/happy_path - ns/op
12687
ns/op9517
ns/op1.33
BenchmarkFlag_Evaluation_ResolveFloat/happy_path - ns/op
12921
ns/op9787
ns/op1.32
BenchmarkFlag_Evaluation_ResolveInt/happy_path - ns/op
12838
ns/op9662
ns/op1.33
BenchmarkFlag_Evaluation_ResolveObject/happy_path - ns/op
15750
ns/op11423
ns/op1.38
This comment was automatically generated by workflow using github-action-benchmark.