@@ -625,8 +625,8 @@ func (w *SyncWorker) apply(ctx context.Context, payloadUpdate *payload.Update, w
625
625
if precreateObjects {
626
626
payload .RunGraph (ctx , graph , 8 , func (ctx context.Context , tasks []* payload.Task ) error {
627
627
for _ , task := range tasks {
628
- if contextIsCancelled ( ctx ) {
629
- return cr .CancelError ( )
628
+ if err := ctx . Err (); err != nil {
629
+ return cr .ContextError ( err )
630
630
}
631
631
if task .Manifest .GVK != configv1 .SchemeGroupVersion .WithKind ("ClusterOperator" ) {
632
632
continue
@@ -644,8 +644,8 @@ func (w *SyncWorker) apply(ctx context.Context, payloadUpdate *payload.Update, w
644
644
// update each object
645
645
errs := payload .RunGraph (ctx , graph , maxWorkers , func (ctx context.Context , tasks []* payload.Task ) error {
646
646
for _ , task := range tasks {
647
- if contextIsCancelled ( ctx ) {
648
- return cr .CancelError ( )
647
+ if err := ctx . Err (); err != nil {
648
+ return cr .ContextError ( err )
649
649
}
650
650
cr .Update ()
651
651
@@ -667,8 +667,10 @@ func (w *SyncWorker) apply(ctx context.Context, payloadUpdate *payload.Update, w
667
667
return nil
668
668
})
669
669
if len (errs ) > 0 {
670
- err := cr .Errors (errs )
671
- return err
670
+ if err := cr .Errors (errs ); err != nil {
671
+ return err
672
+ }
673
+ return errs [0 ]
672
674
}
673
675
674
676
// update the status
@@ -689,11 +691,11 @@ func init() {
689
691
)
690
692
}
691
693
692
- type errCanceled struct {
694
+ type errContext struct {
693
695
err error
694
696
}
695
697
696
- func (e errCanceled ) Error () string { return e .err .Error () }
698
+ func (e errContext ) Error () string { return e .err .Error () }
697
699
698
700
// consistentReporter hides the details of calculating the status based on the progress
699
701
// of the graph runner.
@@ -730,7 +732,7 @@ func (r *consistentReporter) Error(err error) {
730
732
copied := r .status
731
733
copied .Step = "ApplyResources"
732
734
copied .Fraction = float32 (r .done ) / float32 (r .total )
733
- if ! isCancelledError (err ) {
735
+ if ! isContextError (err ) {
734
736
copied .Failure = err
735
737
}
736
738
r .reporter .Report (copied )
@@ -751,10 +753,10 @@ func (r *consistentReporter) Errors(errs []error) error {
751
753
return err
752
754
}
753
755
754
- func (r * consistentReporter ) CancelError ( ) error {
756
+ func (r * consistentReporter ) ContextError ( err error ) error {
755
757
r .lock .Lock ()
756
758
defer r .lock .Unlock ()
757
- return errCanceled {fmt .Errorf ("update was cancelled at %d of %d" , r .done , r .total )}
759
+ return errContext {fmt .Errorf ("update %s at %d of %d" , err , r .done , r .total )}
758
760
}
759
761
760
762
func (r * consistentReporter ) Complete () {
@@ -770,11 +772,11 @@ func (r *consistentReporter) Complete() {
770
772
r .reporter .Report (copied )
771
773
}
772
774
773
- func isCancelledError (err error ) bool {
775
+ func isContextError (err error ) bool {
774
776
if err == nil {
775
777
return false
776
778
}
777
- _ , ok := err .(errCanceled )
779
+ _ , ok := err .(errContext )
778
780
return ok
779
781
}
780
782
@@ -795,11 +797,12 @@ func isImageVerificationError(err error) bool {
795
797
// not truly an error (cancellation).
796
798
// TODO: take into account install vs upgrade
797
799
func summarizeTaskGraphErrors (errs []error ) error {
798
- // we ignore cancellation errors since they don't provide good feedback to users and are an internal
799
- // detail of the server
800
- err := errors .FilterOut (errors .NewAggregate (errs ), isCancelledError )
800
+ // we ignore context errors (canceled or timed out) since they don't
801
+ // provide good feedback to users and are an internal detail of the
802
+ // server
803
+ err := errors .FilterOut (errors .NewAggregate (errs ), isContextError )
801
804
if err == nil {
802
- klog .V (4 ).Infof ("All errors were cancellation errors: %v" , errs )
805
+ klog .V (4 ).Infof ("All errors were context errors: %v" , errs )
803
806
return nil
804
807
}
805
808
agg , ok := err .(errors.Aggregate )
@@ -966,16 +969,6 @@ func ownerRefModifier(config *configv1.ClusterVersion) resourcebuilder.MetaV1Obj
966
969
}
967
970
}
968
971
969
- // contextIsCancelled returns true if the provided context is cancelled.
970
- func contextIsCancelled (ctx context.Context ) bool {
971
- select {
972
- case <- ctx .Done ():
973
- return true
974
- default :
975
- return false
976
- }
977
- }
978
-
979
972
// runThrottledStatusNotifier invokes fn every time ch is updated, but no more often than once
980
973
// every interval. If bucket is non-zero then the channel is throttled like a rate limiter bucket.
981
974
func runThrottledStatusNotifier (stopCh <- chan struct {}, interval time.Duration , bucket int , ch <- chan SyncWorkerStatus , fn func ()) {
0 commit comments