Skip to content

Commit

Permalink
drenv: Add an interesting demo
Browse files Browse the repository at this point in the history
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 '<h1>'
  <h1>Welcome to nginx!</h1>

  OR

  pass the obtained url on your favorite browser to see the
  welcome web page of nginx server.

Updates: RamenDR#643
Signed-off-by: Shwetha K Acharya <sacharya@redhat.com>
  • Loading branch information
Shwetha-Acharya authored and nirs committed Jun 22, 2023
1 parent 79607ae commit 21aed61
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions test/addons/demo/deployment.yaml
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions test/addons/demo/ingress.yaml
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions test/addons/demo/service.yaml
Original file line number Diff line number Diff line change
@@ -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
42 changes: 42 additions & 0 deletions test/addons/demo/start
Original file line number Diff line number Diff line change
@@ -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)
26 changes: 26 additions & 0 deletions test/addons/demo/test
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions test/envs/demo.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 21aed61

Please sign in to comment.