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

Record an event and set status message when creation of provisioning request fails #3056

Merged
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion pkg/controller/admissionchecks/provisioning/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ func (c *Controller) syncOwnedProvisionRequest(ctx context.Context, wl *kueue.Wo
if !c.reqIsNeeded(wl, prc) {
continue
}
if ac := workload.FindAdmissionCheck(wl.Status.AdmissionChecks, checkName); ac != nil && ac.State == kueue.CheckStateReady {
ac := workload.FindAdmissionCheck(wl.Status.AdmissionChecks, checkName)
if ac != nil && ac.State == kueue.CheckStateReady {
log.V(2).Info("Skip syncing of the ProvReq for admission check which is Ready", "workload", klog.KObj(wl), "admissionCheck", checkName)
continue
}
Expand Down Expand Up @@ -302,6 +303,10 @@ func (c *Controller) syncOwnedProvisionRequest(ctx context.Context, wl *kueue.Wo
}

if err := c.client.Create(ctx, req); err != nil {
ac.Message = fmt.Sprintf("Error creating ProvisioningRequest %q: %v", requestName, err)
Copy link
Contributor

@mimowo mimowo Oct 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@IrvingMg it just occurred to me - could you please follow up to use the TruncateConditionMessage, and TruncateEventMessage helpers to make sure the message is not too long?

It shouldn't be a problem in most cases, but since the message may come from custom webhooks it may be arbitrarily long.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

workload.SetAdmissionCheckState(&wl.Status.AdmissionChecks, *ac)

c.record.Eventf(wl, corev1.EventTypeWarning, "FailedCreate", ac.Message)
return nil, err
}
c.record.Eventf(wl, corev1.EventTypeNormal, "ProvisioningRequestCreated", "Created ProvisioningRequest: %q", req.Name)
Expand Down
37 changes: 36 additions & 1 deletion pkg/controller/admissionchecks/provisioning/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package provisioning

import (
"context"
"errors"
"testing"
"time"

Expand All @@ -40,6 +42,8 @@ import (
"sigs.k8s.io/kueue/pkg/workload"
)

var errInvalidProvisioningRequest = errors.New("invalid ProvisioningRequest error")

var (
wlCmpOptions = []cmp.Option{
cmpopts.EquateEmpty(),
Expand Down Expand Up @@ -1171,13 +1175,44 @@ func TestReconcile(t *testing.T) {
Obj(),
},
},
"when invalid provisioning request": {
workload: utiltesting.MakeWorkload("wl", TestNamespace).
Annotations(map[string]string{
"provreq.kueue.x-k8s.io/ValidUntilSeconds": "0",
"invalid-provreq-prefix/Foo1": "Bar1",
"another-invalid-provreq-prefix/Foo2": "Bar2"}).
AdmissionChecks(kueue.AdmissionCheckState{
Name: "check1",
State: kueue.CheckStatePending}).
ReserveQuota(utiltesting.MakeAdmission("q1").Obj()).
Obj(),
checks: []kueue.AdmissionCheck{*baseCheck.DeepCopy()},
configs: []kueue.ProvisioningRequestConfig{{ObjectMeta: metav1.ObjectMeta{Name: "config1"}}},
wantReconcileError: errInvalidProvisioningRequest,
wantEvents: []utiltesting.EventRecord{
{
Key: client.ObjectKeyFromObject(baseWorkload),
EventType: corev1.EventTypeWarning,
Reason: "FailedCreate",
Message: `Error creating ProvisioningRequest "wl-check1-1": invalid ProvisioningRequest error`,
},
},
},
}

for name, tc := range cases {
t.Run(name, func(t *testing.T) {
builder, ctx := getClientBuilder()
builder = builder.WithInterceptorFuncs(interceptor.Funcs{SubResourcePatch: utiltesting.TreatSSAAsStrategicMerge})

if tc.wantReconcileError != nil {
builder = builder.WithInterceptorFuncs(
interceptor.Funcs{
Create: func(ctx context.Context, client client.WithWatch, obj client.Object, opts ...client.CreateOption) error {
return tc.wantReconcileError
}})
}

builder = builder.WithObjects(tc.workload)
builder = builder.WithStatusSubresource(tc.workload)

Expand Down Expand Up @@ -1207,7 +1242,7 @@ func TestReconcile(t *testing.T) {
},
}
_, gotReconcileError := controller.Reconcile(ctx, req)
if diff := cmp.Diff(tc.wantReconcileError, gotReconcileError); diff != "" {
if diff := cmp.Diff(tc.wantReconcileError, gotReconcileError, cmpopts.EquateErrors()); diff != "" {
t.Errorf("unexpected reconcile error (-want/+got):\n%s", diff)
}

Expand Down