@@ -34,24 +34,50 @@ Collect debug info from Deckhouse Kubernetes Platform.
3434© Flant JSC 2025` )
3535
3636func NewCommand () * cobra.Command {
37+ var (
38+ excludeList []string
39+ listExclude bool
40+ )
41+
3742 collectDebugInfoCmd := & cobra.Command {
3843 Use : "collect-debug-info" ,
3944 Short : "Collect debug info." ,
4045 Long : collectDebugInfoCmdLong ,
4146 SilenceErrors : true ,
4247 SilenceUsage : true ,
4348 PreRunE : func (cmd * cobra.Command , args []string ) error {
49+ if listExclude {
50+ return nil
51+ }
52+
4453 if term .IsTerminal (int (os .Stdout .Fd ())) {
45- return fmt .Errorf ("Please provide output tar.gz to dump debug logs, ex. \" > dump-logs.tar.gz\" " )
54+ return fmt .Errorf ("output must be redirected to a file, e.g., \" > dump-logs.tar.gz\" " )
4655 }
56+
4757 return nil
4858 },
49- RunE : collectDebugInfo ,
59+ RunE : func (cmd * cobra.Command , args []string ) error {
60+ return collectDebugInfo (cmd , listExclude , excludeList )
61+ },
5062 }
63+ collectDebugInfoCmd .Flags ().StringSliceVar (& excludeList , "exclude" , []string {}, "Exclude specific files from the debug archive. Use comma-separated values" )
64+ collectDebugInfoCmd .Flags ().BoolVarP (& listExclude , "list-exclude" , "l" , false , "List all files that can be excluded from the debug archive" )
5165 return collectDebugInfoCmd
5266}
5367
54- func collectDebugInfo (cmd * cobra.Command , _ []string ) error {
68+ func printExcludableFiles () {
69+ fmt .Println ("List of possible data to exclude:" )
70+ for _ , fileName := range debugtar .GetExcludableFiles () {
71+ fmt .Println (fileName )
72+ }
73+ }
74+
75+ func collectDebugInfo (cmd * cobra.Command , listExclude bool , excludeList []string ) error {
76+ if listExclude {
77+ printExcludableFiles ()
78+ return nil
79+ }
80+
5581 kubeconfigPath , err := cmd .Flags ().GetString ("kubeconfig" )
5682 if err != nil {
5783 return fmt .Errorf ("Failed to setup Kubernetes client: %w" , err )
@@ -67,9 +93,8 @@ func collectDebugInfo(cmd *cobra.Command, _ []string) error {
6793 return fmt .Errorf ("Failed to setup Kubernetes client: %w" , err )
6894 }
6995
70- err = debugtar .Tarball (config , kubeCl )
71- if err != nil {
96+ if err = debugtar .Tarball (config , kubeCl , excludeList ); err != nil {
7297 return fmt .Errorf ("Error collecting debug info: %w" , err )
7398 }
74- return err
99+ return nil
75100}
0 commit comments