github.com/abayer/test-infra@v0.0.5/prow/cmd/gcsupload/main.go (about)

     1  /*
     2  Copyright 2018 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  // gcsupload uploads the files and folders specified
    18  // to GCS using the Prow-defined job configuration
    19  package main
    20  
    21  import (
    22  	"github.com/sirupsen/logrus"
    23  	"k8s.io/test-infra/prow/pod-utils/downwardapi"
    24  	"k8s.io/test-infra/prow/pod-utils/options"
    25  
    26  	"k8s.io/test-infra/prow/gcsupload"
    27  	"k8s.io/test-infra/prow/logrusutil"
    28  	"k8s.io/test-infra/prow/pod-utils/gcs"
    29  )
    30  
    31  func main() {
    32  	o := gcsupload.NewOptions()
    33  	if err := options.Load(o); err != nil {
    34  		logrus.Fatalf("Could not resolve options: %v", err)
    35  	}
    36  
    37  	if err := o.Validate(); err != nil {
    38  		logrus.Fatalf("Invalid options: %v", err)
    39  	}
    40  
    41  	logrus.SetFormatter(
    42  		logrusutil.NewDefaultFieldsFormatter(nil, logrus.Fields{"component": "gcsupload"}),
    43  	)
    44  
    45  	spec, err := downwardapi.ResolveSpecFromEnv()
    46  	if err != nil {
    47  		logrus.WithError(err).Fatal("Could not resolve job spec")
    48  	}
    49  
    50  	if err := o.Run(spec, map[string]gcs.UploadFunc{}); err != nil {
    51  		logrus.WithError(err).Fatal("Failed to upload to GCS")
    52  	}
    53  }