From 92134cc015e1c679abd030c4f0a5e837d83deec5 Mon Sep 17 00:00:00 2001 From: odubajDT <93584209+odubajDT@users.noreply.github.com> Date: Tue, 25 Apr 2023 17:14:13 +0200 Subject: [PATCH] test: introduce e2e tests for multiple source providers (#452) Signed-off-by: odubajDT --- renovate.json | 23 +++- test/e2e/kuttl/assets/manifests.yaml | 112 ++++++++++++++++++ .../kuttl/fsconfig-file-sync/00-assert.yaml | 4 + .../kuttl/fsconfig-file-sync/00-install.yaml | 14 +++ .../kuttl/fsconfig-file-sync/00-teststep.yaml | 4 + .../kuttl/fsconfig-file-sync/01-assert.yaml | 16 +++ .../fsconfig-flagd-proxy-sync/00-assert.yaml | 4 + .../fsconfig-flagd-proxy-sync/00-install.yaml | 14 +++ .../00-teststep.yaml | 4 + .../fsconfig-flagd-proxy-sync/01-assert.yaml | 16 +++ .../kuttl/fsconfig-k8s-sync/00-assert.yaml | 4 + .../kuttl/fsconfig-k8s-sync/00-install.yaml | 14 +++ .../kuttl/fsconfig-k8s-sync/00-teststep.yaml | 4 + .../kuttl/fsconfig-k8s-sync/01-assert.yaml | 17 +++ 14 files changed, 249 insertions(+), 1 deletion(-) create mode 100644 test/e2e/kuttl/assets/manifests.yaml create mode 100644 test/e2e/kuttl/fsconfig-file-sync/00-assert.yaml create mode 100644 test/e2e/kuttl/fsconfig-file-sync/00-install.yaml create mode 100644 test/e2e/kuttl/fsconfig-file-sync/00-teststep.yaml create mode 100644 test/e2e/kuttl/fsconfig-file-sync/01-assert.yaml create mode 100644 test/e2e/kuttl/fsconfig-flagd-proxy-sync/00-assert.yaml create mode 100644 test/e2e/kuttl/fsconfig-flagd-proxy-sync/00-install.yaml create mode 100644 test/e2e/kuttl/fsconfig-flagd-proxy-sync/00-teststep.yaml create mode 100644 test/e2e/kuttl/fsconfig-flagd-proxy-sync/01-assert.yaml create mode 100644 test/e2e/kuttl/fsconfig-k8s-sync/00-assert.yaml create mode 100644 test/e2e/kuttl/fsconfig-k8s-sync/00-install.yaml create mode 100644 test/e2e/kuttl/fsconfig-k8s-sync/00-teststep.yaml create mode 100644 test/e2e/kuttl/fsconfig-k8s-sync/01-assert.yaml diff --git a/renovate.json b/renovate.json index bf2b762e0..f1fefe245 100644 --- a/renovate.json +++ b/renovate.json @@ -88,7 +88,28 @@ "depNameTemplate": "open-feature/flagd", "datasourceTemplate": "github-releases", "extractVersionTemplate": "^flagd-proxy/(?.*)$" + }, + { + "fileMatch": [ + "^test/e2e/kuttl/fsconfig-flagd-proxy-sync/01-assert.yaml$", + "^test/e2e/kuttl/fsconfig-k8s-sync/01-assert.yaml$", + "^test/e2e/kuttl/fsconfig-file-sync/01-assert.yaml$" + ], + "matchStrings": ["image: ghcr\\.io\/open-feature\/flagd:(?.*?)\\s"], + "depNameTemplate": "open-feature/flagd", + "datasourceTemplate": "github-releases", + "extractVersionTemplate": "^flagd-proxy/(?.*)$" + }, + { + "fileMatch": [ + "^test/e2e/kuttl/fsconfig-flagd-proxy-sync/00-install.yaml$", + "^test/e2e/kuttl/fsconfig-k8s-sync/00-install.yaml$", + "^test/e2e/kuttl/fsconfig-file-sync/00-install.yaml$" + ], + "matchStrings": ["tag: (?.*?)\\s"], + "depNameTemplate": "open-feature/flagd", + "datasourceTemplate": "github-releases", + "extractVersionTemplate": "^flagd-proxy/(?.*)$" } ] - } diff --git a/test/e2e/kuttl/assets/manifests.yaml b/test/e2e/kuttl/assets/manifests.yaml new file mode 100644 index 000000000..52665f75c --- /dev/null +++ b/test/e2e/kuttl/assets/manifests.yaml @@ -0,0 +1,112 @@ +apiVersion: core.openfeature.dev/v1alpha1 +kind: FeatureFlagConfiguration +metadata: + name: end-to-end-test +spec: + featureFlagSpec: | + { + "flags": { + "simple-flag": { + "state": "ENABLED", + "variants": { + "on": true, + "off": false + }, + "defaultVariant": "on" + } + } + } +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: open-feature-e2e-nginx-conf +data: + nginx.conf: | + events {} + http { + server { + location / { + proxy_pass http://127.0.0.1:8013; + } + } + } +--- +# Deployment of nginx using our custom resource +apiVersion: apps/v1 +kind: Deployment +metadata: + name: open-feature-e2e-test-deployment + labels: + app: open-feature-e2e-test +spec: + replicas: 1 + selector: + matchLabels: + app: open-feature-e2e-test + template: + metadata: + labels: + app: open-feature-e2e-test + annotations: + openfeature.dev/enabled: "true" + openfeature.dev/flagsourceconfiguration: "source-configuration" + spec: + volumes: + - name: open-feature-e2e-nginx-conf + configMap: + name: open-feature-e2e-nginx-conf + items: + - key: nginx.conf + path: nginx.conf + containers: + - name: open-feature-e2e-test + image: nginx:stable-alpine + ports: + - containerPort: 80 + volumeMounts: + - name: open-feature-e2e-nginx-conf + mountPath: /etc/nginx + readOnly: true +--- +apiVersion: v1 +kind: Service +metadata: + name: open-feature-e2e-test-service +spec: + type: ClusterIP + selector: + app: open-feature-e2e-test + ports: + - protocol: TCP + port: 30000 + targetPort: 80 +--- +apiVersion: batch/v1 +kind: Job +metadata: + name: flagd-query-test +spec: + backoffLimit: 10 + template: + spec: + containers: + - name: test-flagd-endpoint + image: curlimages/curl:7.72.0 + args: + - /bin/sh + - -ec + - | + EXPECTED_RESPONSE='{"value":true,"reason":"STATIC","variant":"on"}' + RESPONSE=$(curl -s -X POST "open-feature-e2e-test-service:30000/schema.v1.Service/ResolveBoolean" -d '{"flagKey":"simple-flag","context":{}}' -H "Content-Type: application/json") + RESPONSE="${RESPONSE//[[:space:]]/}" # strip whitespace from response + + if [ "$RESPONSE" == "$EXPECTED_RESPONSE" ] + then + exit 0 + fi + + echo "Expected response: $EXPECTED_RESPONSE" + echo "Got response: $RESPONSE" + exit 1 + restartPolicy: OnFailure diff --git a/test/e2e/kuttl/fsconfig-file-sync/00-assert.yaml b/test/e2e/kuttl/fsconfig-file-sync/00-assert.yaml new file mode 100644 index 000000000..0ce96ba41 --- /dev/null +++ b/test/e2e/kuttl/fsconfig-file-sync/00-assert.yaml @@ -0,0 +1,4 @@ +apiVersion: kuttl.dev/v1beta1 +kind: TestAssert +commands: + - command: kubectl wait --for=condition=complete job flagd-query-test -n $NAMESPACE diff --git a/test/e2e/kuttl/fsconfig-file-sync/00-install.yaml b/test/e2e/kuttl/fsconfig-file-sync/00-install.yaml new file mode 100644 index 000000000..113d914a1 --- /dev/null +++ b/test/e2e/kuttl/fsconfig-file-sync/00-install.yaml @@ -0,0 +1,14 @@ +--- +apiVersion: core.openfeature.dev/v1alpha3 +kind: FlagSourceConfiguration +metadata: + name: source-configuration +spec: + metricsPort: 8080 + evaluator: json + defaultSyncProvider: filepath + tag: v0.5.1 + sources: + - source: end-to-end-test + provider: filepath + probesEnabled: true diff --git a/test/e2e/kuttl/fsconfig-file-sync/00-teststep.yaml b/test/e2e/kuttl/fsconfig-file-sync/00-teststep.yaml new file mode 100644 index 000000000..b50b8156c --- /dev/null +++ b/test/e2e/kuttl/fsconfig-file-sync/00-teststep.yaml @@ -0,0 +1,4 @@ +apiVersion: kuttl.dev/v1 +kind: TestStep +apply: + - ../assets/manifests.yaml diff --git a/test/e2e/kuttl/fsconfig-file-sync/01-assert.yaml b/test/e2e/kuttl/fsconfig-file-sync/01-assert.yaml new file mode 100644 index 000000000..5006c645f --- /dev/null +++ b/test/e2e/kuttl/fsconfig-file-sync/01-assert.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Pod +metadata: + annotations: + openfeature.dev/enabled: "true" + openfeature.dev/flagsourceconfiguration: source-configuration + labels: + app: open-feature-e2e-test +status: + phase: Running +spec: + containers: + - name: open-feature-e2e-test + image: nginx:stable-alpine + - name: flagd # this part verifies flagd injection happened + image: ghcr.io/open-feature/flagd:v0.5.1 diff --git a/test/e2e/kuttl/fsconfig-flagd-proxy-sync/00-assert.yaml b/test/e2e/kuttl/fsconfig-flagd-proxy-sync/00-assert.yaml new file mode 100644 index 000000000..0ce96ba41 --- /dev/null +++ b/test/e2e/kuttl/fsconfig-flagd-proxy-sync/00-assert.yaml @@ -0,0 +1,4 @@ +apiVersion: kuttl.dev/v1beta1 +kind: TestAssert +commands: + - command: kubectl wait --for=condition=complete job flagd-query-test -n $NAMESPACE diff --git a/test/e2e/kuttl/fsconfig-flagd-proxy-sync/00-install.yaml b/test/e2e/kuttl/fsconfig-flagd-proxy-sync/00-install.yaml new file mode 100644 index 000000000..586eac7c6 --- /dev/null +++ b/test/e2e/kuttl/fsconfig-flagd-proxy-sync/00-install.yaml @@ -0,0 +1,14 @@ +--- +apiVersion: core.openfeature.dev/v1alpha3 +kind: FlagSourceConfiguration +metadata: + name: source-configuration +spec: + metricsPort: 8080 + evaluator: json + defaultSyncProvider: flagd-proxy + tag: v0.5.1 + sources: + - source: end-to-end-test + provider: flagd-proxy + probesEnabled: true diff --git a/test/e2e/kuttl/fsconfig-flagd-proxy-sync/00-teststep.yaml b/test/e2e/kuttl/fsconfig-flagd-proxy-sync/00-teststep.yaml new file mode 100644 index 000000000..b50b8156c --- /dev/null +++ b/test/e2e/kuttl/fsconfig-flagd-proxy-sync/00-teststep.yaml @@ -0,0 +1,4 @@ +apiVersion: kuttl.dev/v1 +kind: TestStep +apply: + - ../assets/manifests.yaml diff --git a/test/e2e/kuttl/fsconfig-flagd-proxy-sync/01-assert.yaml b/test/e2e/kuttl/fsconfig-flagd-proxy-sync/01-assert.yaml new file mode 100644 index 000000000..5006c645f --- /dev/null +++ b/test/e2e/kuttl/fsconfig-flagd-proxy-sync/01-assert.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Pod +metadata: + annotations: + openfeature.dev/enabled: "true" + openfeature.dev/flagsourceconfiguration: source-configuration + labels: + app: open-feature-e2e-test +status: + phase: Running +spec: + containers: + - name: open-feature-e2e-test + image: nginx:stable-alpine + - name: flagd # this part verifies flagd injection happened + image: ghcr.io/open-feature/flagd:v0.5.1 diff --git a/test/e2e/kuttl/fsconfig-k8s-sync/00-assert.yaml b/test/e2e/kuttl/fsconfig-k8s-sync/00-assert.yaml new file mode 100644 index 000000000..0ce96ba41 --- /dev/null +++ b/test/e2e/kuttl/fsconfig-k8s-sync/00-assert.yaml @@ -0,0 +1,4 @@ +apiVersion: kuttl.dev/v1beta1 +kind: TestAssert +commands: + - command: kubectl wait --for=condition=complete job flagd-query-test -n $NAMESPACE diff --git a/test/e2e/kuttl/fsconfig-k8s-sync/00-install.yaml b/test/e2e/kuttl/fsconfig-k8s-sync/00-install.yaml new file mode 100644 index 000000000..050f7ff0f --- /dev/null +++ b/test/e2e/kuttl/fsconfig-k8s-sync/00-install.yaml @@ -0,0 +1,14 @@ +--- +apiVersion: core.openfeature.dev/v1alpha3 +kind: FlagSourceConfiguration +metadata: + name: source-configuration +spec: + metricsPort: 8080 + evaluator: json + defaultSyncProvider: kubernetes + tag: v0.5.1 + sources: + - source: end-to-end-test + provider: kubernetes + probesEnabled: true diff --git a/test/e2e/kuttl/fsconfig-k8s-sync/00-teststep.yaml b/test/e2e/kuttl/fsconfig-k8s-sync/00-teststep.yaml new file mode 100644 index 000000000..b50b8156c --- /dev/null +++ b/test/e2e/kuttl/fsconfig-k8s-sync/00-teststep.yaml @@ -0,0 +1,4 @@ +apiVersion: kuttl.dev/v1 +kind: TestStep +apply: + - ../assets/manifests.yaml diff --git a/test/e2e/kuttl/fsconfig-k8s-sync/01-assert.yaml b/test/e2e/kuttl/fsconfig-k8s-sync/01-assert.yaml new file mode 100644 index 000000000..ba2e12cbc --- /dev/null +++ b/test/e2e/kuttl/fsconfig-k8s-sync/01-assert.yaml @@ -0,0 +1,17 @@ +apiVersion: v1 +kind: Pod +metadata: + annotations: + openfeature.dev/allowkubernetessync: "true" + openfeature.dev/enabled: "true" + openfeature.dev/flagsourceconfiguration: source-configuration + labels: + app: open-feature-e2e-test +status: + phase: Running +spec: + containers: + - name: open-feature-e2e-test + image: nginx:stable-alpine + - name: flagd # this part verifies flagd injection happened + image: ghcr.io/open-feature/flagd:v0.5.1