Dump cluster logs to artifacts directory

This commit is contained in:
Peter Rifel 2020-12-27 23:01:06 -06:00
parent 12d399e650
commit 95b7210e27
No known key found for this signature in database
GPG Key ID: BC6469E5B16DB2B6
4 changed files with 35 additions and 2 deletions

View File

@ -22,6 +22,7 @@ import (
"fmt"
"os"
"path"
"path/filepath"
"k8s.io/klog/v2"
)
@ -137,3 +138,22 @@ func stateStore(cloudProvider string) string {
}
return ss
}
// the default is $ARTIFACTS if set, otherwise ./_artifacts
// constructed as an absolute path to help the ginkgo tester because
// for some reason it needs an absolute path to the kubeconfig
func defaultArtifactsDir() (string, error) {
if path, set := os.LookupEnv("ARTIFACTS"); set {
absPath, err := filepath.Abs(path)
if err != nil {
return "", fmt.Errorf("failed to convert filepath from $ARTIFACTS (%s) to absolute path: %s", path, err)
}
return absPath, nil
}
absPath, err := filepath.Abs("_artifacts")
if err != nil {
return "", fmt.Errorf("when constructing default artifacts dir, failed to get absolute path: %s", err)
}
return absPath, nil
}

View File

@ -51,6 +51,8 @@ type deployer struct {
SSHPublicKeyPath string `flag:"ssh-public-key" desc:"The path to the public key passed to the cloud provider"`
SSHUser []string `flag:"ssh-user" desc:"The SSH users to use for SSH access to instances"`
ArtifactsDir string `flag:"-"`
BuildOptions *builder.BuildOptions
}
@ -72,6 +74,12 @@ func New(opts types.Options) (types.Deployer, *pflag.FlagSet) {
BuildOptions: &builder.BuildOptions{},
}
dir, err := defaultArtifactsDir()
if err != nil {
klog.Fatalf("unable to determine artifacts directory: %v", err)
}
d.ArtifactsDir = dir
// register flags
fs := bindFlags(d)

View File

@ -27,6 +27,10 @@ func (d *deployer) Down() error {
if err := d.init(); err != nil {
return err
}
if err := d.DumpClusterLogs(); err != nil {
klog.Warningf("Dumping cluster logs at the start of Down() failed: %s", err)
}
args := []string{
d.KopsBinaryPath, "delete", "cluster",
"--name", d.ClusterName,

View File

@ -28,11 +28,12 @@ func (d *deployer) DumpClusterLogs() error {
args := []string{
d.KopsBinaryPath, "toolbox", "dump",
"--name", d.ClusterName,
"--dir",
"--yes",
"--dir", d.ArtifactsDir,
"--private-key", d.SSHPrivateKeyPath,
}
klog.Info(strings.Join(args, " "))
cmd := exec.Command(args[0], args[1:]...)
cmd.SetEnv(d.env()...)
if err := runWithOutput(cmd); err != nil {
return err
}