github.com/abayer/test-infra@v0.0.5/prow/pod-utils/wrapper/options.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 package wrapper 18 19 import ( 20 "errors" 21 "flag" 22 ) 23 24 // BindOptions adds flags to the FlagSet that populate 25 // the wrapper options struct provided. 26 func BindOptions(options *Options, fs *flag.FlagSet) { 27 fs.StringVar(&options.ProcessLog, "process-log", "", "path to the log where stdout and stderr are streamed for the process we execute") 28 fs.StringVar(&options.MarkerFile, "marker-file", "", "file we write the return code of the process we execute once it has finished running") 29 } 30 31 // Options exposes the configuration options 32 // used when wrapping test execution 33 type Options struct { 34 // ProcessLog will contain std{out,err} from the 35 // wrapped test process 36 ProcessLog string `json:"process_log"` 37 38 // MarkerFile will be written with the exit code 39 // of the test process or an internal error code 40 // if the entrypoint fails. 41 MarkerFile string `json:"marker_file"` 42 } 43 44 // Validate ensures that the set of options are 45 // self-consistent and valid 46 func (o *Options) Validate() error { 47 if o.ProcessLog == "" { 48 return errors.New("no log file specified with --process-log") 49 } 50 51 if o.MarkerFile == "" { 52 return errors.New("no marker file specified with --marker-file") 53 } 54 55 return nil 56 }