Skip to content

Commit

Permalink
Merge pull request kubernetes#63067 from k82cn/k8s_63027
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue (batch tested with PRs 62982, 63075, 63067, 62877, 63141). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Removed e2e test on empty NodeAffinity.

Signed-off-by: Da K. Ma <klaus1982.cn@gmail.com>

**Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*:
Fixes kubernetes#63027 

**Special notes for your reviewer**:
In kubernetes#62448, we removed the validation on empty `nodeAffinity` which is already handled in scheduler: select no objects.

**Release note**:
```release-note
None
```
  • Loading branch information
Kubernetes Submit Queue committed Apr 25, 2018
2 parents 9728717 + 793ed98 commit e270b8a
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 24 deletions.
25 changes: 25 additions & 0 deletions pkg/apis/core/validation/validation_test.go
Expand Up @@ -6582,6 +6582,31 @@ func TestValidatePod(t *testing.T) {
}),
},
},
"invalid node selector requirement in node affinity, key is invalid": {
expectedError: "spec.affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms[0].matchExpressions[0].key",
spec: core.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "123",
Namespace: "ns",
},
Spec: validPodSpec(&core.Affinity{
NodeAffinity: &core.NodeAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: &core.NodeSelector{
NodeSelectorTerms: []core.NodeSelectorTerm{
{
MatchExpressions: []core.NodeSelectorRequirement{
{
Key: "invalid key ___@#",
Operator: core.NodeSelectorOpExists,
},
},
},
},
},
},
}),
},
},
"invalid node field selector requirement in node affinity, more values for field selector": {
expectedError: "spec.affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms[0].matchFields[0].values",
spec: core.Pod{
Expand Down
28 changes: 28 additions & 0 deletions pkg/scheduler/algorithm/predicates/predicates_test.go
Expand Up @@ -1359,6 +1359,34 @@ func TestPodFitsSelector(t *testing.T) {
test: "Pod with an Affinity matches node's labels but the PodSpec.NodeSelector(the old thing that we are deprecating) " +
"is not satisfied, won't schedule onto the node",
},
{
pod: &v1.Pod{
Spec: v1.PodSpec{
Affinity: &v1.Affinity{
NodeAffinity: &v1.NodeAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: &v1.NodeSelector{
NodeSelectorTerms: []v1.NodeSelectorTerm{
{
MatchExpressions: []v1.NodeSelectorRequirement{
{
Key: "foo",
Operator: v1.NodeSelectorOpNotIn,
Values: []string{"invalid value: ___@#$%^"},
},
},
},
},
},
},
},
},
},
labels: map[string]string{
"foo": "bar",
},
fits: false,
test: "Pod with an invalid value in Affinity term won't be scheduled onto the node",
},
}
expectedFailureReasons := []algorithm.PredicateFailureReason{ErrNodeSelectorNotMatch}

Expand Down
24 changes: 0 additions & 24 deletions test/e2e/scheduling/predicates.go
Expand Up @@ -21,7 +21,6 @@ import (
"time"

"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
Expand Down Expand Up @@ -367,29 +366,6 @@ var _ = SIGDescribe("SchedulerPredicates [Serial]", func() {
verifyResult(cs, 0, 1, ns)
})

It("validates that a pod with an invalid NodeAffinity is rejected", func() {
By("Trying to launch a pod with an invalid Affinity data.")
podName := "without-label"
_, err := cs.CoreV1().Pods(ns).Create(initPausePod(f, pausePodConfig{
Name: podName,
Affinity: &v1.Affinity{
NodeAffinity: &v1.NodeAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: &v1.NodeSelector{
NodeSelectorTerms: []v1.NodeSelectorTerm{
{
MatchExpressions: []v1.NodeSelectorRequirement{},
},
},
},
},
},
}))

if err == nil || !errors.IsInvalid(err) {
framework.Failf("Expect error of invalid, got : %v", err)
}
})

/*
Testname: scheduler-node-selector-matching
Description: Ensure that scheduler respects the NodeSelector field
Expand Down

0 comments on commit e270b8a

Please sign in to comment.