Skip to content

Commit

Permalink
Pass job spec explicitly to GCS code
Browse files Browse the repository at this point in the history
We need to pass job specification explicitly to the GCS uploading code
that we move to passing the minimum set of information as well as so
that we can support modes of calling the GCS library where `$JOB_SPEC`
is not set.

Signed-off-by: Steve Kuznetsov <[email protected]>
  • Loading branch information
stevekuznetsov committed May 4, 2018
1 parent 0043f95 commit b4a2f84
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 12 deletions.
1 change: 1 addition & 0 deletions prow/cmd/gcsupload/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ go_library(
deps = [
"//prow/gcsupload:go_default_library",
"//prow/logrusutil:go_default_library",
"//prow/pod-utils/downwardapi:go_default_library",
"//prow/pod-utils/gcs:go_default_library",
"//prow/pod-utils/options:go_default_library",
"//vendor/github.com/sirupsen/logrus:go_default_library",
Expand Down
8 changes: 7 additions & 1 deletion prow/cmd/gcsupload/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package main

import (
"github.com/sirupsen/logrus"
"k8s.io/test-infra/prow/pod-utils/downwardapi"
"k8s.io/test-infra/prow/pod-utils/options"

"k8s.io/test-infra/prow/gcsupload"
Expand All @@ -41,7 +42,12 @@ func main() {
logrusutil.NewDefaultFieldsFormatter(nil, logrus.Fields{"component": "gcsupload"}),
)

if err := o.Run(map[string]gcs.UploadFunc{}); err != nil {
spec, err := downwardapi.ResolveSpecFromEnv()
if err != nil {
logrus.WithError(err).Fatal("Could not resolve job spec")
}

if err := o.Run(spec, map[string]gcs.UploadFunc{}); err != nil {
logrus.WithError(err).Fatal("Failed to upload to GCS")
}
}
7 changes: 1 addition & 6 deletions prow/gcsupload/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,7 @@ import (
// a parameter and will have the prefix prepended
// to their destination in GCS, so the caller can
// operate relative to the base of the GCS dir.
func (o Options) Run(extra map[string]gcs.UploadFunc) error {
spec, err := downwardapi.ResolveSpecFromEnv() // TODO: pass in all the config instead of needing this?
if err != nil {
return fmt.Errorf("could not resolve job spec: %v", err)
}

func (o Options) Run(spec *downwardapi.JobSpec, extra map[string]gcs.UploadFunc) error {
uploadTargets := o.assembleTargets(spec, extra)

if !o.DryRun {
Expand Down
1 change: 1 addition & 0 deletions prow/initupload/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ go_library(
deps = [
"//prow/gcsupload:go_default_library",
"//prow/pod-utils/clone:go_default_library",
"//prow/pod-utils/downwardapi:go_default_library",
"//prow/pod-utils/gcs:go_default_library",
],
)
Expand Down
8 changes: 7 additions & 1 deletion prow/initupload/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,16 @@ import (
"time"

"k8s.io/test-infra/prow/pod-utils/clone"
"k8s.io/test-infra/prow/pod-utils/downwardapi"
"k8s.io/test-infra/prow/pod-utils/gcs"
)

func (o Options) Run() error {
spec, err := downwardapi.ResolveSpecFromEnv()
if err != nil {
return fmt.Errorf("could not resolve job spec: %v", err)
}

var cloneRecords []clone.Record
data, err := ioutil.ReadFile(o.Log)
if err != nil {
Expand Down Expand Up @@ -81,7 +87,7 @@ func (o Options) Run() error {
}
}

if err := o.Options.Run(uploadTargets); err != nil {
if err := o.Options.Run(spec, uploadTargets); err != nil {
return fmt.Errorf("failed to upload to GCS: %v", err)
}

Expand Down
1 change: 1 addition & 0 deletions prow/sidecar/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ go_library(
visibility = ["//visibility:public"],
deps = [
"//prow/gcsupload:go_default_library",
"//prow/pod-utils/downwardapi:go_default_library",
"//prow/pod-utils/gcs:go_default_library",
"//prow/pod-utils/wrapper:go_default_library",
"//vendor/github.com/fsnotify/fsnotify:go_default_library",
Expand Down
14 changes: 10 additions & 4 deletions prow/sidecar/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (

"github.com/fsnotify/fsnotify"
"github.com/sirupsen/logrus"
"k8s.io/test-infra/prow/pod-utils/downwardapi"

"k8s.io/test-infra/prow/pod-utils/gcs"
)
Expand All @@ -40,6 +41,11 @@ import (
// and then post the status of that process and any artifacts
// to cloud storage.
func (o Options) Run() error {
spec, err := downwardapi.ResolveSpecFromEnv()
if err != nil {
return fmt.Errorf("could not resolve job spec: %v", err)
}

// If we are being asked to terminate by the kubelet but we have
// NOT seen the test process exit cleanly, we need a to start
// uploading artifacts to GCS immediately. If we notice the process
Expand All @@ -52,7 +58,7 @@ func (o Options) Run() error {
select {
case s := <-interrupt:
logrus.Errorf("Received an interrupt: %s", s)
o.doUpload(false)
o.doUpload(spec, false)
}
}()

Expand Down Expand Up @@ -113,10 +119,10 @@ func (o Options) Run() error {
passed = returnCode == 0 && err == nil
}

return o.doUpload(passed)
return o.doUpload(spec, passed)
}

func (o Options) doUpload(passed bool) error {
func (o Options) doUpload(spec *downwardapi.JobSpec, passed bool) error {
uploadTargets := map[string]gcs.UploadFunc{
"build-log.txt": gcs.FileUpload(o.WrapperOptions.ProcessLog),
}
Expand All @@ -135,7 +141,7 @@ func (o Options) doUpload(passed bool) error {
uploadTargets["finished.json"] = gcs.DataUpload(bytes.NewBuffer(finishedData))
}

if err := o.GcsOptions.Run(uploadTargets); err != nil {
if err := o.GcsOptions.Run(spec, uploadTargets); err != nil {
return fmt.Errorf("failed to upload to GCS: %v", err)
}

Expand Down

0 comments on commit b4a2f84

Please sign in to comment.