Skip to content

Commit

Permalink
[YUNIKORN-1952] Ensure Verify_allow_preemption_tag e2e test honors an…
Browse files Browse the repository at this point in the history
…notation on PriorityClass (#668)

Closes: #668

Signed-off-by: Craig Condit <[email protected]>
  • Loading branch information
wusamzong authored and craigcondit committed Oct 26, 2023
1 parent c8cae65 commit 53f6f3e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 24 deletions.
31 changes: 21 additions & 10 deletions test/e2e/framework/helpers/k8s/pod_conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,18 @@ type SleepPodConfig struct {
CPU int64
Mem int64
RequiredNode string
Optedout bool
Optedout AllowPreemptOpted
Labels map[string]string
}

type AllowPreemptOpted int

const (
NotConfig AllowPreemptOpted = iota
Allow
Deny
)

// TestPodConfig template for sleepPods
func InitSleepPod(conf SleepPodConfig) (*v1.Pod, error) {
// Initialize default values
Expand Down Expand Up @@ -88,9 +96,16 @@ func InitSleepPod(conf SleepPodConfig) (*v1.Pod, error) {
}
}

optedOut := constants.True
if !conf.Optedout {
optedOut = constants.False
annotation := &PodAnnotation{
Other: map[string]string{},
}

switch conf.Optedout {
case NotConfig:
case Allow:
annotation.Other[constants.AnnotationAllowPreemption] = constants.True
case Deny:
annotation.Other[constants.AnnotationAllowPreemption] = constants.False
}

labels := map[string]string{
Expand All @@ -109,12 +124,8 @@ func InitSleepPod(conf SleepPodConfig) (*v1.Pod, error) {
RestartPolicy: v1.RestartPolicyNever,
DeletionGracePeriodSeconds: &secs,
Command: []string{"sleep", strconv.Itoa(conf.Time)},
Annotations: &PodAnnotation{
Other: map[string]string{
constants.AnnotationAllowPreemption: optedOut,
},
},
Labels: labels,
Annotations: annotation,
Labels: labels,
Resources: &v1.ResourceRequirements{
Requests: v1.ResourceList{
"cpu": resource.MustParse(strconv.FormatInt(conf.CPU, 10) + "m"),
Expand Down
22 changes: 11 additions & 11 deletions test/e2e/preemption/preemption_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ var _ = ginkgo.Describe("Preemption", func() {

// Define sleepPod
sleepPodConfigs := createSandbox1SleepPodCofigs(3, 600)
sleepPod4Config := k8s.SleepPodConfig{Name: "sleepjob4", NS: dev, Mem: sleepPodMemLimit, Time: 600, Optedout: true, Labels: map[string]string{"queue": "root.sandbox2"}}
sleepPod4Config := k8s.SleepPodConfig{Name: "sleepjob4", NS: dev, Mem: sleepPodMemLimit, Time: 600, Optedout: k8s.Allow, Labels: map[string]string{"queue": "root.sandbox2"}}
sleepPodConfigs = append(sleepPodConfigs, sleepPod4Config)

for _, config := range sleepPodConfigs {
Expand Down Expand Up @@ -225,7 +225,7 @@ var _ = ginkgo.Describe("Preemption", func() {

// Define sleepPod
sandbox1SleepPodConfigs := createSandbox1SleepPodCofigs(3, 30)
sleepPod4Config := k8s.SleepPodConfig{Name: "sleepjob4", NS: dev, Mem: sleepPodMemLimit, Time: 30, Optedout: true, Labels: map[string]string{"queue": "root.sandbox2"}}
sleepPod4Config := k8s.SleepPodConfig{Name: "sleepjob4", NS: dev, Mem: sleepPodMemLimit, Time: 30, Optedout: k8s.Allow, Labels: map[string]string{"queue": "root.sandbox2"}}

// Deploy pods in root.sandbox1
for _, config := range sandbox1SleepPodConfigs {
Expand Down Expand Up @@ -292,7 +292,7 @@ var _ = ginkgo.Describe("Preemption", func() {

// Define sleepPod
sandbox1SleepPodConfigs := createSandbox1SleepPodCofigs(3, 30)
sleepPod4Config := k8s.SleepPodConfig{Name: "sleepjob4", NS: dev, Mem: sleepPodMemLimit, Time: 30, Optedout: true, Labels: map[string]string{"queue": "root.sandbox2"}}
sleepPod4Config := k8s.SleepPodConfig{Name: "sleepjob4", NS: dev, Mem: sleepPodMemLimit, Time: 30, Optedout: k8s.Allow, Labels: map[string]string{"queue": "root.sandbox2"}}

// Deploy pods in root.sandbox1
for _, config := range sandbox1SleepPodConfigs {
Expand Down Expand Up @@ -367,8 +367,8 @@ var _ = ginkgo.Describe("Preemption", func() {

// Define sleepPod
sandbox1SleepPodConfigs := createSandbox1SleepPodCofigs(3, 30)
sleepPod4Config := k8s.SleepPodConfig{Name: "sleepjob4", NS: dev, Mem: sleepPodMemLimit, Time: 600, Optedout: true, Labels: map[string]string{"queue": "root.low-priority"}}
sleepPod5Config := k8s.SleepPodConfig{Name: "sleepjob5", NS: dev, Mem: sleepPodMemLimit, Time: 600, Optedout: true, Labels: map[string]string{"queue": "root.high-priority"}}
sleepPod4Config := k8s.SleepPodConfig{Name: "sleepjob4", NS: dev, Mem: sleepPodMemLimit, Time: 600, Optedout: k8s.Allow, Labels: map[string]string{"queue": "root.low-priority"}}
sleepPod5Config := k8s.SleepPodConfig{Name: "sleepjob5", NS: dev, Mem: sleepPodMemLimit, Time: 600, Optedout: k8s.Allow, Labels: map[string]string{"queue": "root.high-priority"}}

for _, config := range sandbox1SleepPodConfigs {
ginkgo.By("Deploy the sleep pod " + config.Name + " to the development namespace")
Expand Down Expand Up @@ -483,11 +483,11 @@ var _ = ginkgo.Describe("Preemption", func() {
gomega.Ω(err).ShouldNot(HaveOccurred())

// Define sleepPod
sleepPod1Config := k8s.SleepPodConfig{Name: "sleepjob1", NS: dev, Mem: sleepPodMemLimit2, Time: 60, Optedout: true, Labels: map[string]string{"queue": "root.sandbox3"}}
sleepPod2Config := k8s.SleepPodConfig{Name: "sleepjob2", NS: dev, Mem: sleepPodMemLimit2, Time: 60, Optedout: true, Labels: map[string]string{"queue": "root.sandbox3"}}
sleepPod3Config := k8s.SleepPodConfig{Name: "sleepjob3", NS: dev, Mem: sleepPodMemLimit2, Time: 60, Optedout: false, Labels: map[string]string{"queue": "root.sandbox4"}}
sleepPod4Config := k8s.SleepPodConfig{Name: "sleepjob4", NS: dev, Mem: sleepPodMemLimit2, Time: 60, Optedout: false, Labels: map[string]string{"queue": "root.sandbox4"}}
sleepPod5Config := k8s.SleepPodConfig{Name: "sleepjob5", NS: dev, Mem: sleepPodMemLimit2, Time: 600, Optedout: true, Labels: map[string]string{"queue": "root.sandbox5"}}
sleepPod1Config := k8s.SleepPodConfig{Name: "sleepjob1", NS: dev, Mem: sleepPodMemLimit2, Time: 60, Optedout: k8s.NotConfig, Labels: map[string]string{"queue": "root.sandbox3"}}
sleepPod2Config := k8s.SleepPodConfig{Name: "sleepjob2", NS: dev, Mem: sleepPodMemLimit2, Time: 60, Optedout: k8s.NotConfig, Labels: map[string]string{"queue": "root.sandbox3"}}
sleepPod3Config := k8s.SleepPodConfig{Name: "sleepjob3", NS: dev, Mem: sleepPodMemLimit2, Time: 60, Optedout: k8s.NotConfig, Labels: map[string]string{"queue": "root.sandbox4"}}
sleepPod4Config := k8s.SleepPodConfig{Name: "sleepjob4", NS: dev, Mem: sleepPodMemLimit2, Time: 60, Optedout: k8s.NotConfig, Labels: map[string]string{"queue": "root.sandbox4"}}
sleepPod5Config := k8s.SleepPodConfig{Name: "sleepjob5", NS: dev, Mem: sleepPodMemLimit2, Time: 600, Optedout: k8s.NotConfig, Labels: map[string]string{"queue": "root.sandbox5"}}

for _, config := range []k8s.SleepPodConfig{sleepPod1Config, sleepPod2Config, sleepPod3Config, sleepPod4Config} {
ginkgo.By("Deploy the sleep pod " + config.Name + " to the development namespace")
Expand Down Expand Up @@ -568,7 +568,7 @@ var _ = ginkgo.Describe("Preemption", func() {
func createSandbox1SleepPodCofigs(cnt, time int) []k8s.SleepPodConfig {
sandbox1Configs := make([]k8s.SleepPodConfig, 0, cnt)
for i := 0; i < cnt; i++ {
sandbox1Configs = append(sandbox1Configs, k8s.SleepPodConfig{Name: fmt.Sprintf("sleepjob%d", i+1), NS: dev, Mem: sleepPodMemLimit, Time: time, Optedout: true, Labels: map[string]string{"queue": "root.sandbox1"}})
sandbox1Configs = append(sandbox1Configs, k8s.SleepPodConfig{Name: fmt.Sprintf("sleepjob%d", i+1), NS: dev, Mem: sleepPodMemLimit, Time: time, Optedout: k8s.Allow, Labels: map[string]string{"queue": "root.sandbox1"}})
}
return sandbox1Configs
}
6 changes: 3 additions & 3 deletions test/e2e/simple_preemptor/simple_preemptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ var _ = ginkgo.Describe("SimplePreemptor", func() {
sleepPod3Configs := k8s.SleepPodConfig{Name: "sleepjob3", NS: dev, Mem: sleepPodMemLimit1, Time: 600, RequiredNode: Worker1, AppID: "test01"}

// add the same AppID to sleepPod3Configs so that sleepPod4Configs is not the originator pod
sleepPod4Configs := k8s.SleepPodConfig{Name: "sleepjob4", NS: dev, Mem: sleepPodMemLimit2, Time: 600, Optedout: true, AppID: "test01"}
sleepPod5Configs := k8s.SleepPodConfig{Name: "sleepjob5", NS: dev, Mem: sleepPodMemLimit2, Time: 600, Optedout: false}
sleepPod6Configs := k8s.SleepPodConfig{Name: "sleepjob6", NS: dev, Mem: sleepPodMemLimit2, Time: 600, Optedout: false}
sleepPod4Configs := k8s.SleepPodConfig{Name: "sleepjob4", NS: dev, Mem: sleepPodMemLimit2, Time: 600, Optedout: k8s.Allow, AppID: "test01"}
sleepPod5Configs := k8s.SleepPodConfig{Name: "sleepjob5", NS: dev, Mem: sleepPodMemLimit2, Time: 600, Optedout: k8s.Deny}
sleepPod6Configs := k8s.SleepPodConfig{Name: "sleepjob6", NS: dev, Mem: sleepPodMemLimit2, Time: 600, Optedout: k8s.Deny}
sleepPod7Configs := k8s.SleepPodConfig{Name: "sleepjob7", NS: dev, Mem: sleepPodMemLimit2, Time: 600, RequiredNode: Worker2}

for _, config := range []k8s.SleepPodConfig{sleepPodConfigs, sleepPod2Configs,
Expand Down

0 comments on commit 53f6f3e

Please sign in to comment.