Skip to content

Commit

Permalink
Merge pull request #59 from amwat/logdump
Browse files Browse the repository at this point in the history
[GKE] Enable Log dumping
  • Loading branch information
k8s-ci-robot authored Sep 23, 2020
2 parents d47fe00 + 1bc89be commit e0ffa6a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 9 deletions.
10 changes: 9 additions & 1 deletion kubetest2-gke/deployer/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
)

func (d *deployer) Build() error {
if err := d.BuildOptions.Validate(); err != nil {
if err := d.verifyBuildFlags(); err != nil {
return err
}
version, err := d.BuildOptions.Build()
Expand All @@ -41,3 +41,11 @@ func (d *deployer) Build() error {
d.Version = version
return nil
}

func (d *deployer) verifyBuildFlags() error {
if d.RepoRoot == "" {
return fmt.Errorf("required repo-root when building from source")
}
d.BuildOptions.RepoRoot = d.RepoRoot
return d.BuildOptions.Validate()
}
3 changes: 2 additions & 1 deletion kubetest2-gke/deployer/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ type deployer struct {

BuildOptions *options.BuildOptions

Version string `desc:"Use a specific GKE version e.g. 1.16.13.gke-400 or 'latest'. If --build is specified it will default to building kubernetes from source."`
RepoRoot string `desc:"Path to root of the kubernetes repo. Used with --build and for dumping cluster logs."`
Version string `desc:"Use a specific GKE version e.g. 1.16.13.gke-400 or 'latest'. If --build is specified it will default to building kubernetes from source."`

// doInit helps to make sure the initialization is performed only once
doInit sync.Once
Expand Down
6 changes: 4 additions & 2 deletions kubetest2-gke/deployer/dumplogs.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,14 @@ export KUBE_NODE_OS_DISTRIBUTION='%[3]s'
dumpCmd += " " + d.gcsLogsDir
}

if err := runWithOutput(exec.Command("bash", "-c", fmt.Sprintf(gkeLogDumpTemplate,
cmd := exec.Command("bash", "-c", fmt.Sprintf(gkeLogDumpTemplate,
project,
d.zone,
os.Getenv("NODE_OS_DISTRIBUTION"),
strings.Join(filters, " OR "),
dumpCmd))); err != nil {
dumpCmd))
cmd.SetDir(d.RepoRoot)
if err := runWithOutput(cmd); err != nil {
return err
}
}
Expand Down
6 changes: 1 addition & 5 deletions kubetest2-gke/deployer/options/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,12 @@ import (
type BuildOptions struct {
Strategy string `flag:"~strategy" desc:"Determines the build strategy to use either make or bazel."`
StageLocation string `flag:"~stage" desc:"Upload binaries to gs://bucket/ci/job-suffix if set"`
RepoRoot string `flag:"~repo-root" desc:"Path to root of the kubernetes repo. Used with --build."`

RepoRoot string `flag:"-"`
build.Builder
build.Stager
}

func (bo *BuildOptions) Validate() error {
if bo.RepoRoot == "" {
return fmt.Errorf("required repo-root when building from source")
}
return bo.implementationFromStrategy()
}

Expand Down
10 changes: 10 additions & 0 deletions kubetest2-gke/deployer/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ func (d *deployer) Up() error {
return err
}

defer func() {
if d.RepoRoot == "" {
klog.Warningf("repo-root not supplied, skip dumping cluster logs")
return
}
if err := d.DumpClusterLogs(); err != nil {
klog.Warningf("Dumping cluster logs at the end of Up() failed: %s", err)
}
}()

// Only run prepare once for the first GCP project.
if err := d.prepareGcpIfNeeded(d.projects[0]); err != nil {
return err
Expand Down

0 comments on commit e0ffa6a

Please sign in to comment.