Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Commit

Permalink
Hoist docker flags into a per-runtime instance version
Browse files Browse the repository at this point in the history
  • Loading branch information
sargun committed May 1, 2018
1 parent e729bb9 commit aa37e28
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 119 deletions.
9 changes: 5 additions & 4 deletions cmd/titus-executor/main.go
Expand Up @@ -58,12 +58,13 @@ func main() {
// avoid os.Exit as much as possible to let deferred functions run
defer time.Sleep(1 * time.Second)

app.Flags = append(flags, docker.Flags...)
dockerCfg, dockerCfgFlags := docker.NewConfig()
app.Flags = append(flags, dockerCfgFlags...)

cfg, cfgFlags := config.NewConfig()
app.Flags = append(app.Flags, cfgFlags...)
app.Action = func(c *cli.Context) error {
return cli.NewExitError(mainWithError(c, cfg), 1)
return cli.NewExitError(mainWithError(c, dockerCfg, cfg), 1)
}

altsrc.InitInputSourceWithContext(app.Flags, properties.NewQuiteliteSource("disable-quitelite", "quitelite-url"))
Expand All @@ -72,7 +73,7 @@ func main() {
}
}

func mainWithError(c *cli.Context, cfg *config.Config) error {
func mainWithError(c *cli.Context, dockerCfg *docker.Config, cfg *config.Config) error {
defer log.Info("titus executor terminated")

ctx, cancel := context.WithCancel(context.Background())
Expand All @@ -97,7 +98,7 @@ func mainWithError(c *cli.Context, cfg *config.Config) error {
return fmt.Errorf("Cannot create log uploaders: %v", err)
}

runner, err := runner.New(ctx, m, logUploaders, *cfg)
runner, err := runner.New(ctx, m, logUploaders, *cfg, *dockerCfg)
if err != nil {
return fmt.Errorf("Cannot create Titus executor: %v", err)
}
Expand Down
15 changes: 9 additions & 6 deletions cmd/titus-standalone/main.go
Expand Up @@ -40,9 +40,6 @@ func main() {
// avoid os.Exit as much as possible to let deferred functions run
cfg, cfgFlags := config.NewConfig()

app.Action = func(c *cli.Context) error {
return cli.NewExitError(mainWithError(c, cfg, &options), 1)
}
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "container-info",
Expand Down Expand Up @@ -75,15 +72,21 @@ func main() {
Destination: &options.logLevel,
},
}
app.Flags = append(app.Flags, docker.Flags...)
app.Flags = append(app.Flags, cfgFlags...)

dockerCfg, dockerCfgFlags := docker.NewConfig()
app.Flags = append(app.Flags, dockerCfgFlags...)

app.Action = func(c *cli.Context) error {
return cli.NewExitError(mainWithError(c, dockerCfg, cfg, &options), 1)
}

if err := app.Run(os.Args); err != nil {
panic(err)
}
}

func mainWithError(c *cli.Context, cfg *config.Config, options *cliOptions) error { // nolint: gocyclo
func mainWithError(c *cli.Context, dockerCfg *docker.Config, cfg *config.Config, options *cliOptions) error { // nolint: gocyclo
defer log.Info("titus executor terminated")

switch options.logLevel {
Expand Down Expand Up @@ -125,7 +128,7 @@ func mainWithError(c *cli.Context, cfg *config.Config, options *cliOptions) erro
return fmt.Errorf("Cannot create log uploaders: %v", err)
}

runner, err := runner.New(ctx, m, logUploaders, *cfg)
runner, err := runner.New(ctx, m, logUploaders, *cfg, *dockerCfg)
if err != nil {
return fmt.Errorf("Cannot create Titus executor: %v", err)
}
Expand Down
8 changes: 7 additions & 1 deletion executor/mock/jobrunner.go
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/Netflix/titus-executor/config"
"github.com/Netflix/titus-executor/executor/drivers"
"github.com/Netflix/titus-executor/executor/runner"
"github.com/Netflix/titus-executor/executor/runtime/docker"
"github.com/Netflix/titus-executor/uploader"
protobuf "github.com/golang/protobuf/proto"
"github.com/pborman/uuid"
Expand Down Expand Up @@ -123,14 +124,19 @@ func NewJobRunner() *JobRunner {
cfg.KeepLocalFileAfterUpload = true
cfg.MetatronEnabled = false

dockerCfg, err := docker.GenerateConfiguration(nil)
if err != nil {
panic(err)
}

// Create an executor
logUploaders, err := uploader.NewUploaders(cfg)
if err != nil {
log.Fatalf("cannot create log uploaders: %s", err)
}
ctx, cancel := context.WithCancel(context.Background())
// TODO: Replace this config mechanism
r, err := runner.New(ctx, metrics.Discard, logUploaders, *cfg)
r, err := runner.New(ctx, metrics.Discard, logUploaders, *cfg, *dockerCfg)
if err != nil {
log.Fatalf("cannot create executor : %s", err)
}
Expand Down
34 changes: 18 additions & 16 deletions executor/mock/standalone/standalone_test.go
Expand Up @@ -12,29 +12,17 @@ import (
"testing"
"time"

"io/ioutil"

"github.com/Netflix/titus-executor/api/netflix/titus"
"github.com/Netflix/titus-executor/executor/mock"
"github.com/Netflix/titus-executor/executor/runtime/docker"
"github.com/mesos/mesos-go/mesosproto"
"github.com/pborman/uuid"
log "github.com/sirupsen/logrus"
"gopkg.in/urfave/cli.v1"
)

var standalone bool

func init() {
if debug, err := strconv.ParseBool(os.Getenv("DEBUG")); err == nil && debug {
log.SetLevel(log.DebugLevel)
}
flag.BoolVar(&standalone, "standalone", false, "Enable standalone tests")
flag.Parse()
app := cli.NewApp()
app.Flags = docker.Flags
app.Writer = ioutil.Discard
_ = app.Run(os.Args)
}

type testImage struct {
Expand Down Expand Up @@ -74,9 +62,6 @@ var (
// This file still uses log as opposed to using the testing library's built-in logging framework.
// Since we do not configure Logrus, we will just log to stderr.
func TestStandalone(t *testing.T) {
if !standalone {
t.Skipf("Standalone tests are not enabled! Activate with the -standalone cmdline flag.")
}
testFunctions := []func(*testing.T){
testSimpleJob,
testSimpleJobWithBadEnvironment,
Expand Down Expand Up @@ -104,7 +89,8 @@ func TestStandalone(t *testing.T) {
fullName := runtime.FuncForPC(reflect.ValueOf(fun).Pointer()).Name()
splitName := strings.Split(fullName, ".")
funName := splitName[len(splitName)-1]
t.Run(strings.Title(funName), makeTestParallel(fun))
testName := strings.Title(funName)
t.Run(testName, wrapTestStandalone(testName, makeTestParallel(fun)))
}
}

Expand All @@ -115,6 +101,22 @@ func makeTestParallel(f func(*testing.T)) func(*testing.T) {
}
}

func wrapTestStandalone(testName string, f func(*testing.T)) func(*testing.T) {
return func(t *testing.T) {
// TODO: Add logic to pull in config.flags, and docker.flags
var standalone bool
flagSet := flag.NewFlagSet(testName, flag.PanicOnError)
flagSet.BoolVar(&standalone, "standalone", false, "Enable standalone tests")
if err := flagSet.Parse(os.Args); err != nil {
t.Fatal("Could not parse flags: ", err)
}
if !standalone {
t.Skip("Standalone tests are not enabled! Activate with the -standalone cmdline flag")
}
f(t)
}
}

func testSimpleJob(t *testing.T) {
ji := &mock.JobInput{
ImageName: alpine.name,
Expand Down
4 changes: 2 additions & 2 deletions executor/runner/runner.go
Expand Up @@ -77,9 +77,9 @@ type Runner struct { // nolint: maligned
type RuntimeProvider func(context.Context, config.Config) (runtimeTypes.Runtime, error)

// New constructs a new Executor object with the default (docker) runtime
func New(ctx context.Context, m metrics.Reporter, logUploaders *uploader.Uploaders, cfg config.Config) (*Runner, error) {
func New(ctx context.Context, m metrics.Reporter, logUploaders *uploader.Uploaders, cfg config.Config, dockerCfg docker.Config) (*Runner, error) {
dockerRuntime := func(ctx context.Context, cfg config.Config) (runtimeTypes.Runtime, error) {
return docker.NewDockerRuntime(ctx, m, cfg)
return docker.NewDockerRuntime(ctx, m, dockerCfg, cfg)
}
return WithRuntime(ctx, m, dockerRuntime, logUploaders, cfg)
}
Expand Down

0 comments on commit aa37e28

Please sign in to comment.