diff --git a/pkg/apis/build/v1alpha1/build_types.go b/pkg/apis/build/v1alpha1/build_types.go index 9a2640db..f6334241 100644 --- a/pkg/apis/build/v1alpha1/build_types.go +++ b/pkg/apis/build/v1alpha1/build_types.go @@ -65,6 +65,12 @@ type BuildSpec struct { // populate fields in the build, and optional Arguments to pass to the // template. Template *TemplateInstantiationSpec `json:"template,omitempty"` + + // NodeSelector is a selector which must be true for the pod to fit on a node. + // Selector which must match a node's labels for the pod to be scheduled on that node. + // More info: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/ + // +optional + NodeSelector map[string]string `json:"nodeSelector,omitempty"` } // TemplateInstantiationSpec specifies how a BuildTemplate is instantiated into diff --git a/pkg/apis/build/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/build/v1alpha1/zz_generated.deepcopy.go index a73da3e4..36d62a66 100644 --- a/pkg/apis/build/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/build/v1alpha1/zz_generated.deepcopy.go @@ -153,6 +153,13 @@ func (in *BuildSpec) DeepCopyInto(out *BuildSpec) { (*in).DeepCopyInto(*out) } } + if in.NodeSelector != nil { + in, out := &in.NodeSelector, &out.NodeSelector + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } return } diff --git a/pkg/builder/cluster/convert/convert.go b/pkg/builder/cluster/convert/convert.go index e534c368..9f9fc212 100644 --- a/pkg/builder/cluster/convert/convert.go +++ b/pkg/builder/cluster/convert/convert.go @@ -333,6 +333,7 @@ func FromCRD(build *v1alpha1.Build, kubeclient kubernetes.Interface) (*corev1.Po Containers: []corev1.Container{nopContainer}, ServiceAccountName: build.Spec.ServiceAccountName, Volumes: volumes, + NodeSelector: build.Spec.NodeSelector, }, }, nil } @@ -450,6 +451,7 @@ func ToCRD(pod *corev1.Pod) (*v1alpha1.Build, error) { Steps: steps, ServiceAccountName: podSpec.ServiceAccountName, Volumes: volumes, + NodeSelector: podSpec.NodeSelector, }, }, nil } diff --git a/pkg/builder/cluster/convert/convert_test.go b/pkg/builder/cluster/convert/convert_test.go index a59db5d1..4910c4ca 100644 --- a/pkg/builder/cluster/convert/convert_test.go +++ b/pkg/builder/cluster/convert/convert_test.go @@ -46,6 +46,7 @@ func TestParsing(t *testing.T) { "testdata/security-context.yaml", "testdata/volumes.yaml", "testdata/custom-source.yaml", + "testdata/nodeselector.yaml", "testdata/git-revision.yaml", diff --git a/pkg/builder/cluster/convert/testdata/nodeselector.yaml b/pkg/builder/cluster/convert/testdata/nodeselector.yaml new file mode 100644 index 00000000..47614fc7 --- /dev/null +++ b/pkg/builder/cluster/convert/testdata/nodeselector.yaml @@ -0,0 +1,19 @@ +# Copyright 2018 The Knative Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +steps: +- name: helloworld + image: gcr.io/google-containers/busybox + args: ["echo Hello World!"] +nodeSelector: + disktype: ssd