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.
This commit is contained in:
1 parent
1a87f8e5bf
commit
4cd1315700
2 files changed
+12
-2
No files matched your search
@@ -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
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user