Skip to content

[deckhouse-cli] Updating the debug archive and adding an archive for virtualization - #472

Merged
ldmonster merged 16 commits into
mainfrom
chore/update-collection-logs-for-archive
Sep 24, 2026
Merged

ldmonster merged 16 commits into
mainfrom
chore/update-collection-logs-for-archive

Conversation

@VaLosev

@VaLosev VaLosev commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Changes to the archive generated by the d8 system collect-debug-info command:

  • Data collection files have been renamed to group information from various components.
  • A 3,000-line limit has been added when collecting logs from virtualization module controllers.
  • Collection of CRD resources from the cluster has been added.
  • Collection of machine resources for MCM and CAPI has been improved.
  • The exec→tar loop was moved from the Tarball() function to the reusable runCommands function so it can be used when creating a new archive for virtualization.
  • Pod container identification has been moved to the beginning of the logs.
  • Commands for building the archive and using the --list-exclude and --exclude flags have been moved to separate files to improve code readability; tests have also been added for them.
  • The README.md file in internal/system has been updated.

The ExpandPerModule bool field has been removed from the Command structure; the decision to execute a command for all modules specified in RequiredModule is now based on the presence of the {module-name} placeholder in the File or Args fields. This ensures a single source of truth for this mechanism—the template itself.
A test has also been added to verify that {module-name} is not used without specifying RequiredModule.


Additionally, a separate command has been added to collect logs from all pods in the d8-virtualization namespace: d8 system collect-debug-info virtualization. This was done because the 3,000-line limit is often insufficient for diagnosing virtualization issues, and the logs from virt-handler pods (deployed via a DaemonSet on every node) are also crucial—yet there can be many such pods (depending on the number of nodes).

Including all these logs in the main archive would significantly increase its size, whereas a debug archive needs to remain a tool for rapid diagnostics, allowing clients to quickly gather and submit it. Thus, if virtualization issues arise and the standard archive's logs prove insufficient, a specialized virtualization-focused archive can be requested.

The --command-timeout and --request-interval flags were carried over to this new archive, and a new --skip-ds-logs flag was added; this allows for disabling log collection from DaemonSet (DS) pods in clusters with a large number of nodes.


Changes to internal/utilk8s/operatepod.go:

To collect virtualization logs without using the Deckhouse pod, the ExecCommandInPod function and a private syncBuffer type were added to the utilk8s package. This addition follows a comment regarding an issue with buffer reuse, which could potentially corrupt the logs.
#472 (comment)

Changes to internal/utilk8s/clientset.go:

The SetupK8sClientSet mechanism and the identical error message "Failed to setup Kubernetes client: %w" were previously duplicated across the standard and virtualization archive collection processes. This logic has now been moved to the utilk8s package, where similar mechanisms are utilized.

d8 system collect-debug-info virtualization --help
Collect a separate debug archive with detailed data from the d8-virtualization namespace.

Usage:
  d8 system collect-debug-info virtualization [flags] > deckhouse-debug-virtualization-$(date +"%Y_%m_%d").tar.gz

Examples:
  # Collect the virtualization debug archive:
  d8 system collect-debug-info virtualization > deckhouse-debug-virtualization-$(date +"%Y_%m_%d").tar.gz

  # The --skip-ds-logs flag can be used to skip logs from DaemonSet-managed pods
  # (virt-handler, virtualization-dra, vm-route-forge, ...) to reduce archive size:
  d8 system collect-debug-info virtualization --skip-ds-logs > deckhouse-debug-virtualization-$(date +"%Y_%m_%d").tar.gz

Flags:
      --command-timeout duration    Timeout for each individual debug command execution (default 2m0s)
  -h, --help                        help for virtualization
      --request-interval duration   Minimum interval between debug command executions to avoid overloading the cluster (e.g. 200ms, 500ms, 1s). Zero disables rate limiting (default 0s)
      --skip-ds-logs                Skip collecting logs from pods managed by a DaemonSet (virt-handler, virtualization-dra, vm-route-forge, ...) to reduce archive size on clusters with many nodes

Global Flags:
      --context string      The name of the kubeconfig context to use
  -k, --kubeconfig string   Path to kubeconfig file. (default is $KUBECONFIG when it is set, otherwise the default kubeconfig path for the current OS user) (default "/root/.kube/config")

Signed-off-by: Valery Losev <valery.losev@flant.com>
Signed-off-by: Valery Losev <valery.losev@flant.com>
@VaLosev VaLosev self-assigned this Sep 1, 2026
@VaLosev
VaLosev requested a review from ldmonster as a code owner September 1, 2026 14:21
Signed-off-by: Valery Losev <valery.losev@flant.com>
Signed-off-by: Valery Losev <valery.losev@flant.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

There are user-facing behavioral issues (notably --exclude no longer matching module-expanded filenames as documented) and reliability issues from ignoring tar/gzip Close() errors that can produce silently corrupted archives.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR enhances d8 system collect-debug-info by reorganizing debug archive contents (renamed output files, additional collected resources) and extracting a reusable command-execution pipeline, while also introducing a dedicated virtualization subcommand to collect a separate, more detailed archive for the d8-virtualization namespace.

Changes:

  • Refactored the tarball creation flow by extracting the exec→tar loop into a reusable runCommands helper.
  • Renamed/added collected artifacts in the main debug archive (including CRD collection and additional virtualization module controller logs with tail limits).
  • Added d8 system collect-debug-info virtualization to collect per-pod logs from d8-virtualization with an option to skip DaemonSet-owned pod logs.
File summaries
File Description
internal/system/cmd/collect-debug-info/virtualizationtar/virtualizationTar.go Adds the new virtualization cobra subcommand and CLI flags.
internal/system/cmd/collect-debug-info/debugtar/virtualizationTarball.go Implements the virtualization-focused tarball (pod discovery + per-pod logs).
internal/system/cmd/collect-debug-info/debugtar/debugTar.go Renames/extends the main debug command list and extracts runCommands.
internal/system/cmd/collect-debug-info/collect-debug-info.go Wires the new virtualization subcommand into collect-debug-info.
Review details

Suppressed comments (1)

internal/system/cmd/collect-debug-info/debugtar/debugTar.go:177

  • Same issue as the CCM logs filename: {module-name} prefix breaks prefix-based --exclude values like csi-controller-logs and makes --list-exclude output less useful. Keeping the placeholder at the end preserves existing exclusion behavior.
		File:            "{module-name}-csi-controller-logs.txt",
  • Files reviewed: 4/4 changed files
  • Comments generated: 5
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread internal/system/cmd/collect-debug-info/debugtar/debugTar.go Outdated
Comment thread internal/system/cmd/collect-debug-info/debugtar/debugTar.go Outdated
Comment thread internal/system/cmd/collect-debug-info/debugtar/virtualizationTarball.go Outdated
Comment thread internal/system/cmd/collect-debug-info/collect-debug-info.go
Comment thread internal/system/cmd/collect-debug-info/debugtar/virtualizationTarball.go Outdated
ldmonster
ldmonster previously approved these changes Sep 3, 2026

@Glitchy-Sheep Glitchy-Sheep left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two things to fix before merging, both in the base archive:

  1. --exclude and --list-exclude break for per-module files after the rename. See the inline comment.
  2. MCM machines are dropped from the archive instead of being collected alongside CAPI machines. See the inline comment.

One thing to decide: renaming almost every file in the archive is a breaking change. It affects existing --exclude values, support scripts and the docs on the site. The card and the thread did not ask for it. If we keep it, please state it in the PR description and update the --exclude example in the help once the exclude logic is fixed.

Optional: --all-containers=true in the log commands would also capture sidecars, for example the second container of dvcr. kubectl defaults to the first container, so this is not blocking.

Comment thread internal/system/cmd/collect-debug-info/debugtar/debugTar.go Outdated
Comment thread internal/system/cmd/collect-debug-info/debugtar/debugcommands.go Outdated
Signed-off-by: Valery Losev <valery.losev@flant.com>
@VaLosev
VaLosev marked this pull request as draft September 7, 2026 17:04
Signed-off-by: Valery Losev <valery.losev@flant.com>
Signed-off-by: Valery Losev <valery.losev@flant.com>
Signed-off-by: Valery Losev <valery.losev@flant.com>
@VaLosev
VaLosev marked this pull request as ready for review September 8, 2026 18:22
Signed-off-by: Valery Losev <valery.losev@flant.com>
Comment thread internal/system/cmd/collect-debug-info/debugtar/virtualizationTarball.go Outdated
Comment thread internal/system/cmd/collect-debug-info/debugtar/virtualizationTarball.go Outdated
Comment thread internal/system/cmd/collect-debug-info/debugtar/debugcommands.go
Comment thread internal/system/cmd/collect-debug-info/debugtar/debugTar.go Outdated
Comment thread internal/system/cmd/collect-debug-info/debugtar/virtualizationTarball.go Outdated
Comment thread internal/system/cmd/collect-debug-info/collect-debug-info.go
Comment thread internal/system/cmd/collect-debug-info/debugtar/debugTar.go Outdated
Comment thread internal/system/cmd/collect-debug-info/debugtar/debugTar.go Outdated
Comment thread internal/system/cmd/collect-debug-info/debugtar/debugcommands.go
Comment thread internal/system/cmd/collect-debug-info/debugtar/debugTar.go Outdated
Comment thread internal/system/cmd/collect-debug-info/debugtar/debugcommands.go
Comment thread internal/system/cmd/collect-debug-info/debugtar/virtualizationTarball.go Outdated
Comment thread internal/system/cmd/collect-debug-info/debugtar/debugTar.go Outdated
Comment thread internal/system/cmd/collect-debug-info/debugtar/debugTar.go Outdated
Signed-off-by: Valery Losev <valery.losev@flant.com>
ldmonster
ldmonster previously approved these changes Sep 16, 2026
Signed-off-by: Valery Losev <valery.losev@flant.com>
VaLosev and others added 5 commits September 22, 2026 16:53
Signed-off-by: Valery Losev <valery.losev@flant.com>
Signed-off-by: Valery Losev <valery.losev@flant.com>
Signed-off-by: Valery Losev <valery.losev@flant.com>
Signed-off-by: Valery Losev <valery.losev@flant.com>
@ldmonster
ldmonster merged commit 5525a74 into main Sep 24, 2026
8 of 9 checks passed
@ldmonster
ldmonster deleted the chore/update-collection-logs-for-archive branch September 24, 2026 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants