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 e2c3417
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 17 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
13 changes: 5 additions & 8 deletions pkg/build/api/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,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 `json:"completionDeadlineSeconds,omitempty" protobuf:"varint,8,opt,name=completionDeadlineSeconds"`

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

// BuildTriggerCause holds information about a triggered build. It is used for
Expand Down Expand Up @@ -255,11 +258,7 @@ type BuildSource struct {
Secrets []SecretBuildSource `json:"secrets,omitempty" protobuf:"bytes,8,rep,name=secrets"`
}

// ImageSource is used to describe build source that will be extracted from an image. A reference of
// type ImageStreamTag, ImageStreamImage or DockerImage may be used. A pull secret can be specified
// to pull the image from an external registry or override the default service account secret if pulling
// from the internal registry. A list of paths to copy from the image and their respective destination
// within the build directory must be specified in the paths array.
// ImageSource describes an image that is used as source for the build
type ImageSource struct {
// from is a reference to an ImageStreamTag, ImageStreamImage, or DockerImage to
// copy source from.
Expand Down Expand Up @@ -615,9 +614,7 @@ type BuildOutput struct {
PushSecret *kapi.LocalObjectReference `json:"pushSecret,omitempty" protobuf:"bytes,2,opt,name=pushSecret"`
}

// Build configurations define a build process for new Docker images. There are three types of builds possible - a Docker build using a Dockerfile, a Source-to-Image build that uses a specially prepared base image that accepts source code that it can make runnable, and a custom build that can run // arbitrary Docker images as a base and accept the build parameters. Builds run on the cluster and on completion are pushed to the Docker registry specified in the "output" section. A build can be triggered via a webhook, when the base image changes, or when a user manually requests a new build be // created.
//
// Each build created by a build configuration is numbered and refers back to its parent configuration. Multiple builds can be triggered at once. Builds that do not have "output" set can be used to test code or run a verification build.
// BuildConfig is a template which can be used to create new builds.
type BuildConfig struct {
unversioned.TypeMeta `json:",inline"`
// metadata for BuildConfig.
Expand Down
1 change: 1 addition & 0 deletions pkg/build/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ func (g *BuildGenerator) generateBuildFromConfig(ctx kapi.Context, bc *buildapi.
Resources: bcCopy.Spec.Resources,
PostCommit: bcCopy.Spec.PostCommit,
CompletionDeadlineSeconds: bcCopy.Spec.CompletionDeadlineSeconds,
NodeSelector: bcCopy.Spec.NodeSelector,
},
},
ObjectMeta: kapi.ObjectMeta{
Expand Down

0 comments on commit e2c3417

Please sign in to comment.