-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a PodTemplate field for PipelineRun and TaskRun
This allows to group and add `PodSpec` customizations to PipelineRun and TaskRun and share the field with both of them. - We are still putting field by hand compared to PodSpec as PodSpec has a large number of fields, including `InitContainers` and `Containers` and we don't want people to be able to add random containers to the `Task` pod. - This adds SecurityContext in addition to the current `PodSpec` specific fields. - This adds Volumes in addition to the current `PodSpec` specific fields. This is done in a backward compatibility way. The old field are still there, but `PodTemplate` takes precedence over it (depending on which field are present). These fields will be remove when we bump the API to `v1beta1`. Signed-off-by: Vincent Demeester <vdemeest@redhat.com>
- Loading branch information
1 parent
254a715
commit 9e49bc0
Showing
11 changed files
with
307 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
Copyright 2019 The Tekton 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. | ||
*/ | ||
|
||
package v1alpha1 | ||
|
||
import ( | ||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
// PodTemplate holds pod specific configuration | ||
type PodTemplate struct { | ||
// 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"` | ||
|
||
// If specified, the pod's tolerations. | ||
// +optional | ||
Tolerations []corev1.Toleration `json:"tolerations,omitempty"` | ||
|
||
// If specified, the pod's scheduling constraints | ||
// +optional | ||
Affinity *corev1.Affinity `json:"affinity,omitempty"` | ||
|
||
// SecurityContext holds pod-level security attributes and common container settings. | ||
// Optional: Defaults to empty. See type description for default values of each field. | ||
// +optional | ||
SecurityContext *corev1.PodSecurityContext `json:"securityContext,omitempty"` | ||
|
||
// List of volumes that can be mounted by containers belonging to the pod. | ||
// More info: https://kubernetes.io/docs/concepts/storage/volumes | ||
// +optional | ||
Volumes []corev1.Volume `json:"volumes,omitempty" patchStrategy:"merge,retainKeys" patchMergeKey:"name" protobuf:"bytes,1,rep,name=volumes"` | ||
} | ||
|
||
// CombinePodTemplate takes a PodTemplate (either from TaskRun or PipelineRun) and merge it with deprecated field that were inlined. | ||
func CombinedPodTemplate(template PodTemplate, deprecatedNodeSelector map[string]string, deprecatedTolerations []corev1.Toleration, deprecatedAffinity *corev1.Affinity) PodTemplate { | ||
if len(template.NodeSelector) == 0 && len(deprecatedNodeSelector) != 0 { | ||
template.NodeSelector = deprecatedNodeSelector | ||
} | ||
if len(template.Tolerations) == 0 && len(deprecatedTolerations) != 0 { | ||
template.Tolerations = deprecatedTolerations | ||
} | ||
if template.Affinity == nil && deprecatedAffinity != nil { | ||
template.Affinity = deprecatedAffinity | ||
} | ||
return template | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
Copyright 2019 The Tekton 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. | ||
*/ | ||
|
||
package v1alpha1_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" | ||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
func TestCombinedPodTemplate(t *testing.T) { | ||
affinity := &corev1.Affinity{ | ||
NodeAffinity: &corev1.NodeAffinity{}, | ||
} | ||
nodeSelector := map[string]string{ | ||
"banana": "chocolat", | ||
} | ||
tolerations := []corev1.Toleration{{ | ||
Key: "banana", | ||
Value: "chocolat", | ||
}} | ||
|
||
template := v1alpha1.PodTemplate{ | ||
NodeSelector: map[string]string{ | ||
"foo": "bar", | ||
"bar": "baz", | ||
}, | ||
Tolerations: []corev1.Toleration{{ | ||
Key: "foo", | ||
Value: "bar", | ||
}}, | ||
Affinity: &corev1.Affinity{ | ||
PodAffinity: &corev1.PodAffinity{}, | ||
}, | ||
} | ||
// Same as template above | ||
want := v1alpha1.PodTemplate{ | ||
NodeSelector: map[string]string{ | ||
"foo": "bar", | ||
"bar": "baz", | ||
}, | ||
Tolerations: []corev1.Toleration{{ | ||
Key: "foo", | ||
Value: "bar", | ||
}}, | ||
Affinity: &corev1.Affinity{ | ||
PodAffinity: &corev1.PodAffinity{}, | ||
}, | ||
} | ||
|
||
got := v1alpha1.CombinedPodTemplate(template, nodeSelector, tolerations, affinity) | ||
if d := cmp.Diff(got, want); d != "" { | ||
t.Errorf("Diff:\n%s", d) | ||
} | ||
} | ||
|
||
func TestCombinedPodTemplateOnlyDeprecated(t *testing.T) { | ||
template := v1alpha1.PodTemplate{} | ||
affinity := &corev1.Affinity{ | ||
NodeAffinity: &corev1.NodeAffinity{}, | ||
} | ||
|
||
nodeSelector := map[string]string{ | ||
"foo": "bar", | ||
} | ||
tolerations := []corev1.Toleration{{ | ||
Key: "foo", | ||
Value: "bar", | ||
}} | ||
|
||
want := v1alpha1.PodTemplate{ | ||
NodeSelector: map[string]string{ | ||
"foo": "bar", | ||
}, | ||
Tolerations: []corev1.Toleration{{ | ||
Key: "foo", | ||
Value: "bar", | ||
}}, | ||
Affinity: affinity, | ||
} | ||
|
||
got := v1alpha1.CombinedPodTemplate(template, nodeSelector, tolerations, affinity) | ||
if d := cmp.Diff(got, want); d != "" { | ||
t.Errorf("Diff:\n%s", d) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.