-
Notifications
You must be signed in to change notification settings - Fork 66
feat(evalhub): emit Kubernetes events for operator-detected evaluation failures (RHAI-278) #846
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6c493ae
chore(rbac): add events:create and jobs:patch/get permissions for Eva…
ruivieira 7f96bd3
feat(evalhub): emit events for job infrastructure failures (#844)
ruivieira 42e5771
test(evalhub): add lifecycle unit tests for failure reconciler event …
ruivieira b51adc3
fix(evalhub): prevent duplicate POST and Event on Kueue workload retry
ruivieira 7170627
fix(evalhub): retry Job failure labels after partial Workload commit
ruivieira 87bb77f
fix(evalhub): clean up Job when server already handled failure
ruivieira c3440b1
docs(evalhub): clarify evalhub-events role binding target
ruivieira 9bdbfe3
fix(evalhub): prevent duplicate POST and Event on Job failure retry
ruivieira 656bcc6
Merge branch 'main' into dev/RHAI-278
ruivieira File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
controllers/evalhub/evaluation_failed_kueue_workloads_reconciler_lifecycle_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| /* | ||
| Copyright 2025. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| */ | ||
|
|
||
| package evalhub | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| evalhubv1 "github.com/trustyai-explainability/trustyai-service-operator/api/evalhub/v1" | ||
| batchv1 "k8s.io/api/batch/v1" | ||
| corev1 "k8s.io/api/core/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apimachinery/pkg/runtime" | ||
| "k8s.io/apimachinery/pkg/types" | ||
| "k8s.io/client-go/rest" | ||
| "k8s.io/client-go/tools/record" | ||
| ctrl "sigs.k8s.io/controller-runtime" | ||
| "sigs.k8s.io/controller-runtime/pkg/client" | ||
| "sigs.k8s.io/controller-runtime/pkg/client/fake" | ||
| "sigs.k8s.io/controller-runtime/pkg/client/interceptor" | ||
| kueue "sigs.k8s.io/kueue/apis/kueue/v1beta1" | ||
| ) | ||
|
|
||
| // kueueLifecycleScheme builds the minimal scheme for Kueue failure reconciler lifecycle tests. | ||
| func kueueLifecycleScheme(t *testing.T) *runtime.Scheme { | ||
| t.Helper() | ||
| sc := runtime.NewScheme() | ||
| require.NoError(t, batchv1.AddToScheme(sc)) | ||
| require.NoError(t, corev1.AddToScheme(sc)) | ||
| require.NoError(t, evalhubv1.AddToScheme(sc)) | ||
| require.NoError(t, kueue.AddToScheme(sc)) | ||
| return sc | ||
| } | ||
|
|
||
| // inadmissibleWorkload builds a Kueue Workload with QuotaReserved=False/Inadmissible owned by a Job. | ||
| func inadmissibleWorkload(name, ns, jobName string, jobUID types.UID, condMsg string) *kueue.Workload { | ||
| return &kueue.Workload{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: name, | ||
| Namespace: ns, | ||
| UID: types.UID("wl-uid-" + name), | ||
| OwnerReferences: []metav1.OwnerReference{{ | ||
| APIVersion: "batch/v1", Kind: "Job", Name: jobName, UID: jobUID, | ||
| }}, | ||
| }, | ||
| Spec: kueue.WorkloadSpec{ | ||
| QueueName: "default-queue", | ||
| }, | ||
| Status: kueue.WorkloadStatus{ | ||
| Conditions: []metav1.Condition{{ | ||
| Type: kueue.WorkloadQuotaReserved, | ||
| Status: metav1.ConditionFalse, | ||
| Reason: kueueWorkloadReasonInadmissible, | ||
| Message: condMsg, | ||
| }}, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| // buildKueueReconciler returns a reconciler with a FakeRecorder and the given tenant namespace. | ||
| func buildKueueReconciler(fc client.Client, tenantNamespace string) (*EvalHubEvaluationFailedKueueWorkloadsReconciler, *record.FakeRecorder) { | ||
| rec := record.NewFakeRecorder(10) | ||
| tn := newEvalHubTenantNamespaces() | ||
| tn.Add(tenantNamespace) | ||
| return &EvalHubEvaluationFailedKueueWorkloadsReconciler{ | ||
| Client: fc, | ||
| RESTConfig: &rest.Config{}, | ||
| EventRecorder: rec, | ||
| tenantNS: tn, | ||
| }, rec | ||
| } | ||
|
|
||
| // TestKueueReconciler_Eviction_EmitsEventAndPatchesJobAndWorkload verifies the full lifecycle for a Kueue | ||
| // admission failure: the reconciler POSTs to EvalHub, emits an EvaluationFailed warning event on the Job, | ||
| // stamps evaluation-phase=Failed on the Job, and annotates the Workload as reported. | ||
| func TestKueueReconciler_Eviction_EmitsEventAndPatchesJobAndWorkload(t *testing.T) { | ||
| srv := noopEvalHubServer(t) | ||
| sc := kueueLifecycleScheme(t) | ||
| ns := "tenant-ns" | ||
|
|
||
| job := evalHubEvaluationJob("eval-job-kueue", ns, map[string]string{ | ||
| evalHubInstanceNameLabel: "evalhub-1", | ||
| evalHubInstanceNamespaceLabel: "control-ns", | ||
| }) | ||
| wl := inadmissibleWorkload("wl-1", ns, job.Name, job.UID, "insufficient quota") | ||
| eh := readyEvalHubCR("evalhub-1", "control-ns", srv.URL) | ||
|
|
||
| var patchedJobLabels map[string]string | ||
| var workloadAnnotated bool | ||
|
|
||
| fc := fake.NewClientBuilder(). | ||
| WithScheme(sc). | ||
| WithObjects(eh, job, wl). | ||
| WithInterceptorFuncs(interceptor.Funcs{ | ||
| Patch: func(ctx context.Context, c client.WithWatch, obj client.Object, patch client.Patch, opts ...client.PatchOption) error { | ||
| switch o := obj.(type) { | ||
| case *batchv1.Job: | ||
| if o.Labels[labelEvaluationPhase] == labelEvaluationPhaseFailed { | ||
| patchedJobLabels = o.Labels | ||
| } | ||
| case *kueue.Workload: | ||
| if o.Annotations[annotationKueueFailedWorkloadEventReported] == "true" { | ||
| workloadAnnotated = true | ||
| } | ||
| } | ||
| return c.Patch(ctx, obj, patch, opts...) | ||
| }, | ||
| }). | ||
| Build() | ||
|
|
||
| r, rec := buildKueueReconciler(fc, ns) | ||
|
|
||
| _, err := r.Reconcile(context.Background(), ctrl.Request{ | ||
| NamespacedName: types.NamespacedName{Namespace: ns, Name: wl.Name}, | ||
| }) | ||
| require.NoError(t, err) | ||
|
|
||
| select { | ||
| case ev := <-rec.Events: | ||
| assert.Contains(t, ev, corev1.EventTypeWarning) | ||
| assert.Contains(t, ev, eventReasonEvaluationFailed) | ||
| default: | ||
| t.Fatal("expected EvaluationFailed event but recorder is empty") | ||
| } | ||
|
|
||
| require.NotNil(t, patchedJobLabels, "evaluation-phase=Failed patch was never applied to Job") | ||
| assert.Equal(t, labelEvaluationPhaseFailed, patchedJobLabels[labelEvaluationPhase]) | ||
| assert.True(t, workloadAnnotated, "Workload should be annotated as reported") | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.