Skip to content
This repository has been archived by the owner on Sep 5, 2019. It is now read-only.

Commit

Permalink
remove entrypoint/wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
aaron-prindle committed Jan 14, 2019
1 parent 1877a7e commit f5527aa
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 191 deletions.
2 changes: 1 addition & 1 deletion cmd/entrypoint/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,5 @@ func main() {
logger.Fatalf("Invalid options: %v", err)
}

os.Exit(o.Run())
os.Exit(o.Run(logger))
}
75 changes: 48 additions & 27 deletions pkg/entrypoint/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,53 @@ import (
"encoding/json"
"errors"
"flag"

"github.com/knative/build/pkg/entrypoint/wrapper"
"fmt"
)

// NewOptions returns an empty Options with no nil fields
func NewOptions() *Options {
return &Options{
Options: &wrapper.Options{},
}
}

// Options exposes the configuration necessary
// for defining the process being watched and
// where in the image repository an upload will land.
// Options exposes the configuration options
// used when wrapping test execution
type Options struct {
// Args is the process and args to run
Args []string `json:"args"`

*wrapper.Options
// ShouldWaitForPrevStep will be written with the exit code
// of the test process or an internal error code
// if the entrypoint fails.
ShouldWaitForPrevStep bool `json:"shouldWaitForPrevStep"`

// PreRunFile will be written with the exit code
// of the test process or an internal error code
// if the entrypoint fails.
PreRunFile string `json:"preRunFile"`

// ShouldWaitForPrevStep will be written with the exit code
// of the test process or an internal error code
// if the entrypoint fails.
ShouldRunPostRun bool `json:"shouldRunPostRun"`

// PostRunFile will be written with the exit code
// of the test process or an internal error code
// if the entrypoint fails or if it succeeds
PostRunFile string `json:"postRunFile"`
}

// NewOptions returns an empty Options with no nil fields
func NewOptions() *Options {
return &Options{}
}

// AddFlags adds flags to the FlagSet that populate
// the wrapper options struct provided.
func (o *Options) AddFlags(flags *flag.FlagSet) {
flags.BoolVar(&o.ShouldWaitForPrevStep, "should-wait-for-prev-step",
DefaultShouldWaitForPrevStep, "If we should wait for prev step.")
flags.BoolVar(&o.ShouldRunPostRun, "should-run-post-run",
DefaultShouldRunPostRun, "If the post run step should be run after execution finishes.")
flags.StringVar(&o.PreRunFile, "prerun-file",
DefaultPreRunFile, "The path of the file that acts as a lock for the entrypoint. The entrypoint binary will wait until that file is present to launch the specified command.")
flags.StringVar(&o.PostRunFile, "postrun-file",
DefaultPostRunFile, "The path of the file that will be written once the command finishes for the entrypoint. This can act as a lock for other entrypoint rewritten containers.")
return
}

// Validate ensures that the set of options are
Expand All @@ -48,7 +76,13 @@ func (o *Options) Validate() error {
return errors.New("no process to wrap specified")
}

return o.Options.Validate()
if o.PreRunFile != "" && !o.ShouldWaitForPrevStep {
return fmt.Errorf("PreRunFile specified but ShouldWaitForPrevStep is false")
}
if o.PostRunFile != "" && !o.ShouldRunPostRun {
return fmt.Errorf("PostRunFile specified but ShouldRunPostRun is false")
}
return nil
}

const (
Expand All @@ -69,19 +103,6 @@ func (o *Options) LoadConfig(config string) error {
return json.Unmarshal([]byte(config), o)
}

// AddFlags binds flags to options
func (o *Options) AddFlags(flags *flag.FlagSet) {
flags.BoolVar(&o.ShouldWaitForPrevStep, "should-wait-for-prev-step",
DefaultShouldWaitForPrevStep, "If we should wait for prev step.")
flags.BoolVar(&o.ShouldRunPostRun, "should-run-post-run",
DefaultShouldRunPostRun, "If the post run step should be run after execution finishes.")
flags.StringVar(&o.PreRunFile, "prerun-file",
DefaultPreRunFile, "The path of the file that acts as a lock for the entrypoint. The entrypoint binary will wait until that file is present to launch the specified command.")
flags.StringVar(&o.PostRunFile, "postrun-file",
DefaultPostRunFile, "The path of the file that will be written once the command finishes for the entrypoint. This can act as a lock for other entrypoint rewritten containers.")
o.Options.AddFlags(flags)
}

// Complete internalizes command line arguments
func (o *Options) Complete(args []string) {
o.Args = args
Expand Down
18 changes: 2 additions & 16 deletions pkg/entrypoint/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ package entrypoint

import (
"testing"

"github.com/knative/build/pkg/entrypoint/wrapper"
)

func TestOptions_Validate(t *testing.T) {
Expand All @@ -30,21 +28,9 @@ func TestOptions_Validate(t *testing.T) {
}{{
name: "all ok",
input: Options{
Args: []string{"/usr/bin/true"},
Options: &wrapper.Options{
ProcessLog: "output.txt",
MarkerFile: "marker.txt",
},
},
}, {
name: "missing args",
input: Options{
Options: &wrapper.Options{
ProcessLog: "output.txt",
MarkerFile: "marker.txt",
},
Args: []string{"/usr/bin/true"},
ShouldRunPostRun: true,
},
expectedErr: true,
}}

for _, testCase := range testCases {
Expand Down
3 changes: 1 addition & 2 deletions pkg/entrypoint/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"strconv"
"syscall"

"github.com/knative/pkg/logging"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -55,7 +54,7 @@ const (

// Run executes the test process then writes the exit code to the marker file.
// This function returns the status code that should be passed to os.Exit().
func (o Options) Run(*zap.SugaredLogger logger) int {
func (o Options) Run(logger *zap.SugaredLogger) int {
defer logger.Sync()

code, err := o.ExecuteProcess()
Expand Down
16 changes: 9 additions & 7 deletions pkg/entrypoint/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"path"
"testing"

"github.com/knative/build/pkg/entrypoint/wrapper"
"github.com/knative/pkg/logging"
)

func TestOptions_Run(t *testing.T) {
Expand Down Expand Up @@ -67,13 +67,15 @@ func TestOptions_Run(t *testing.T) {
}()

options := Options{
Args: testCase.args,
Options: &wrapper.Options{
ShouldWaitForPrevStep: false,
PreRunFile: path.Join(tmpDir, "0"),
PostRunFile: path.Join(tmpDir, "0"),
},
Args: testCase.args,
ShouldWaitForPrevStep: false,
PreRunFile: path.Join(tmpDir, "0"),
PostRunFile: path.Join(tmpDir, "0"),
}

logger, _ := logging.NewLogger("", "entrypoint")
defer logger.Sync()
options.Run(logger)
if options.ShouldWaitForPrevStep {
compareFileContents(testCase.name, options.PreRunFile,
testCase.expectedPreRunFile, t)
Expand Down
19 changes: 0 additions & 19 deletions pkg/entrypoint/wrapper/doc.go

This file was deleted.

57 changes: 0 additions & 57 deletions pkg/entrypoint/wrapper/options.go

This file was deleted.

62 changes: 0 additions & 62 deletions pkg/entrypoint/wrapper/options_test.go

This file was deleted.

0 comments on commit f5527aa

Please sign in to comment.