From 21aed610a22a6f2de93af43f84c34078a90c11d3 Mon Sep 17 00:00:00 2001 From: Shwetha K Acharya Date: Mon, 20 Mar 2023 18:33:08 +0530 Subject: [PATCH] drenv: Add an interesting demo demo environment deploys a web page accessible from a web browser or curl command. This is an attempt to create an interesting demonstration of drenv tool with an interactive use case. Example run: $ drenv start envs/demo.yaml 2023-06-14 17:40:35,327 INFO [demo] Starting environment 2023-06-14 17:40:36,008 INFO [demo1] Starting minikube cluster 2023-06-14 17:40:37,069 INFO [demo2] Starting minikube cluster 2023-06-14 17:45:00,790 INFO [demo1] Cluster started in 264.78 seconds 2023-06-14 17:45:00,790 INFO [demo1/0] Running addons/demo/start 2023-06-14 17:45:30,166 INFO [demo2] Cluster started in 293.10 seconds 2023-06-14 17:45:30,167 INFO [demo2/0] Running addons/demo/start 2023-06-14 17:46:09,158 INFO [demo1/0] addons/demo/start completed in 68.37 seconds 2023-06-14 17:46:09,158 INFO [demo1/0] Running addons/demo/test 2023-06-14 17:46:09,857 INFO [demo1/0] addons/demo/test completed in 0.70 seconds 2023-06-14 17:46:45,639 INFO [demo2/0] addons/demo/start completed in 75.47 seconds 2023-06-14 17:46:45,640 INFO [demo2/0] Running addons/demo/test 2023-06-14 17:46:45,989 INFO [demo2/0] addons/demo/test completed in 0.35 seconds 2023-06-14 17:46:45,989 INFO [demo] Environment started in 370.66 seconds Example interaction with the webpage for the context demo1: - obtain the url of the deployed web page $minikube ip --profile demo1 http://192.168.122.133 - use curl to access the web page in html format $curl http://192.168.122.133/ | grep '

'

Welcome to nginx!

OR pass the obtained url on your favorite browser to see the welcome web page of nginx server. Updates: #643 Signed-off-by: Shwetha K Acharya --- test/README.md | 1 + test/addons/demo/deployment.yaml | 25 +++++++++++++++++++ test/addons/demo/ingress.yaml | 18 ++++++++++++++ test/addons/demo/service.yaml | 16 ++++++++++++ test/addons/demo/start | 42 ++++++++++++++++++++++++++++++++ test/addons/demo/test | 26 ++++++++++++++++++++ test/envs/demo.yaml | 21 ++++++++++++++++ 7 files changed, 149 insertions(+) create mode 100644 test/addons/demo/deployment.yaml create mode 100644 test/addons/demo/ingress.yaml create mode 100644 test/addons/demo/service.yaml create mode 100755 test/addons/demo/start create mode 100755 test/addons/demo/test create mode 100644 test/envs/demo.yaml diff --git a/test/README.md b/test/README.md index 9bf19ccfd..28b20b910 100644 --- a/test/README.md +++ b/test/README.md @@ -545,6 +545,7 @@ simpler and faster to work with a minimal environment. - `test.yaml` - for testing `drenv` - `example.yaml` - example for experimenting with the `drenv` tool +- `demo.yaml` - interactive demo for exploring the `drenv` tool - `external.yaml` - example for using external clusters - `minio.yaml` - for testing `minio` deployment - `ocm.yaml` - for testing `ocm` deployment diff --git a/test/addons/demo/deployment.yaml b/test/addons/demo/deployment.yaml new file mode 100644 index 000000000..bf68d6db6 --- /dev/null +++ b/test/addons/demo/deployment.yaml @@ -0,0 +1,25 @@ +# SPDX-FileCopyrightText: The RamenDR authors +# SPDX-License-Identifier: Apache-2.0 +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: demo-deployment + labels: + app: demo +spec: + replicas: 1 + selector: + matchLabels: + app: demo + template: + metadata: + labels: + app: demo + spec: + containers: + - name: demo + image: docker.io/library/nginx:stable + ports: + - containerPort: 80 + name: demo-port diff --git a/test/addons/demo/ingress.yaml b/test/addons/demo/ingress.yaml new file mode 100644 index 000000000..a4876c756 --- /dev/null +++ b/test/addons/demo/ingress.yaml @@ -0,0 +1,18 @@ +# SPDX-FileCopyrightText: The RamenDR authors +# SPDX-License-Identifier: Apache-2.0 +--- +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: demo-ingress +spec: + rules: + - http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: demo-service + port: + number: 80 diff --git a/test/addons/demo/service.yaml b/test/addons/demo/service.yaml new file mode 100644 index 000000000..0499be29b --- /dev/null +++ b/test/addons/demo/service.yaml @@ -0,0 +1,16 @@ +# SPDX-FileCopyrightText: The RamenDR authors +# SPDX-License-Identifier: Apache-2.0 +--- +apiVersion: v1 +kind: Service +metadata: + name: demo-service + labels: + app: demo +spec: + type: NodePort + ports: + - port: 80 + name: demo-port + selector: + app: demo diff --git a/test/addons/demo/start b/test/addons/demo/start new file mode 100755 index 000000000..7d0652a32 --- /dev/null +++ b/test/addons/demo/start @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 + +# SPDX-FileCopyrightText: The RamenDR authors +# SPDX-License-Identifier: Apache-2.0 + +import os +import sys + +from drenv import kubectl + +if len(sys.argv) != 2: + print(f"Usage: {sys.argv[0]} cluster") + sys.exit(1) + +os.chdir(os.path.dirname(__file__)) +cluster = sys.argv[1] + +print("Deploying demo") +kubectl.apply("--filename", "deployment.yaml", context=cluster) + +print("Creating the service") +kubectl.apply("--filename", "service.yaml", context=cluster) + +print("Waiting until deployment is rolled out") +kubectl.rollout( + "status", + "deployment", + "--timeout=120s", + context=cluster, +) + +print("Waiting until ingress controller deployment is rolled out") +kubectl.rollout( + "status", + "ingress", + "--namespace=ingress-nginx", + "--timeout=120s", + context=cluster, +) + +print("Configuring ingress") +kubectl.apply("--filename", "ingress.yaml", context=cluster) diff --git a/test/addons/demo/test b/test/addons/demo/test new file mode 100755 index 000000000..4146d9af7 --- /dev/null +++ b/test/addons/demo/test @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 + +# SPDX-FileCopyrightText: The RamenDR authors +# SPDX-License-Identifier: Apache-2.0 + +import os +import sys +import subprocess + +print(sys.argv) +if len(sys.argv) != 2: + print(f"Usage: {sys.argv[0]} cluster") + sys.exit(1) + +os.chdir(os.path.dirname(__file__)) +cluster = sys.argv[1] + +print("Testing demo deployment") + +cmd = ["minikube", "ip", "--profile", cluster] +node_addr = subprocess.check_output(cmd).decode().rstrip() + +cmd = ["curl", f"http://{node_addr}/"] +out = subprocess.check_output(cmd).decode().rstrip() + +assert "Welcome to nginx!" in out diff --git a/test/envs/demo.yaml b/test/envs/demo.yaml new file mode 100644 index 000000000..83e815213 --- /dev/null +++ b/test/envs/demo.yaml @@ -0,0 +1,21 @@ +# SPDX-FileCopyrightText: The RamenDR authors +# SPDX-License-Identifier: Apache-2.0 + +# Demo environment. +--- +name: demo +templates: + - name: "demo-cluster" + driver: kvm2 + container_runtime: containerd + network: default + addons: + - ingress + workers: + - addons: + - name: demo +profiles: + - name: demo1 + template: demo-cluster + - name: demo2 + template: demo-cluster