-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support-bundle command (#1351)
* feat: add support-bundle command add support-bundle command. this command generates a support bundle using the in-cluster support bundle definitions and the local host support bundle definitions. * feat: disable interactive support-bundle we just want to generate a support bundle and save it to disk so we don't need to have the interactive mode enabled. * chore: support-bundle isn't always a json we can't rely on parsing the output as json, it might contain error messages mixed up.
- Loading branch information
1 parent
cfd6d15
commit 2f44e63
Showing
5 changed files
with
111 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"io" | ||
"os" | ||
|
||
"github.com/urfave/cli/v2" | ||
|
||
"github.com/replicatedhq/embedded-cluster/pkg/defaults" | ||
"github.com/replicatedhq/embedded-cluster/pkg/helpers" | ||
"github.com/replicatedhq/embedded-cluster/pkg/spinner" | ||
) | ||
|
||
func supportBundleCommand() *cli.Command { | ||
return &cli.Command{ | ||
Name: "support-bundle", | ||
Usage: fmt.Sprintf("Generate a %s support bundle", defaults.BinaryName()), | ||
Before: func(c *cli.Context) error { | ||
if os.Getuid() != 0 { | ||
return fmt.Errorf("support-bundle command must be run as root") | ||
} | ||
return nil | ||
}, | ||
Action: func(c *cli.Context) error { | ||
provider := discoverBestProvider(c.Context) | ||
os.Setenv("TMPDIR", provider.EmbeddedClusterTmpSubDir()) | ||
|
||
supportBundle := provider.PathToEmbeddedClusterBinary("kubectl-support_bundle") | ||
if _, err := os.Stat(supportBundle); err != nil { | ||
return fmt.Errorf("unable to find support bundle binary") | ||
} | ||
|
||
kubeConfig := provider.PathToKubeConfig() | ||
hostSupportBundle := provider.PathToEmbeddedClusterSupportFile("host-support-bundle.yaml") | ||
|
||
spin := spinner.Start() | ||
spin.Infof("Collecting support bundle (this may take a while)") | ||
|
||
stdout := bytes.NewBuffer(nil) | ||
stderr := bytes.NewBuffer(nil) | ||
if err := helpers.RunCommandWithOptions( | ||
helpers.RunCommandOptions{ | ||
Writer: stdout, | ||
ErrWriter: stderr, | ||
LogOnSuccess: true, | ||
}, | ||
supportBundle, | ||
"--interactive=false", | ||
fmt.Sprintf("--kubeconfig=%s", kubeConfig), | ||
"--load-cluster-specs", | ||
hostSupportBundle, | ||
); err != nil { | ||
spin.Infof("Failed to collect support bundle") | ||
spin.CloseWithError() | ||
io.Copy(os.Stdout, stdout) | ||
io.Copy(os.Stderr, stderr) | ||
return ErrNothingElseToAdd | ||
} | ||
|
||
spin.Infof("Support bundle collected!") | ||
spin.Close() | ||
return nil | ||
}, | ||
} | ||
} |
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