diff --git a/pkg/cincinnati/cincinnati.go b/pkg/cincinnati/cincinnati.go index cd6b282b19..d25e33c35a 100644 --- a/pkg/cincinnati/cincinnati.go +++ b/pkg/cincinnati/cincinnati.go @@ -1,6 +1,7 @@ package cincinnati import ( + "context" "encoding/json" "fmt" "io/ioutil" @@ -38,7 +39,7 @@ type Update node // finding all of the children. These children are the available updates for // the current version and their payloads indicate from where the actual update // image can be downloaded. -func (c Client) GetUpdates(upstream string, channel string, version semver.Version) ([]Update, error) { +func (c Client) GetUpdates(ctx context.Context, upstream string, channel string, version semver.Version) ([]Update, error) { // Prepare parametrized cincinnati query. cincinnatiURL, err := url.Parse(upstream) if err != nil { @@ -58,7 +59,7 @@ func (c Client) GetUpdates(upstream string, channel string, version semver.Versi req.Header.Add("Accept", GraphMediaType) client := http.Client{} - resp, err := client.Do(req) + resp, err := client.Do(req.WithContext(ctx)) if err != nil { return nil, err } diff --git a/pkg/cincinnati/cincinnati_test.go b/pkg/cincinnati/cincinnati_test.go index e07f559085..96653b4179 100644 --- a/pkg/cincinnati/cincinnati_test.go +++ b/pkg/cincinnati/cincinnati_test.go @@ -1,6 +1,7 @@ package cincinnati import ( + "context" "encoding/json" "fmt" "net/http" @@ -123,7 +124,7 @@ func TestGetUpdates(t *testing.T) { c := NewClient(clientID) - updates, err := c.GetUpdates(ts.URL, channelName, semver.MustParse(test.version)) + updates, err := c.GetUpdates(context.TODO(), ts.URL, channelName, semver.MustParse(test.version)) if test.err == "" { if err != nil { t.Fatalf("expected nil error, got: %v", err) diff --git a/pkg/cvo/availableupdates.go b/pkg/cvo/availableupdates.go index bfe9165b74..1eb4b8433d 100644 --- a/pkg/cvo/availableupdates.go +++ b/pkg/cvo/availableupdates.go @@ -1,6 +1,7 @@ package cvo import ( + "context" "fmt" "time" @@ -20,7 +21,7 @@ import ( // syncAvailableUpdates attempts to retrieve the latest updates and update the status of the ClusterVersion // object. It will set the RetrievedUpdates condition. Updates are only checked if it has been more than // the minimumUpdateCheckInterval since the last check. -func (optr *Operator) syncAvailableUpdates(config *configv1.ClusterVersion) error { +func (optr *Operator) syncAvailableUpdates(ctx context.Context, config *configv1.ClusterVersion) error { usedDefaultUpstream := false upstream := string(config.Spec.Upstream) if len(upstream) == 0 { @@ -36,7 +37,7 @@ func (optr *Operator) syncAvailableUpdates(config *configv1.ClusterVersion) erro return nil } - updates, condition := calculateAvailableUpdatesStatus(string(config.Spec.ClusterID), upstream, channel, optr.releaseVersion) + updates, condition := calculateAvailableUpdatesStatus(ctx, string(config.Spec.ClusterID), upstream, channel, optr.releaseVersion) if usedDefaultUpstream { upstream = "" @@ -103,7 +104,7 @@ func (optr *Operator) getAvailableUpdates() *availableUpdates { return optr.availableUpdates } -func calculateAvailableUpdatesStatus(clusterID, upstream, channel, version string) ([]configv1.Update, configv1.ClusterOperatorStatusCondition) { +func calculateAvailableUpdatesStatus(ctx context.Context, clusterID, upstream, channel, version string) ([]configv1.Update, configv1.ClusterOperatorStatusCondition) { if len(upstream) == 0 { return nil, configv1.ClusterOperatorStatusCondition{ Type: configv1.RetrievedUpdates, Status: configv1.ConditionFalse, Reason: "NoUpstream", @@ -127,7 +128,7 @@ func calculateAvailableUpdatesStatus(clusterID, upstream, channel, version strin } } - updates, err := checkForUpdate(clusterID, upstream, channel, currentVersion) + updates, err := checkForUpdate(ctx, clusterID, upstream, channel, currentVersion) if err != nil { glog.V(2).Infof("Upstream server %s could not return available updates: %v", upstream, err) return nil, configv1.ClusterOperatorStatusCondition{ @@ -152,7 +153,7 @@ func calculateAvailableUpdatesStatus(clusterID, upstream, channel, version strin } } -func checkForUpdate(clusterID, upstream, channel string, currentVersion semver.Version) ([]cincinnati.Update, error) { +func checkForUpdate(ctx context.Context, clusterID, upstream, channel string, currentVersion semver.Version) ([]cincinnati.Update, error) { uuid, err := uuid.Parse(string(clusterID)) if err != nil { return nil, err @@ -160,5 +161,5 @@ func checkForUpdate(clusterID, upstream, channel string, currentVersion semver.V if len(upstream) == 0 { return nil, fmt.Errorf("no upstream URL set for cluster version") } - return cincinnati.NewClient(uuid).GetUpdates(upstream, channel, currentVersion) + return cincinnati.NewClient(uuid).GetUpdates(ctx, upstream, channel, currentVersion) } diff --git a/pkg/cvo/cvo.go b/pkg/cvo/cvo.go index d51b3bdb2b..64d3bbb6bc 100644 --- a/pkg/cvo/cvo.go +++ b/pkg/cvo/cvo.go @@ -1,6 +1,7 @@ package cvo import ( + "context" "fmt" "strconv" "sync" @@ -361,8 +362,8 @@ func (optr *Operator) availableUpdatesSync(key string) error { if errs := validation.ValidateClusterVersion(config); len(errs) > 0 { return nil } - - return optr.syncAvailableUpdates(config) + ctx := context.TODO() + return optr.syncAvailableUpdates(ctx, config) } // isOlderThanLastUpdate returns true if the cluster version is older than