Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new controller for restricting upgrade of operator #60

Closed
wants to merge 1 commit into from

Conversation

leelavg
Copy link
Contributor

@leelavg leelavg commented Jan 10, 2024

As part of heartbeat response provider sends desired version that it wants client operator to match and this PR introduces a new (upgrade) controller to stop upgrades if the current version is ahead of desired version.

Copy link

openshift-ci bot commented Jan 10, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: leelavg

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@leelavg leelavg force-pushed the stop-client-upgrade branch from 8736511 to 1edf4ea Compare January 10, 2024 07:41
@leelavg
Copy link
Contributor Author

leelavg commented Jan 10, 2024

Depends on red-hat-storage/ocs-operator#2329

@leelavg leelavg force-pushed the stop-client-upgrade branch from 1edf4ea to 348cc6a Compare January 10, 2024 09:49
return reconcile.Result{}, fmt.Errorf("unable to find csv with prefix %q", csvPrefix)
csv, err := utils.GetCSVByPrefix(s.ctx, s.Client, "ocs-client-operator", s.OperatorNamespace)
if err != nil {
s.Log.Error(err, "failed to get clusterserviceverison of ocs client operator")
Copy link
Contributor

Choose a reason for hiding this comment

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

Please log in the original error

// and custom channels also might exist, either get this data as part of a configmap
// or cut the name by '-'
subscriptionChannelNamePrefix = "stable-"
controllerName = "upgrade"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
controllerName = "upgrade"
controllerName = "upgrade-controller"

subscriptionChannelNamePrefix = "stable-"
controllerName = "upgrade"
upgradeConditionReason = "ConstraintsSatisfied"
dummyPatchVersion = ".99"
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see a need for an arbitrary value that can be different in any call site without any impact

log logr.Logger

Scheme *runtime.Scheme
OperatorCondition conditions.Condition
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this specifically the upgrade condition? If so, I prefer that the context will be in the name.
Also, this entire code is inside the operator, so no need to specify the obvious

Suggested change
OperatorCondition conditions.Condition
UpgradeCondition conditions.Condition


Scheme *runtime.Scheme
OperatorCondition conditions.Condition
OperatorNamespace string
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
OperatorNamespace string
Namespace string

if err != nil {
r.log.Error(err, "an error occurred during reconcilePhases")
}
r.log.Info("reconciling completed")
Copy link
Contributor

Choose a reason for hiding this comment

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

Reconciliation is not completed in the case of an error

}

// returns current version of the operator based on the subscription
func (r *UpgradeReconciler) getCurrentOperatorVersion() (*semver.Version, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This method returns the version from the subscription! it is not the operator version. The operator version is specified in the current CSV. Also, subscriptions do not specify versions they specify channels, we should not build logic based on channel naming conventions.

}

// returns desired version of the operator based on storageclients
func (r *UpgradeReconciler) getDesiredOperatorVersion() (*semver.Version, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
func (r *UpgradeReconciler) getDesiredOperatorVersion() (*semver.Version, error) {
func (r *UpgradeReconciler) getLowestDesiredOperatorVersion() (*semver.Version, error) {

Comment on lines +211 to +215
oldest, err := semver.Make(storageClientList.Items[0].Status.DesiredOperatorVersion + dummyPatchVersion)
if err != nil {
return nil, err
}
Copy link
Contributor

Choose a reason for hiding this comment

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

You will run on this item again in the for loop. The usual way to solve this is to have a hard-coded value here which is the highest or a special value with special meaning. Personally, I would use the hard coded value approach.

Suggested change
oldest, err := semver.Make(storageClientList.Items[0].Status.DesiredOperatorVersion + dummyPatchVersion)
if err != nil {
return nil, err
}
oldest, err := semver.Make("999.999.999")
if err != nil {
panic(err)
}

@@ -60,3 +67,30 @@ func ValidateStausReporterImage() error {

return nil
}

// return csv matching the prefix or else error
func GetCSVByPrefix(ctx context.Context, c client.Client, prefix, namespace string) (*opv1a1.ClusterServiceVersion, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
func GetCSVByPrefix(ctx context.Context, c client.Client, prefix, namespace string) (*opv1a1.ClusterServiceVersion, error) {
func GetNonPendingCSVByPrefix(ctx context.Context, c client.Client, prefix, namespace string) (*opv1a1.ClusterServiceVersion, error) {

@leelavg
Copy link
Contributor Author

leelavg commented Jan 11, 2024

/hold

@leelavg
Copy link
Contributor Author

leelavg commented Feb 6, 2024

not be revived

@leelavg leelavg closed this Feb 6, 2024
@leelavg leelavg deleted the stop-client-upgrade branch March 8, 2024 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants