Skip to content

Commit

Permalink
build nodeselector support with defaults and overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
bparees committed Sep 29, 2016
1 parent c834bf5 commit d8814bb
Show file tree
Hide file tree
Showing 11 changed files with 393 additions and 217 deletions.
15 changes: 11 additions & 4 deletions pkg/build/admission/defaults/admission.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ func (a *buildDefaults) applyBuildDefaults(build *buildapi.Build) {
addDefaultEnvVar(envVar, buildEnv)
}

for k, v := range a.defaultsConfig.NodeSelector {
glog.V(5).Infof("Adding default nodeselector %s=%s to build %s/%s", k, v, build.Namespace, build.Name)
addDefaultNodeSelector(k, v, build.Spec.NodeSelector)
}

sourceDefaults := a.defaultsConfig.SourceStrategyDefaults
sourceStrategy := build.Spec.Strategy.SourceStrategy
if sourceDefaults != nil && sourceDefaults.Incremental != nil && *sourceDefaults.Incremental &&
Expand Down Expand Up @@ -131,10 +136,6 @@ func getBuildEnv(build *buildapi.Build) *[]kapi.EnvVar {
}

func addDefaultEnvVar(v kapi.EnvVar, envVars *[]kapi.EnvVar) {
if envVars == nil {
return
}

found := false
for i := range *envVars {
if (*envVars)[i].Name == v.Name {
Expand All @@ -145,3 +146,9 @@ func addDefaultEnvVar(v kapi.EnvVar, envVars *[]kapi.EnvVar) {
*envVars = append(*envVars, v)
}
}

func addDefaultNodeSelector(k, v string, selectors map[string]string) {
if _, ok := selectors[k]; !ok {
selectors[k] = v
}
}
3 changes: 3 additions & 0 deletions pkg/build/admission/defaults/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ type BuildDefaultsConfig struct {
// SourceStrategyDefaults are default values that apply to builds using the
// source strategy.
SourceStrategyDefaults *SourceStrategyDefaultsConfig

// NodeSelector is a selector which must be true for the build pod to fit on a node
NodeSelector map[string]string
}

// SourceStrategyDefaultsConfig contains values that apply to builds using the
Expand Down
13 changes: 8 additions & 5 deletions pkg/build/admission/defaults/api/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,29 @@ import (
type BuildDefaultsConfig struct {
unversioned.TypeMeta `json:",inline"`

// GitHTTPProxy is the location of the HTTPProxy for Git source
// gitHTTPProxy is the location of the HTTPProxy for Git source
GitHTTPProxy string `json:"gitHTTPProxy,omitempty"`

// GitHTTPSProxy is the location of the HTTPSProxy for Git source
// gitHTTPSProxy is the location of the HTTPSProxy for Git source
GitHTTPSProxy string `json:"gitHTTPSProxy,omitempty"`

// Env is a set of default environment variables that will be applied to the
// env is a set of default environment variables that will be applied to the
// build if the specified variables do not exist on the build
Env []kapi.EnvVar `json:"env,omitempty"`

// SourceStrategyDefaults are default values that apply to builds using the
// sourceStrategyDefaults are default values that apply to builds using the
// source strategy.
SourceStrategyDefaults *SourceStrategyDefaultsConfig `json:"sourceStrategyDefaults,omitempty"`

// nodeSelector is a selector which must be true for the build pod to fit on a node
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
}

// SourceStrategyDefaultsConfig contains values that apply to builds using the
// source strategy.
type SourceStrategyDefaultsConfig struct {

// Incremental indicates if s2i build strategies should perform an incremental
// incremental indicates if s2i build strategies should perform an incremental
// build or not
Incremental *bool `json:"incremental,omitempty"`
}
6 changes: 6 additions & 0 deletions pkg/build/admission/overrides/admission.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ func (a *buildOverrides) applyOverrides(attributes admission.Attributes) error {
glog.V(5).Infof("Setting custom strategy ForcePull to true in build %s/%s", build.Namespace, build.Name)
build.Spec.Strategy.CustomStrategy.ForcePull = true
}

for k, v := range a.overridesConfig.NodeSelector {
glog.V(5).Infof("Adding override nodeselector %s=%s to build %s/%s", k, v, build.Namespace, build.Name)
build.Spec.NodeSelector[k] = v
}

return buildadmission.SetBuild(attributes, build, version)
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/build/admission/overrides/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ type BuildOverridesConfig struct {

// ForcePull indicates whether the build strategy should always be set to ForcePull=true
ForcePull bool

// nodeSelector is a selector which must be true for the build pod to fit on a node
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
}
3 changes: 3 additions & 0 deletions pkg/build/admission/overrides/api/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ type BuildOverridesConfig struct {

// ForcePull indicates whether the build strategy should always be set to ForcePull=true
ForcePull bool `json:"forcePull"`

// nodeSelector is a selector which must be true for the build pod to fit on a node
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
}
3 changes: 3 additions & 0 deletions pkg/build/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ type CommonSpec struct {
// be active on a node before the system actively tries to terminate the
// build; value must be positive integer.
CompletionDeadlineSeconds *int64

// NodeSelector is a selector which must be true for the build pod to fit on a node
NodeSelector map[string]string
}

// BuildTriggerCause holds information about a triggered build. It is used for
Expand Down
Loading

0 comments on commit d8814bb

Please sign in to comment.