mirror of https://github.com/kubernetes/kops.git
Dump cluster logs to artifacts directory
This commit is contained in:
parent
12d399e650
commit
95b7210e27
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue