-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We're adding a "k8s inspect" command that will invoke the "inspect.sh" script, aiming to improve the user experience. Note that we'll avoid parsing the arguments twice since that's unnecessary and would complicate the process of adding new parameters.
- Loading branch information
1 parent
afa585a
commit 7e7162b
Showing
7 changed files
with
82 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package k8s | ||
|
||
import ( | ||
"syscall" | ||
|
||
cmdutil "github.com/canonical/k8s/cmd/util" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func newInspectCmd(env cmdutil.ExecutionEnvironment) *cobra.Command { | ||
// We're copying the help string from the "inspect.sh" script with | ||
// only minor adjustments. At the same time, we'll avoid parsing the | ||
// same arguments twice. | ||
return &cobra.Command{ | ||
Use: "inspect <output-file>", | ||
Short: "generate inspection report", | ||
Long: ` | ||
This command collects diagnostics and other relevant information from a Kubernetes | ||
node (either control-plane or worker node) and compiles them into a tarball report. | ||
The collected data includes service arguments, Kubernetes cluster info, SBOM, system | ||
diagnostics, network diagnostics, and more. The command needs to be run with | ||
elevated permissions (sudo). | ||
Arguments: | ||
output_file (Optional) The full path and filename for the generated tarball. | ||
If not provided, a default filename based on the current date | ||
and time will be used. | ||
--all-namespaces (Optional) Acquire detailed debugging information, including logs | ||
from all Kubernetes namespaces. | ||
--num-snap-log-entries (Optional) The maximum number of log entries to collect | ||
from snap services. Default: 100000. | ||
--timeout (Optional) The maximum time in seconds to wait for a command. | ||
Default: 180s. | ||
`, | ||
DisableFlagParsing: true, | ||
PreRun: chainPreRunHooks(hookRequireRoot(env)), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
inspectScriptPath := env.Snap.K8sInspectScriptPath() | ||
|
||
command := append([]string{inspectScriptPath}, args...) | ||
environ := cmdutil.EnvironWithDefaults( | ||
env.Environ, | ||
) | ||
if err := syscall.Exec(inspectScriptPath, command, environ); err != nil { | ||
cmd.PrintErrf("Failed to run %s.\n\nError: %v\n", command, err) | ||
env.Exit(1) | ||
return | ||
} | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters