diff --git a/pkg/apis/build/v1alpha1/build_types.go b/pkg/apis/build/v1alpha1/build_types.go index 9a2640db..70e8e204 100644 --- a/pkg/apis/build/v1alpha1/build_types.go +++ b/pkg/apis/build/v1alpha1/build_types.go @@ -65,6 +65,9 @@ type BuildSpec struct { // populate fields in the build, and optional Arguments to pass to the // template. Template *TemplateInstantiationSpec `json:"template,omitempty"` + // If specified, the pod's scheduling constraints + // +optional + Affinity *corev1.Affinity `json:"affinity,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..24aa99b4 100644 --- a/pkg/apis/build/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/build/v1alpha1/zz_generated.deepcopy.go @@ -153,6 +153,15 @@ func (in *BuildSpec) DeepCopyInto(out *BuildSpec) { (*in).DeepCopyInto(*out) } } + if in.Affinity != nil { + in, out := &in.Affinity, &out.Affinity + if *in == nil { + *out = nil + } else { + *out = new(v1.Affinity) + (*in).DeepCopyInto(*out) + } + } return } diff --git a/pkg/builder/cluster/convert/convert.go b/pkg/builder/cluster/convert/convert.go index e534c368..b465cfe9 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, + Affinity: build.Spec.Affinity, }, }, nil } @@ -450,6 +451,7 @@ func ToCRD(pod *corev1.Pod) (*v1alpha1.Build, error) { Steps: steps, ServiceAccountName: podSpec.ServiceAccountName, Volumes: volumes, + Affinity: podSpec.Affinity, }, }, nil } diff --git a/pkg/builder/cluster/convert/convert_test.go b/pkg/builder/cluster/convert/convert_test.go index a59db5d1..9550ee11 100644 --- a/pkg/builder/cluster/convert/convert_test.go +++ b/pkg/builder/cluster/convert/convert_test.go @@ -51,6 +51,7 @@ func TestParsing(t *testing.T) { "testdata/gcs-archive.yaml", "testdata/gcs-manifest.yaml", + "testdata/podaffinity.yaml", } for _, in := range inputs { diff --git a/pkg/builder/cluster/convert/testdata/podaffinity.yaml b/pkg/builder/cluster/convert/testdata/podaffinity.yaml new file mode 100644 index 00000000..323e600e --- /dev/null +++ b/pkg/builder/cluster/convert/testdata/podaffinity.yaml @@ -0,0 +1,35 @@ +# 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!"] +affinity: + nodeAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + nodeSelectorTerms: + - matchExpressions: + - key: kubernetes.io/e2e-az-name + operator: In + values: + - e2e-az1 + - e2e-az2 + preferredDuringSchedulingIgnoredDuringExecution: + - weight: 1 + preference: + matchExpressions: + - key: another-node-label-key + operator: In + values: + - another-node-label-value