Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions pkg/cvo/cvo.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ type Operator struct {
upgradeable *upgradeable
upgradeableChecks []upgradeableCheck

// minimumUpgradeableCheckInterval is the minimum duration before another
// synchronization of the upgradeable status can happen during failing
// precondition checks.
minimumUpgradeableCheckInterval time.Duration

// verifier, if provided, will be used to check an update before it is executed.
// Any error will prevent an update payload from being accessed.
verifier verify.Interface
Expand Down Expand Up @@ -179,10 +184,11 @@ func New(
Image: releaseImage,
},

statusInterval: 15 * time.Second,
minimumUpdateCheckInterval: minimumInterval,
payloadDir: overridePayloadDir,
defaultUpstreamServer: "https://api.openshift.com/api/upgrades_info/v1/graph",
statusInterval: 15 * time.Second,
minimumUpdateCheckInterval: minimumInterval,
minimumUpgradeableCheckInterval: 15 * time.Second,
payloadDir: overridePayloadDir,
defaultUpstreamServer: "https://api.openshift.com/api/upgrades_info/v1/graph",

client: client,
kubeClient: kubeClient,
Expand Down Expand Up @@ -627,7 +633,7 @@ func (optr *Operator) upgradeableSync(ctx context.Context, key string) error {
return nil
}

return optr.syncUpgradeable()
return optr.syncUpgradeable(config)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CVO using the in-cluster ClusterVersion to pass state from one goroutine to another feels sticky... I'm not set against it, but it would be nice if we could find a way to plumb the data we need through without having to pass this thing we just got from the cluster here. syncUpgradeable is already an Operator method, so it should have access to a lot of state already...

Copy link
Member

@LalatenduMohanty LalatenduMohanty Aug 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had seen this, but somehow did not spend time figuring out if we can avoid this.

Copy link
Contributor Author

@DavidHurta DavidHurta Aug 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I wasn't keen on it either. However, the syncAvailableUpdates() in pkg/cvo/availableupdates.go uses the cluster version as a parameter also (https://github.com/openshift/cluster-version-operator/blob/master/pkg/cvo/availableupdates.go#L31), so I ended up using here as well. (Now I see the commit db150e6 for that change was from 4 years ago).

Another alternative I can think of is calling the

config, err := optr.cvLister.Get(optr.name)

in syncUpgradeable() but I'll try to think of a better idea.

Copy link
Member

@LalatenduMohanty LalatenduMohanty Aug 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think it is a bad idea to pass config in optr.syncUpgradeable(config) because upgradeableSync() is aleady in a go-routine and it is calling the optr.cvLister.Get(optr.name) . So I do not think there is much difference between upgradeableSync() or SyncUpgradeable() calling optr.cvLister.Get(optr.name)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I don't think it matters if we shift the Get around. What I'd like long-term is no get at all in this pathway. Looking here, here, and here, something like optr.getUpgradeable().Conditions will get you the current conditions without having to leave local CVO memory. Although a lock guarding access to a pointer property seems a bit suspect...

}

// isOlderThanLastUpdate returns true if the cluster version is older than
Expand Down
38 changes: 32 additions & 6 deletions pkg/cvo/upgradeable.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ const (

var adminAckGateRegexp = regexp.MustCompile(adminAckGateFmt)

// syncUpgradeable. The status is only checked if it has been more than
// the minimumUpdateCheckInterval since the last check.
func (optr *Operator) syncUpgradeable() error {
// updates are only checked at most once per minimumUpdateCheckInterval or if the generation changes
// syncUpgradeable synchronizes the upgradeable status only if it has been more than
// the minimumUpdateCheckInterval since the last synchronization or the precondition
// checks on the payload are failing for less than minimumUpdateCheckInterval, and it has
// been more than the minimumUpgradeableCheckInterval since the last synchronization.
func (optr *Operator) syncUpgradeable(config *configv1.ClusterVersion) error {
u := optr.getUpgradeable()
if u != nil && u.RecentlyChanged(optr.minimumUpdateCheckInterval) {
if u != nil && u.RecentlyChanged(optr.minimumUpdateCheckInterval) && !shouldSyncUpgradeableDueToPreconditionChecks(optr, config, u) {
klog.V(2).Infof("Upgradeable conditions were recently checked, will try later.")
return nil
}
Expand Down Expand Up @@ -92,8 +93,14 @@ type upgradeable struct {
Conditions []configv1.ClusterOperatorStatusCondition
}

// hasPassedDurationSinceTime checks if a certain amount of time specified by duration
// has passed since time. Returns true if the duration has passed, returns false otherwise.
func hasPassedDurationSinceTime(t time.Time, duration time.Duration) bool {
return time.Now().After(t.Add(duration))
}

func (u *upgradeable) RecentlyChanged(interval time.Duration) bool {
return u.At.After(time.Now().Add(-interval))
return !hasPassedDurationSinceTime(u.At, interval)
}

func (u *upgradeable) NeedsUpdate(original *configv1.ClusterVersion) *configv1.ClusterVersion {
Expand Down Expand Up @@ -442,3 +449,22 @@ func (optr *Operator) adminGatesEventHandler() cache.ResourceEventHandler {
DeleteFunc: optr.deleteFunc,
}
}

// shouldSyncUpgradeableDueToPreconditionChecks checks if the upgradeable status should
// be synchronized due to the precondition checks. It checks whether the precondition
// checks on the payload are failing for less than minimumUpdateCheckInterval, and it has
// been more than the minimumUpgradeableCheckInterval since the last synchronization.
// This means, upon precondition failure, we will synchronize the upgradeable status
// more frequently at beginning of an upgrade.
//
// shouldSyncUpgradeableDueToPreconditionChecks expects the parameters not to be nil.
//
// Function returns true if the synchronization should happen, returns false otherwise.
func shouldSyncUpgradeableDueToPreconditionChecks(optr *Operator, config *configv1.ClusterVersion, u *upgradeable) bool {
cond := resourcemerge.FindOperatorStatusCondition(config.Status.Conditions, DesiredReleaseAccepted)
if cond != nil && cond.Reason == "PreconditionChecks" && cond.Status == configv1.ConditionFalse &&
hasPassedDurationSinceTime(u.At, optr.minimumUpgradeableCheckInterval) && !hasPassedDurationSinceTime(cond.LastTransitionTime.Time, optr.minimumUpdateCheckInterval) {
return true
}
return false
}