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.
pull/101869/head^2
Mariell Hoversholm 2 months ago committed by GitHub
parent 1a87f8e5bf
commit 4cd1315700
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 8
      pkg/registry/apis/provisioning/jobs/export/resources.go
  2. 6
      pkg/registry/apis/provisioning/jobs/sync/worker.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 {

@ -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
}

Loading…
Cancel
Save