Skip to content

Commit

Permalink
Use IsActive function, clean up provisioning integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PBundyra committed Jun 7, 2024
1 parent 01d788d commit bbcf7c5
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 44 deletions.
6 changes: 3 additions & 3 deletions pkg/controller/core/workload_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (r *WorkloadReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
return ctrl.Result{}, nil
}

if ptr.Deref(wl.Spec.Active, true) {
if workload.IsActive(&wl) {
var updated bool
if cond := apimeta.FindStatusCondition(wl.Status.Conditions, kueue.WorkloadRequeued); cond != nil && cond.Status == metav1.ConditionFalse {
switch cond.Reason {
Expand Down Expand Up @@ -420,7 +420,7 @@ func syncAdmissionCheckConditions(conds []kueue.AdmissionCheckState, admissionCh
func (r *WorkloadReconciler) reconcileNotReadyTimeout(ctx context.Context, req ctrl.Request, wl *kueue.Workload) (ctrl.Result, error) {
log := ctrl.LoggerFrom(ctx)

if !ptr.Deref(wl.Spec.Active, true) || apimeta.IsStatusConditionTrue(wl.Status.Conditions, kueue.WorkloadEvicted) {
if !workload.IsActive(wl) || apimeta.IsStatusConditionTrue(wl.Status.Conditions, kueue.WorkloadEvicted) {
// the workload has already been evicted by the PodsReadyTimeout or been deactivated.
return ctrl.Result{}, nil
}
Expand Down Expand Up @@ -568,7 +568,7 @@ func (r *WorkloadReconciler) Update(e event.UpdateEvent) bool {
status := workload.Status(wl)
log := r.log.WithValues("workload", klog.KObj(wl), "queue", wl.Spec.QueueName, "status", status)
ctx := ctrl.LoggerInto(context.Background(), log)
active := ptr.Deref(wl.Spec.Active, true)
active := workload.IsActive(wl)

prevQueue := oldWl.Spec.QueueName
if prevQueue != wl.Spec.QueueName {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,6 @@ var _ = ginkgo.Describe("Provisioning", ginkgo.Ordered, ginkgo.ContinueOnFailure
})

ginkgo.By("Checking no provision request is created", func() {
provReqKey := types.NamespacedName{
Namespace: wlKey.Namespace,
Name: provisioning.ProvisioningRequestName(wlKey.Name, ac.Name, 1),
}
gomega.Consistently(func() error {
request := &autoscaling.ProvisioningRequest{}
return k8sClient.Get(ctx, provReqKey, request)
Expand Down Expand Up @@ -249,10 +245,6 @@ var _ = ginkgo.Describe("Provisioning", ginkgo.Ordered, ginkgo.ContinueOnFailure

createdRequest := &autoscaling.ProvisioningRequest{}
ginkgo.By("Checking that the provision request is created", func() {
provReqKey := types.NamespacedName{
Namespace: wlKey.Namespace,
Name: provisioning.ProvisioningRequestName(wlKey.Name, ac.Name, 1),
}
gomega.Eventually(func() error {
return k8sClient.Get(ctx, provReqKey, createdRequest)
}, util.Timeout, util.Interval).Should(gomega.Succeed())
Expand Down Expand Up @@ -311,10 +303,6 @@ var _ = ginkgo.Describe("Provisioning", ginkgo.Ordered, ginkgo.ContinueOnFailure
})

ginkgo.By("Checking that the provision request is preserved", func() {
provReqKey := types.NamespacedName{
Namespace: wlKey.Namespace,
Name: provisioning.ProvisioningRequestName(wlKey.Name, ac.Name, 1),
}
gomega.Consistently(func() error {
return k8sClient.Get(ctx, provReqKey, createdRequest)
}, util.ConsistentDuration, util.Interval).Should(gomega.Succeed())
Expand Down Expand Up @@ -346,10 +334,6 @@ var _ = ginkgo.Describe("Provisioning", ginkgo.Ordered, ginkgo.ContinueOnFailure
}, util.Timeout, util.Interval).Should(gomega.Succeed())
})

provReqKey := types.NamespacedName{
Namespace: wlKey.Namespace,
Name: provisioning.ProvisioningRequestName(wlKey.Name, ac.Name, 1),
}
ginkgo.By("Setting the provision request as Accepted", func() {
createdRequest := &autoscaling.ProvisioningRequest{}
gomega.Eventually(func() error {
Expand Down Expand Up @@ -462,10 +446,6 @@ var _ = ginkgo.Describe("Provisioning", ginkgo.Ordered, ginkgo.ContinueOnFailure

ginkgo.By("Setting the provision request as Failed", func() {
createdRequest := &autoscaling.ProvisioningRequest{}
provReqKey := types.NamespacedName{
Namespace: wlKey.Namespace,
Name: provisioning.ProvisioningRequestName(wlKey.Name, ac.Name, 1),
}
gomega.Eventually(func() error {
err := k8sClient.Get(ctx, provReqKey, createdRequest)
if err != nil {
Expand Down Expand Up @@ -623,10 +603,6 @@ var _ = ginkgo.Describe("Provisioning", ginkgo.Ordered, ginkgo.ContinueOnFailure
})

createdRequest := &autoscaling.ProvisioningRequest{}
provReqKey := types.NamespacedName{
Namespace: wlKey.Namespace,
Name: provisioning.ProvisioningRequestName(wlKey.Name, ac.Name, 1),
}
ginkgo.By("Checking that the provision request is created", func() {
gomega.Eventually(func() error {
return k8sClient.Get(ctx, provReqKey, createdRequest)
Expand Down Expand Up @@ -712,10 +688,6 @@ var _ = ginkgo.Describe("Provisioning", ginkgo.Ordered, ginkgo.ContinueOnFailure
})

ginkgo.By("Checking no provision request is deleted", func() {
provReqKey := types.NamespacedName{
Namespace: wlKey.Namespace,
Name: provisioning.ProvisioningRequestName(wlKey.Name, ac.Name, 1),
}
gomega.Eventually(func() error {
request := &autoscaling.ProvisioningRequest{}
return k8sClient.Get(ctx, provReqKey, request)
Expand Down Expand Up @@ -757,11 +729,6 @@ var _ = ginkgo.Describe("Provisioning", ginkgo.Ordered, ginkgo.ContinueOnFailure
})

createdRequest := &autoscaling.ProvisioningRequest{}
provReqKey := types.NamespacedName{
Namespace: wlKey.Namespace,
Name: provisioning.ProvisioningRequestName(wlKey.Name, ac.Name, 1),
}

ginkgo.By("Checking that the provision request is created", func() {
gomega.Eventually(func() error {
return k8sClient.Get(ctx, provReqKey, createdRequest)
Expand Down
4 changes: 2 additions & 2 deletions test/integration/controller/jobs/pod/pod_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1742,7 +1742,7 @@ var _ = ginkgo.Describe("Pod controller interacting with Workload controller whe
ginkgo.By("checking the workload is evicted due to pods ready timeout")
gomega.Eventually(func(g gomega.Gomega) {
g.Expect(k8sClient.Get(ctx, wlKey, wl)).Should(gomega.Succeed())
g.Expect(ptr.Deref(wl.Spec.Active, true)).Should(gomega.BeTrue())
g.Expect(workload.IsActive(wl)).Should(gomega.BeTrue())
g.Expect(wl.Status.RequeueState).ShouldNot(gomega.BeNil())
g.Expect(wl.Status.RequeueState.Count).Should(gomega.Equal(ptr.To[int32](1)))
g.Expect(wl.Status.RequeueState.RequeueAt).Should(gomega.BeNil())
Expand Down Expand Up @@ -1794,7 +1794,7 @@ var _ = ginkgo.Describe("Pod controller interacting with Workload controller whe
ginkgo.By("checking the workload is deactivated and evicted")
gomega.Eventually(func(g gomega.Gomega) {
g.Expect(k8sClient.Get(ctx, wlKey, wl)).Should(gomega.Succeed())
g.Expect(ptr.Deref(wl.Spec.Active, true)).Should(gomega.BeFalse())
g.Expect(workload.IsActive(wl)).Should(gomega.BeFalse())
g.Expect(wl.Status.RequeueState).Should(gomega.BeNil())
g.Expect(wl.Status.Conditions).To(gomega.ContainElements(
gomega.BeComparableTo(metav1.Condition{
Expand Down
5 changes: 3 additions & 2 deletions test/integration/kueuectl/resume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"sigs.k8s.io/kueue/apis/kueue/v1beta1"
"sigs.k8s.io/kueue/cmd/kueuectl/app"
"sigs.k8s.io/kueue/pkg/util/testing"
"sigs.k8s.io/kueue/pkg/workload"
"sigs.k8s.io/kueue/test/util"
)

Expand Down Expand Up @@ -57,7 +58,7 @@ var _ = ginkgo.Describe("Kueuectl Resume", ginkgo.Ordered, ginkgo.ContinueOnFail
ginkgo.By("Get the created Workload", func() {
gomega.Eventually(func(g gomega.Gomega) {
g.Expect(k8sClient.Get(ctx, types.NamespacedName{Name: wl.Name, Namespace: ns.Name}, createdWorkload)).To(gomega.Succeed())
g.Expect(ptr.Deref(wl.Spec.Active, true)).Should(gomega.BeFalse())
g.Expect(workload.IsActive(wl)).Should(gomega.BeFalse())
}, util.Timeout, util.Interval).Should(gomega.Succeed())
})

Expand All @@ -74,7 +75,7 @@ var _ = ginkgo.Describe("Kueuectl Resume", ginkgo.Ordered, ginkgo.ContinueOnFail
ginkgo.By("Check that the Workload successfully resumed", func() {
gomega.Eventually(func(g gomega.Gomega) {
g.Expect(k8sClient.Get(ctx, types.NamespacedName{Name: wl.Name, Namespace: ns.Name}, wl)).To(gomega.Succeed())
g.Expect(ptr.Deref(wl.Spec.Active, true)).Should(gomega.BeTrue())
g.Expect(workload.IsActive(wl)).Should(gomega.BeTrue())
}, util.Timeout, util.Interval).Should(gomega.Succeed())
})
})
Expand Down
5 changes: 3 additions & 2 deletions test/integration/kueuectl/stop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"sigs.k8s.io/kueue/apis/kueue/v1beta1"
"sigs.k8s.io/kueue/cmd/kueuectl/app"
"sigs.k8s.io/kueue/pkg/util/testing"
"sigs.k8s.io/kueue/pkg/workload"
"sigs.k8s.io/kueue/test/util"
)

Expand Down Expand Up @@ -57,7 +58,7 @@ var _ = ginkgo.Describe("Kueuectl Stop", ginkgo.Ordered, ginkgo.ContinueOnFailur
ginkgo.By("Get the created Workload", func() {
gomega.Eventually(func(g gomega.Gomega) {
g.Expect(k8sClient.Get(ctx, types.NamespacedName{Name: wl.Name, Namespace: ns.Name}, createdWorkload)).To(gomega.Succeed())
g.Expect(ptr.Deref(wl.Spec.Active, true)).Should(gomega.BeTrue())
g.Expect(workload.IsActive(wl)).Should(gomega.BeTrue())
}, util.Timeout, util.Interval).Should(gomega.Succeed())
})

Expand All @@ -74,7 +75,7 @@ var _ = ginkgo.Describe("Kueuectl Stop", ginkgo.Ordered, ginkgo.ContinueOnFailur
ginkgo.By("Check that the Workload successfully stopped", func() {
gomega.Eventually(func(g gomega.Gomega) {
g.Expect(k8sClient.Get(ctx, types.NamespacedName{Name: wl.Name, Namespace: ns.Name}, wl)).To(gomega.Succeed())
g.Expect(ptr.Deref(wl.Spec.Active, true)).Should(gomega.BeFalse())
g.Expect(workload.IsActive(wl)).Should(gomega.BeFalse())
}, util.Timeout, util.Interval).Should(gomega.Succeed())
})
})
Expand Down
4 changes: 2 additions & 2 deletions test/integration/scheduler/podsready/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ var _ = ginkgo.Describe("SchedulerWithWaitForPodsReady", func() {
time.Sleep(podsReadyTimeout)
gomega.Eventually(func(g gomega.Gomega) {
g.Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(prodWl), prodWl)).Should(gomega.Succeed())
g.Expect(ptr.Deref(prodWl.Spec.Active, true)).Should(gomega.BeFalse())
g.Expect(workload.IsActive(prodWl)).Should(gomega.BeFalse())
g.Expect(prodWl.Status.RequeueState).Should(gomega.BeNil())
workload.SetRequeuedCondition(prodWl, kueue.WorkloadEvictedByDeactivation, "by test", false)
g.Expect(workload.ApplyAdmissionStatus(ctx, k8sClient, prodWl, true)).Should(gomega.Succeed())
Expand Down Expand Up @@ -686,7 +686,7 @@ var _ = ginkgo.Describe("SchedulerWithWaitForPodsReadyNonblockingMode", func() {
util.ExpectWorkloadToHaveRequeueState(ctx, k8sClient, client.ObjectKeyFromObject(prodWl), &kueue.RequeueState{
Count: ptr.To[int32](2),
}, false)
gomega.Expect(ptr.Deref(prodWl.Spec.Active, true)).Should(gomega.BeTrue())
gomega.Expect(workload.IsActive(prodWl)).Should(gomega.BeTrue())
})
})

Expand Down

0 comments on commit bbcf7c5

Please sign in to comment.