From 1e024de99e80b444f26cafbe663c74bce4b2da93 Mon Sep 17 00:00:00 2001 From: Nir Soffer Date: Wed, 15 Jan 2025 21:50:31 +0200 Subject: [PATCH] drenv: Support verbose gather If drenv is run in verbose mode, pass --verbose flag to kubectl-gather to log more verbose gather logs. This may be useful to debug issues in kubectl gather in the CI environment. Example log with this change: % drenv gather envs/regional-dr.yaml -v 2025-01-15 22:13:31,064 DEBUG [envfile] Detected os: 'darwin' 2025-01-15 22:13:31,064 DEBUG [envfile] Detected machine: 'arm64' 2025-01-15 22:13:31,064 DEBUG [envfile] Using provider: 'lima' 2025-01-15 22:13:31,064 DEBUG [envfile] Using driver: '' 2025-01-15 22:13:31,064 DEBUG [envfile] Using network: '' 2025-01-15 22:13:31,064 DEBUG [envfile] Detected os: 'darwin' 2025-01-15 22:13:31,064 DEBUG [envfile] Detected machine: 'arm64' 2025-01-15 22:13:31,064 DEBUG [envfile] Using provider: 'lima' 2025-01-15 22:13:31,064 DEBUG [envfile] Using driver: '' 2025-01-15 22:13:31,064 DEBUG [envfile] Using network: '' 2025-01-15 22:13:31,064 DEBUG [envfile] Detected os: 'darwin' 2025-01-15 22:13:31,064 DEBUG [envfile] Detected machine: 'arm64' 2025-01-15 22:13:31,064 DEBUG [envfile] Using provider: 'lima' 2025-01-15 22:13:31,064 DEBUG [envfile] Using driver: '' 2025-01-15 22:13:31,064 DEBUG [envfile] Using network: '' 2025-01-15 22:13:31,064 INFO [rdr] Gathering environment 2025-01-15 22:13:31,356 INFO [gather] Using kubeconfig "/Users/nsoffer/.kube/config" 2025-01-15 22:13:31,359 INFO [gather] Gathering from all namespaces 2025-01-15 22:13:31,359 INFO [gather] Using all addons 2025-01-15 22:13:31,359 INFO [gather] Storing data in "gather.20250115221331" 2025-01-15 22:13:31,359 INFO [gather] Gathering from cluster "dr1" 2025-01-15 22:13:31,359 INFO [gather] Gathering from cluster "dr2" 2025-01-15 22:13:31,359 INFO [gather] Gathering from cluster "hub" 2025-01-15 22:13:31,406 DEBUG [gather.dr2] Listed 133 api resources in 0.038 seconds 2025-01-15 22:13:31,406 DEBUG [gather.hub] Listed 105 api resources in 0.038 seconds 2025-01-15 22:13:31,410 DEBUG [gather.dr1] Listed 133 api resources in 0.042 seconds 2025-01-15 22:13:31,416 DEBUG [gather.dr2] Listed 0 "podtemplates" in 0.010 seconds 2025-01-15 22:13:31,416 DEBUG [gather.dr2] Gathered 0 "podtemplates" in 0.010 seconds Signed-off-by: Nir Soffer --- test/drenv/__main__.py | 1 + test/drenv/kubectl.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/test/drenv/__main__.py b/test/drenv/__main__.py index 039ae8012..fe36a5d3f 100644 --- a/test/drenv/__main__.py +++ b/test/drenv/__main__.py @@ -286,6 +286,7 @@ def do_gather(args): directory=args.directory, namespaces=args.namespaces, name=env["name"], + verbose=args.verbose, ) logging.info( "[%s] Environment gathered in %.2f seconds", diff --git a/test/drenv/kubectl.py b/test/drenv/kubectl.py index ad934030b..d05fe46c1 100644 --- a/test/drenv/kubectl.py +++ b/test/drenv/kubectl.py @@ -191,7 +191,7 @@ def watch( return commands.watch(*cmd, timeout=timeout) -def gather(contexts, namespaces=None, directory=None, name="gather"): +def gather(contexts, namespaces=None, directory=None, name="gather", verbose=False): """ Run kubectl gather plugin, logging gather logs. """ @@ -207,6 +207,8 @@ def gather(contexts, namespaces=None, directory=None, name="gather"): cmd.extend(("--namespaces", ",".join(namespaces))) if directory: cmd.extend(("--directory", directory)) + if verbose: + cmd.append("--verbose") # Redirecting stderr to stdout to get the logs. kubectl gather does not # output anytihng to stdout.