From 4cd1315700d9a15831da055ea30bead3f0aed1de Mon Sep 17 00:00:00 2001 From: Mariell Hoversholm Date: Thu, 27 Mar 2025 15:11:07 +0100 Subject: [PATCH] App Platform(Provisioning): Listen to context cancel ASAP (#102957) We should not write after the context is cancelled. This causes tests to fail as they are trying to clean up. To try to accommodate this, we'll need to listen to the context in any loop where we don't immediately get other instructions from e.g. trying to do an HTTP request. --- pkg/registry/apis/provisioning/jobs/export/resources.go | 8 ++++++-- pkg/registry/apis/provisioning/jobs/sync/worker.go | 6 ++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/pkg/registry/apis/provisioning/jobs/export/resources.go b/pkg/registry/apis/provisioning/jobs/export/resources.go index 2cfbf138e11..6a42a6593ff 100644 --- a/pkg/registry/apis/provisioning/jobs/export/resources.go +++ b/pkg/registry/apis/provisioning/jobs/export/resources.go @@ -41,13 +41,17 @@ func (r *exportJob) loadResourcesFromAPIServer(ctx context.Context, kind schema. } var continueToken string - for { + for ctx.Err() == nil { list, err := client.List(ctx, metav1.ListOptions{Limit: 100, Continue: continueToken}) if err != nil { return fmt.Errorf("error executing list: %w", err) } for _, item := range list.Items { + if ctx.Err() != nil { + return ctx.Err() + } + r.progress.Record(ctx, r.write(ctx, &item)) if err := r.progress.TooManyErrors(); err != nil { return err @@ -60,7 +64,7 @@ func (r *exportJob) loadResourcesFromAPIServer(ctx context.Context, kind schema. } } - return nil + return ctx.Err() } func (r *exportJob) write(ctx context.Context, obj *unstructured.Unstructured) jobs.JobResourceResult { diff --git a/pkg/registry/apis/provisioning/jobs/sync/worker.go b/pkg/registry/apis/provisioning/jobs/sync/worker.go index ebeacbe2e29..1778766d032 100644 --- a/pkg/registry/apis/provisioning/jobs/sync/worker.go +++ b/pkg/registry/apis/provisioning/jobs/sync/worker.go @@ -258,6 +258,9 @@ func (r *syncJob) applyChanges(ctx context.Context, changes []ResourceFileChange r.progress.SetMessage(ctx, "replicating changes") for _, change := range changes { + if ctx.Err() != nil { + return ctx.Err() + } if err := r.progress.TooManyErrors(); err != nil { return err } @@ -341,6 +344,9 @@ func (r *syncJob) applyVersionedChanges(ctx context.Context, repo repository.Ver r.progress.SetMessage(ctx, "replicating versioned changes") for _, change := range diff { + if ctx.Err() != nil { + return ctx.Err() + } if err := r.progress.TooManyErrors(); err != nil { return err }