Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug when checking if a JobSet is active during tests. #531

Merged
merged 1 commit into from
Apr 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion test/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package util
import (
"context"
"fmt"
"slices"
"time"

"github.com/onsi/ginkgo/v2"
Expand Down Expand Up @@ -119,7 +120,26 @@ func JobSetStartupPolicyNotFinished(ctx context.Context, k8sClient client.Client

func JobSetActive(ctx context.Context, k8sClient client.Client, js *jobset.JobSet, timeout time.Duration) {
ginkgo.By("checking jobset status is active")
gomega.Consistently(checkJobSetStatus, timeout, interval).WithArguments(ctx, k8sClient, js, []metav1.Condition{}).Should(gomega.Equal(true))
gomega.Consistently(checkJobSetActive, timeout, interval).WithArguments(ctx, k8sClient, js).Should(gomega.Equal(true))
}

// checkJobSetActive performs a check if the JobSet is active.
// A JobSet is not active when any of the conditions JobSetFailed, JobSetComplete, or JobSetSuspended are true.
// A JobSet is otherwise considered active.
func checkJobSetActive(ctx context.Context, k8sClient client.Client, js *jobset.JobSet) (bool, error) {
var fetchedJS jobset.JobSet
if err := k8sClient.Get(ctx, types.NamespacedName{Namespace: js.Namespace, Name: js.Name}, &fetchedJS); err != nil {
return false, err
}

forbiddenTypes := []string{string(jobset.JobSetFailed), string(jobset.JobSetCompleted), string(jobset.JobSetSuspended)}

for _, c := range fetchedJS.Status.Conditions {
if slices.Contains(forbiddenTypes, c.Type) && c.Status == metav1.ConditionTrue {
return false, nil
}
}
return true, nil
}

func checkJobSetStatus(ctx context.Context, k8sClient client.Client, js *jobset.JobSet, conditions []metav1.Condition) (bool, error) {
Expand Down