Skip to content

Commit

Permalink
Add --check-container-placement-strategy.
Browse files Browse the repository at this point in the history
Signed-off-by: Evan <chaol@vmware.com>
  • Loading branch information
evanchaoli committed Jul 26, 2022
1 parent 4ca8281 commit 7dd2088
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
7 changes: 5 additions & 2 deletions atc/atccmd/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ func (cmd *RunCommand) backendComponents(
return nil, err
}

buildContainerStrategy, noInputBuildContainerStrategy, err := cmd.chooseBuildContainerStrategy()
buildContainerStrategy, noInputBuildContainerStrategy, checkBuildContainerStrategy, err := cmd.chooseBuildContainerStrategy()
if err != nil {
return nil, err
}
Expand All @@ -1058,6 +1058,7 @@ func (cmd *RunCommand) backendComponents(
defaultLimits,
buildContainerStrategy,
noInputBuildContainerStrategy,
checkBuildContainerStrategy,
lockFactory,
rateLimiter,
policyChecker,
Expand Down Expand Up @@ -1669,7 +1670,7 @@ func constructLockConns(driverName, connectionString string) ([lock.FactoryCount
return conns, nil
}

func (cmd *RunCommand) chooseBuildContainerStrategy() (worker.PlacementStrategy, worker.PlacementStrategy, error) {
func (cmd *RunCommand) chooseBuildContainerStrategy() (worker.PlacementStrategy, worker.PlacementStrategy, worker.PlacementStrategy, error) {
return worker.NewPlacementStrategy(cmd.ContainerPlacementStrategyOptions)
}

Expand Down Expand Up @@ -1707,6 +1708,7 @@ func (cmd *RunCommand) constructEngine(
defaultLimits atc.ContainerLimits,
strategy worker.PlacementStrategy,
noInputStrategy worker.PlacementStrategy,
checkStrategy worker.PlacementStrategy,
lockFactory lock.LockFactory,
rateLimiter engine.RateLimiter,
policyChecker policy.Checker,
Expand All @@ -1724,6 +1726,7 @@ func (cmd *RunCommand) constructEngine(
defaultLimits,
strategy,
noInputStrategy,
checkStrategy,
cmd.GlobalResourceCheckTimeout,
cmd.DefaultGetTimeout,
cmd.DefaultPutTimeout,
Expand Down
3 changes: 3 additions & 0 deletions atc/engine/step_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type coreStepFactory struct {
defaultLimits atc.ContainerLimits
strategy worker.PlacementStrategy
noInputStrategy worker.PlacementStrategy
checkStrategy worker.PlacementStrategy
defaultCheckTimeout time.Duration
defaultGetTimeout time.Duration
defaultPutTimeout time.Duration
Expand All @@ -42,6 +43,7 @@ func NewCoreStepFactory(
defaultLimits atc.ContainerLimits,
strategy worker.PlacementStrategy,
noInputStrategy worker.PlacementStrategy,
checkStrategy worker.PlacementStrategy,
defaultCheckTimeout time.Duration,
defaultGetTimeout time.Duration,
defaultPutTimeout time.Duration,
Expand All @@ -58,6 +60,7 @@ func NewCoreStepFactory(
defaultLimits: defaultLimits,
strategy: strategy,
noInputStrategy: noInputStrategy,
checkStrategy: checkStrategy,
defaultCheckTimeout: defaultCheckTimeout,
defaultGetTimeout: defaultGetTimeout,
defaultPutTimeout: defaultPutTimeout,
Expand Down
14 changes: 8 additions & 6 deletions atc/exec/check_step.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ type CheckStep struct {
metadata StepMetadata
containerMetadata db.ContainerMetadata
resourceConfigFactory db.ResourceConfigFactory
strategy worker.PlacementStrategy
noInputStrategy worker.PlacementStrategy
checkStrategy worker.PlacementStrategy
delegateFactory CheckDelegateFactory
workerPool Pool
defaultCheckTimeout time.Duration
Expand Down Expand Up @@ -55,7 +56,8 @@ func NewCheckStep(
metadata StepMetadata,
resourceConfigFactory db.ResourceConfigFactory,
containerMetadata db.ContainerMetadata,
strategy worker.PlacementStrategy,
noInputStrategy worker.PlacementStrategy,
checkStrategy worker.PlacementStrategy,
pool Pool,
delegateFactory CheckDelegateFactory,
defaultCheckTimeout time.Duration,
Expand All @@ -67,7 +69,8 @@ func NewCheckStep(
resourceConfigFactory: resourceConfigFactory,
containerMetadata: containerMetadata,
workerPool: pool,
strategy: strategy,
noInputStrategy: noInputStrategy,
checkStrategy: checkStrategy,
delegateFactory: delegateFactory,
defaultCheckTimeout: defaultCheckTimeout,
}
Expand Down Expand Up @@ -273,10 +276,9 @@ func (step *CheckStep) runCheck(
return nil, runtime.ProcessResult{}, err
}

strategy := step.strategy
strategy := step.noInputStrategy
if step.plan.IsResourceCheck() {
// Resource check containers should be placed randomly. Refer to issue #3251.
strategy = nil
strategy = step.checkStrategy
}
worker, err := step.workerPool.FindOrSelectWorker(ctx, containerOwner, containerSpec, workerSpec, strategy, delegate)
if err != nil {
Expand Down
15 changes: 10 additions & 5 deletions atc/worker/placement.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import (

type PlacementOptions struct {
Strategies []string `long:"container-placement-strategy" default:"volume-locality" choice:"volume-locality" choice:"random" choice:"fewest-build-containers" choice:"limit-active-tasks" choice:"limit-active-containers" choice:"limit-active-volumes" description:"Method by which a worker is selected during container placement. If multiple methods are specified, they will be applied in order. Random strategy should only be used alone."`
NoInputStrategies []string `long:"no-input-container-placement-strategy" choice:"volume-locality" choice:"random" choice:"fewest-build-containers" choice:"limit-active-tasks" choice:"limit-active-containers" choice:"limit-active-volumes" description:"A second container placement strategy that will only be used for get and nested check steps."`
NoInputStrategies []string `long:"no-input-container-placement-strategy" choice:"random" choice:"fewest-build-containers" choice:"limit-active-tasks" choice:"limit-active-containers" choice:"limit-active-volumes" description:"A second container placement strategy that will only be used for get and nested check steps."`
CheckStrategies []string `long:"check-container-placement-strategy" default:"random" choice:"random" choice:"fewest-build-containers" choice:"limit-active-tasks" choice:"limit-active-containers" choice:"limit-active-volumes" description:"A second container placement strategy that will only be used for lidar checks."`
MaxActiveTasksPerWorker int `long:"max-active-tasks-per-worker" default:"0" description:"Maximum allowed number of active build tasks per worker. Has effect only when used with limit-active-tasks placement strategy. 0 means no limit."`
MaxActiveContainersPerWorker int `long:"max-active-containers-per-worker" default:"0" description:"Maximum allowed number of active containers per worker. Has effect only when used with limit-active-containers placement strategy. 0 means no limit."`
MaxActiveVolumesPerWorker int `long:"max-active-volumes-per-worker" default:"0" description:"Maximum allowed number of active volumes per worker. Has effect only when used with limit-active-volumes placement strategy. 0 means no limit."`
Expand All @@ -25,7 +26,7 @@ var (
ErrTooManyVolumes = errors.New("worker has too many volumes")
)

func NewPlacementStrategy(options PlacementOptions) (PlacementStrategy, PlacementStrategy, error) {
func NewPlacementStrategy(options PlacementOptions) (PlacementStrategy, PlacementStrategy, PlacementStrategy, error) {
// If no-input-container-placement-strategy is not configured, then just use
// container-placement-strategy.
if len(options.NoInputStrategies) == 0 {
Expand All @@ -34,14 +35,18 @@ func NewPlacementStrategy(options PlacementOptions) (PlacementStrategy, Placemen

strategy, err := newPlaceStrategy(options, options.Strategies)
if err != nil {
return nil, nil, err
return nil, nil, nil, err
}
noInputStrategy, err := newPlaceStrategy(options, options.NoInputStrategies)
if err != nil {
return nil, nil, err
return nil, nil, nil, err
}
checkStrategy, err := newPlaceStrategy(options, options.CheckStrategies)
if err != nil {
return nil, nil, nil, err
}

return strategy, noInputStrategy, nil
return strategy, noInputStrategy, checkStrategy, nil
}

func newPlaceStrategy(options PlacementOptions, chain []string) (PlacementStrategy, error) {
Expand Down

0 comments on commit 7dd2088

Please sign in to comment.