Skip to content

Commit

Permalink
Merge pull request kubernetes-sigs#2161 from BenTheElder/export-version
Browse files Browse the repository at this point in the history
fix kind export logs
  • Loading branch information
k8s-ci-robot authored Mar 26, 2021
2 parents 8885b2c + 7f4dc38 commit d0df6d2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 23 deletions.
16 changes: 0 additions & 16 deletions pkg/cluster/internal/providers/common/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"path/filepath"

"sigs.k8s.io/kind/pkg/cluster/nodes"
"sigs.k8s.io/kind/pkg/cmd/kind/version"
"sigs.k8s.io/kind/pkg/errors"
"sigs.k8s.io/kind/pkg/exec"
)
Expand All @@ -23,24 +22,9 @@ func CollectLogs(n nodes.Node, dir string) error {
return cmd.SetStdout(f).SetStderr(f).Run()
}
}
writeToPathFn := func(s string, path string) func() error {
return func() error {
f, err := FileOnHost(path)
if err != nil {
return err
}
defer f.Close()
_, err = f.WriteString(s)
return err
}
}

return errors.AggregateConcurrent([]func() error{
// record info about the node container
writeToPathFn(
version.DisplayVersion(),
filepath.Join(dir, "kind-version.txt"),
),
execToPathFn(
n.Command("cat", "/kind/version"),
"kubernetes-version.txt",
Expand Down
18 changes: 18 additions & 0 deletions pkg/cluster/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@ limitations under the License.
package cluster

import (
"io/ioutil"
"os"
"path/filepath"
"sort"

"sigs.k8s.io/kind/pkg/cmd/kind/version"

"sigs.k8s.io/kind/pkg/cluster/constants"
"sigs.k8s.io/kind/pkg/cluster/nodes"
"sigs.k8s.io/kind/pkg/cluster/nodeutils"
Expand Down Expand Up @@ -226,5 +231,18 @@ func (p *Provider) CollectLogs(name, dir string) error {
if err != nil {
return err
}
// ensure directory
if err := os.MkdirAll(dir, os.ModePerm); err != nil {
return errors.Wrap(err, "failed to create logs directory")
}
// write kind version
if err := ioutil.WriteFile(
filepath.Join(dir, "kind-version.txt"),
[]byte(version.DisplayVersion()),
0666, // match os.Create
); err != nil {
return errors.Wrap(err, "failed to write kind-version.txt")
}
// collect and write cluster logs
return p.provider.CollectLogs(dir, n)
}
13 changes: 6 additions & 7 deletions pkg/cmd/kind/export/logs/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,11 @@ func runE(logger log.Logger, streams cmd.IOStreams, flags *flagpole, args []stri
dir = args[0]
}

// collect the logs
if err := provider.CollectLogs(flags.Name, dir); err != nil {
return err
}

logger.V(0).Infof("Exported logs for cluster %q to:", flags.Name)
// NOTE: the path is the output of this command to be captured by calling tools
// whereas "Exporting logs..." is info / debug (stderr)
logger.V(0).Infof("Exporting logs for cluster %q to:", flags.Name)
fmt.Fprintln(streams.Out, dir)
return nil

// collect the logs
return provider.CollectLogs(flags.Name, dir)
}

0 comments on commit d0df6d2

Please sign in to comment.