diff --git a/pkg/project/apiserver/admission/nodeenv/admission.go b/pkg/project/apiserver/admission/nodeenv/admission.go index 66ba8fd27840..8753582541a6 100644 --- a/pkg/project/apiserver/admission/nodeenv/admission.go +++ b/pkg/project/apiserver/admission/nodeenv/admission.go @@ -15,6 +15,10 @@ import ( "github.com/openshift/origin/pkg/util/labelselector" ) +const ( + KubeProjectNodeSelector = "scheduler.alpha.kubernetes.io/node-selector" +) + func Register(plugins *admission.Plugins) { plugins.Register("OriginPodNodeEnvironment", func(config io.Reader) (admission.Interface, error) { @@ -58,6 +62,15 @@ func (p *podNodeEnvironment) Admit(a admission.Attributes) (err error) { if err != nil { return apierrors.NewForbidden(resource, name, err) } + + // If scheduler.alpha.kubernetes.io/node-selector is set on the pod, + // do not process the pod further. + if len(namespace.ObjectMeta.Annotations) > 0 { + if _, ok := namespace.ObjectMeta.Annotations[KubeProjectNodeSelector]; ok { + return nil + } + } + projectNodeSelector, err := p.cache.GetNodeSelectorMap(namespace) if err != nil { return err diff --git a/vendor/k8s.io/kubernetes/pkg/controller/daemon/patch_nodeselector.go b/vendor/k8s.io/kubernetes/pkg/controller/daemon/patch_nodeselector.go index 85367f7af10d..de42132718a6 100644 --- a/vendor/k8s.io/kubernetes/pkg/controller/daemon/patch_nodeselector.go +++ b/vendor/k8s.io/kubernetes/pkg/controller/daemon/patch_nodeselector.go @@ -56,22 +56,24 @@ func (dsc *DaemonSetsController) namespaceNodeSelectorMatches(node *v1.Node, ds } func (dsc *DaemonSetsController) nodeSelectorMatches(node *v1.Node, ns *v1.Namespace) bool { - originNodeSelector, ok := ns.Annotations["openshift.io/node-selector"] - switch { - case ok: - selector, err := labels.Parse(originNodeSelector) - if err == nil { - if !selector.Matches(labels.Set(node.Labels)) { + kubeNodeSelector, ok := ns.Annotations["scheduler.alpha.kubernetes.io/node-selector"] + if !ok { + originNodeSelector, ok := ns.Annotations["openshift.io/node-selector"] + switch { + case ok: + selector, err := labels.Parse(originNodeSelector) + if err == nil { + if !selector.Matches(labels.Set(node.Labels)) { + return false + } + } + case !ok && len(dsc.openshiftDefaultNodeSelectorString) > 0: + if !dsc.openshiftDefaultNodeSelector.Matches(labels.Set(node.Labels)) { return false } } - case !ok && len(dsc.openshiftDefaultNodeSelectorString) > 0: - if !dsc.openshiftDefaultNodeSelector.Matches(labels.Set(node.Labels)) { - return false - } } - kubeNodeSelector, ok := ns.Annotations["scheduler.alpha.kubernetes.io/node-selector"] switch { case ok: selector, err := labels.Parse(kubeNodeSelector) diff --git a/vendor/k8s.io/kubernetes/pkg/controller/daemon/patch_nodeselector_test.go b/vendor/k8s.io/kubernetes/pkg/controller/daemon/patch_nodeselector_test.go index 27cc65c221f1..0c2126c3bd36 100644 --- a/vendor/k8s.io/kubernetes/pkg/controller/daemon/patch_nodeselector_test.go +++ b/vendor/k8s.io/kubernetes/pkg/controller/daemon/patch_nodeselector_test.go @@ -156,8 +156,9 @@ func TestNamespaceNodeSelectorMatches(t *testing.T) { name: "bothSpecified", namespace: bothSpecified, expected: map[string]bool{ - "fifth": true, - "sixth": true, + "second": true, + "fifth": true, + "sixth": true, }, }, }