Skip to content

Commit

Permalink
drenv: Support verbose gather
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
nirs committed Jan 15, 2025
1 parent f15935a commit 1e024de
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions test/drenv/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion test/drenv/kubectl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand All @@ -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.
Expand Down

0 comments on commit 1e024de

Please sign in to comment.