Merge pull request #43105 from intelsdi-x/reuse-sched-event-predicates
Automatic merge from submit-queue (batch tested with PRs 42854, 43105, 43090) Move e2e sched event predicates to new file. **What this PR does / why we need it**: Small e2e test refactor for scheduler. Moves scheduler event predicates out of opaque_resource.go for reuse elsewhere. **Release note**: ```release-note NONE ``` cc @kubernetes/sig-scheduling-pr-reviews @timothysc @bsalamat
This commit is contained in:
		@@ -10,6 +10,7 @@ load(
 | 
			
		||||
go_library(
 | 
			
		||||
    name = "go_default_library",
 | 
			
		||||
    srcs = [
 | 
			
		||||
        "events.go",
 | 
			
		||||
        "opaque_resource.go",
 | 
			
		||||
        "predicates.go",
 | 
			
		||||
        "rescheduler.go",
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										41
									
								
								test/e2e/scheduling/events.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								test/e2e/scheduling/events.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,41 @@
 | 
			
		||||
/*
 | 
			
		||||
Copyright 2017 The Kubernetes 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 scheduling
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"strings"
 | 
			
		||||
 | 
			
		||||
	"k8s.io/kubernetes/pkg/api/v1"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func scheduleSuccessEvent(podName, nodeName string) func(*v1.Event) bool {
 | 
			
		||||
	return func(e *v1.Event) bool {
 | 
			
		||||
		return e.Type == v1.EventTypeNormal &&
 | 
			
		||||
			e.Reason == "Scheduled" &&
 | 
			
		||||
			strings.HasPrefix(e.Name, podName) &&
 | 
			
		||||
			strings.Contains(e.Message, fmt.Sprintf("Successfully assigned %v to %v", podName, nodeName))
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func scheduleFailureEvent(podName string) func(*v1.Event) bool {
 | 
			
		||||
	return func(e *v1.Event) bool {
 | 
			
		||||
		return strings.HasPrefix(e.Name, podName) &&
 | 
			
		||||
			e.Type == "Warning" &&
 | 
			
		||||
			e.Reason == "FailedScheduling"
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -78,7 +78,7 @@ var _ = framework.KubeDescribe("Opaque resources [Feature:OpaqueResources]", fun
 | 
			
		||||
		}
 | 
			
		||||
		// Here we don't check for the bound node name since it can land on
 | 
			
		||||
		// any one (this pod doesn't require any of the opaque resource.)
 | 
			
		||||
		predicate := scheduleSuccess(pod.Name, "")
 | 
			
		||||
		predicate := scheduleSuccessEvent(pod.Name, "")
 | 
			
		||||
		success, err := common.ObserveEventAfterAction(f, predicate, action)
 | 
			
		||||
		Expect(err).NotTo(HaveOccurred())
 | 
			
		||||
		Expect(success).To(Equal(true))
 | 
			
		||||
@@ -103,7 +103,7 @@ var _ = framework.KubeDescribe("Opaque resources [Feature:OpaqueResources]", fun
 | 
			
		||||
			_, err := f.ClientSet.Core().Pods(f.Namespace.Name).Create(pod)
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
		predicate := scheduleSuccess(pod.Name, node.Name)
 | 
			
		||||
		predicate := scheduleSuccessEvent(pod.Name, node.Name)
 | 
			
		||||
		success, err := common.ObserveEventAfterAction(f, predicate, action)
 | 
			
		||||
		Expect(err).NotTo(HaveOccurred())
 | 
			
		||||
		Expect(success).To(Equal(true))
 | 
			
		||||
@@ -121,7 +121,7 @@ var _ = framework.KubeDescribe("Opaque resources [Feature:OpaqueResources]", fun
 | 
			
		||||
			_, err := f.ClientSet.Core().Pods(f.Namespace.Name).Create(f.NewTestPod("over-max-oir", requests, limits))
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
		predicate := scheduleFailure("over-max-oir")
 | 
			
		||||
		predicate := scheduleFailureEvent("over-max-oir")
 | 
			
		||||
		success, err := common.ObserveEventAfterAction(f, predicate, action)
 | 
			
		||||
		Expect(err).NotTo(HaveOccurred())
 | 
			
		||||
		Expect(success).To(Equal(true))
 | 
			
		||||
@@ -166,7 +166,7 @@ var _ = framework.KubeDescribe("Opaque resources [Feature:OpaqueResources]", fun
 | 
			
		||||
			_, err := f.ClientSet.Core().Pods(f.Namespace.Name).Create(pod)
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
		predicate := scheduleSuccess(pod.Name, node.Name)
 | 
			
		||||
		predicate := scheduleSuccessEvent(pod.Name, node.Name)
 | 
			
		||||
		success, err := common.ObserveEventAfterAction(f, predicate, action)
 | 
			
		||||
		Expect(err).NotTo(HaveOccurred())
 | 
			
		||||
		Expect(success).To(Equal(true))
 | 
			
		||||
@@ -206,7 +206,7 @@ var _ = framework.KubeDescribe("Opaque resources [Feature:OpaqueResources]", fun
 | 
			
		||||
			_, err = f.ClientSet.Core().Pods(f.Namespace.Name).Create(pod)
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
		predicate = scheduleFailure(pod.Name)
 | 
			
		||||
		predicate = scheduleFailureEvent(pod.Name)
 | 
			
		||||
		success, err = common.ObserveEventAfterAction(f, predicate, action)
 | 
			
		||||
		Expect(err).NotTo(HaveOccurred())
 | 
			
		||||
		Expect(success).To(Equal(true))
 | 
			
		||||
@@ -232,7 +232,7 @@ var _ = framework.KubeDescribe("Opaque resources [Feature:OpaqueResources]", fun
 | 
			
		||||
			_, err := f.ClientSet.Core().Pods(f.Namespace.Name).Create(pod1)
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
		predicate := scheduleSuccess(pod1.Name, node.Name)
 | 
			
		||||
		predicate := scheduleSuccessEvent(pod1.Name, node.Name)
 | 
			
		||||
		success, err := common.ObserveEventAfterAction(f, predicate, action)
 | 
			
		||||
		Expect(err).NotTo(HaveOccurred())
 | 
			
		||||
		Expect(success).To(Equal(true))
 | 
			
		||||
@@ -242,7 +242,7 @@ var _ = framework.KubeDescribe("Opaque resources [Feature:OpaqueResources]", fun
 | 
			
		||||
			_, err := f.ClientSet.Core().Pods(f.Namespace.Name).Create(pod2)
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
		predicate = scheduleFailure(pod2.Name)
 | 
			
		||||
		predicate = scheduleFailureEvent(pod2.Name)
 | 
			
		||||
		success, err = common.ObserveEventAfterAction(f, predicate, action)
 | 
			
		||||
		Expect(err).NotTo(HaveOccurred())
 | 
			
		||||
		Expect(success).To(Equal(true))
 | 
			
		||||
@@ -252,7 +252,7 @@ var _ = framework.KubeDescribe("Opaque resources [Feature:OpaqueResources]", fun
 | 
			
		||||
			err := f.ClientSet.Core().Pods(f.Namespace.Name).Delete(pod1.Name, nil)
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
		predicate = scheduleSuccess(pod2.Name, node.Name)
 | 
			
		||||
		predicate = scheduleSuccessEvent(pod2.Name, node.Name)
 | 
			
		||||
		success, err = common.ObserveEventAfterAction(f, predicate, action)
 | 
			
		||||
		Expect(err).NotTo(HaveOccurred())
 | 
			
		||||
		Expect(success).To(Equal(true))
 | 
			
		||||
@@ -302,20 +302,3 @@ func escapeForJSONPatch(resName v1.ResourceName) string {
 | 
			
		||||
	// See https://tools.ietf.org/html/rfc6901#section-3
 | 
			
		||||
	return strings.Replace(string(resName), "/", "~1", -1)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func scheduleSuccess(podName, nodeName string) func(*v1.Event) bool {
 | 
			
		||||
	return func(e *v1.Event) bool {
 | 
			
		||||
		return e.Type == v1.EventTypeNormal &&
 | 
			
		||||
			e.Reason == "Scheduled" &&
 | 
			
		||||
			strings.HasPrefix(e.Name, podName) &&
 | 
			
		||||
			strings.Contains(e.Message, fmt.Sprintf("Successfully assigned %v to %v", podName, nodeName))
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func scheduleFailure(podName string) func(*v1.Event) bool {
 | 
			
		||||
	return func(e *v1.Event) bool {
 | 
			
		||||
		return strings.HasPrefix(e.Name, podName) &&
 | 
			
		||||
			e.Type == "Warning" &&
 | 
			
		||||
			e.Reason == "FailedScheduling"
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user