diff --git a/pkg/build/admission/defaults/admission.go b/pkg/build/admission/defaults/admission.go index 19c815fcfe59..d0499b789ae0 100644 --- a/pkg/build/admission/defaults/admission.go +++ b/pkg/build/admission/defaults/admission.go @@ -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 && @@ -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 { @@ -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 + } +} diff --git a/pkg/build/admission/defaults/api/types.go b/pkg/build/admission/defaults/api/types.go index 40bdb2309200..b6fd9b341cec 100644 --- a/pkg/build/admission/defaults/api/types.go +++ b/pkg/build/admission/defaults/api/types.go @@ -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 diff --git a/pkg/build/admission/defaults/api/v1/types.go b/pkg/build/admission/defaults/api/v1/types.go index b86606c29989..5143c6f905ab 100644 --- a/pkg/build/admission/defaults/api/v1/types.go +++ b/pkg/build/admission/defaults/api/v1/types.go @@ -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"` } diff --git a/pkg/build/admission/overrides/admission.go b/pkg/build/admission/overrides/admission.go index d4ac5862065c..875c1a7dbda1 100644 --- a/pkg/build/admission/overrides/admission.go +++ b/pkg/build/admission/overrides/admission.go @@ -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) } diff --git a/pkg/build/admission/overrides/api/types.go b/pkg/build/admission/overrides/api/types.go index e0d6db377da8..a669240406a5 100644 --- a/pkg/build/admission/overrides/api/types.go +++ b/pkg/build/admission/overrides/api/types.go @@ -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"` } diff --git a/pkg/build/admission/overrides/api/v1/types.go b/pkg/build/admission/overrides/api/v1/types.go index ed78def96c86..69d3280b93c8 100644 --- a/pkg/build/admission/overrides/api/v1/types.go +++ b/pkg/build/admission/overrides/api/v1/types.go @@ -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"` } diff --git a/pkg/build/api/types.go b/pkg/build/api/types.go index 7ca948a44780..b24e5bd0d89e 100644 --- a/pkg/build/api/types.go +++ b/pkg/build/api/types.go @@ -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 diff --git a/pkg/build/api/v1/types.go b/pkg/build/api/v1/types.go index 1dfc33222cb4..a06cc0047c3b 100644 --- a/pkg/build/api/v1/types.go +++ b/pkg/build/api/v1/types.go @@ -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 @@ -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. @@ -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. diff --git a/pkg/build/generator/generator.go b/pkg/build/generator/generator.go index 1a0bdc91cf3e..95dd8b875a79 100644 --- a/pkg/build/generator/generator.go +++ b/pkg/build/generator/generator.go @@ -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{