Skip to content

Commit

Permalink
Add --skip-addons option
Browse files Browse the repository at this point in the history
This is useful for starting a stopped working environment quickly
without trying to redeploy everything. The main motivation is using a
pre created environment in location with weak network like a conference.

Other use cases are working around bugs in addons that do not work well
when starting a stopped cluster, for example clusteradm.

With `--skip-addons` we skip the `start` and `stop` hooks, but we do run
the `test` hooks. This is useful for starting a stopped environment
faster but testing that the environment works. To skip all hooks run
with both `--skip-addons` and `--skip-tests`.

Example run:

    $ drenv start --skip-addons --skip-tests $env
    2023-11-20 00:59:25,341 INFO    [rdr-kubevirt] Starting environment
    2023-11-20 00:59:25,464 INFO    [dr1] Starting minikube cluster
    2023-11-20 00:59:29,566 INFO    [hub] Starting minikube cluster
    2023-11-20 00:59:29,578 INFO    [dr2] Starting minikube cluster
    2023-11-20 01:00:23,402 INFO    [dr1] Cluster started in 57.94 seconds
    2023-11-20 01:00:23,402 INFO    [dr1] Configuring containerd
    2023-11-20 01:00:24,936 INFO    [dr1] Waiting until all deployments are available
    2023-11-20 01:00:28,749 INFO    [hub] Cluster started in 59.18 seconds
    2023-11-20 01:00:28,750 INFO    [hub] Waiting until all deployments are available
    2023-11-20 01:00:53,834 INFO    [dr2] Cluster started in 84.26 seconds
    2023-11-20 01:00:53,834 INFO    [dr2] Configuring containerd
    2023-11-20 01:00:55,042 INFO    [dr2] Waiting until all deployments are available
    2023-11-20 01:01:01,063 INFO    [hub] Deployments are available in 32.31 seconds
    2023-11-20 01:01:09,482 INFO    [dr1] Deployments are available in 44.55 seconds
    2023-11-20 01:01:34,661 INFO    [dr2] Deployments are available in 39.62 seconds
    2023-11-20 01:01:34,661 INFO    [rdr-kubevirt] Dumping ramen e2e config to '/home/nsoffer/.config/drenv/rdr-kubevirt'
    2023-11-20 01:01:34,827 INFO    [rdr-kubevirt] Environment started in 129.49 seconds

Signed-off-by: Nir Soffer <[email protected]>
  • Loading branch information
nirs committed Dec 11, 2023
1 parent 72ff7ac commit a327148
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions test/drenv/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,16 @@ def main():
p = argparse.ArgumentParser(prog="drenv")
p.add_argument("-v", "--verbose", action="store_true", help="Be more verbose")
p.add_argument(
"--skip-tests", dest="run_tests", action="store_false", help="Skip self tests"
"--skip-tests",
dest="run_tests",
action="store_false",
help="Skip addons 'test' hooks",
)
p.add_argument(
"--skip-addons",
dest="run_addons",
action="store_false",
help="Skip addons 'start' and 'stop' hooks",
)
p.add_argument("command", choices=commands, help="Command to run")
p.add_argument("--name-prefix", help="Prefix profile names")
Expand All @@ -52,7 +61,12 @@ def main():
def cmd_start(env, args):
start = time.monotonic()
logging.info("[%s] Starting environment", env["name"])
hooks = ["start", "test"] if args.run_tests else ["start"]

hooks = []
if args.run_addons:
hooks.append("start")
if args.run_tests:
hooks.append("test")

# Delaying `minikube start` ensures cluster start order.
execute(
Expand All @@ -62,7 +76,9 @@ def cmd_start(env, args):
hooks=hooks,
verbose=args.verbose,
)
execute(run_worker, env["workers"], hooks=hooks)

if hooks:
execute(run_worker, env["workers"], hooks=hooks)

if "ramen" in env:
ramen.dump_e2e_config(env)
Expand All @@ -77,7 +93,8 @@ def cmd_start(env, args):
def cmd_stop(env, args):
start = time.monotonic()
logging.info("[%s] Stopping environment", env["name"])
execute(stop_cluster, env["profiles"])
hooks = ["stop"] if args.run_addons else []
execute(stop_cluster, env["profiles"], hooks=hooks)
logging.info(
"[%s] Environment stopped in %.2f seconds",
env["name"],
Expand Down Expand Up @@ -147,17 +164,18 @@ def start_cluster(profile, hooks=(), verbose=False, **options):
if is_restart:
wait_for_deployments(profile)

execute(run_worker, profile["workers"], hooks=hooks)
if hooks:
execute(run_worker, profile["workers"], hooks=hooks)


def stop_cluster(profile, **options):
def stop_cluster(profile, hooks=(), **options):
cluster_status = cluster.status(profile["name"])

if cluster_status == cluster.READY:
if cluster_status == cluster.READY and hooks:
execute(
run_worker,
profile["workers"],
hooks=["stop"],
hooks=hooks,
reverse=True,
allow_failure=True,
)
Expand Down

0 comments on commit a327148

Please sign in to comment.