Skip to content

Commit

Permalink
fix: Avoid failure on unchanged provider version
Browse files Browse the repository at this point in the history
In the current implementation, when a provider version remains the same
during subsequent reconciliations, the operator encounters an error with
the message "failed getting clusterctl Provider version," leading to a
degraded status.

This PR addresses this issue by adding a check to determine whether
the provider version has changed or not.
  • Loading branch information
Fedosin committed May 8, 2023
1 parent b2e6b7a commit 3f6d6e1
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions internal/controllers/phases.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,18 +334,23 @@ func (p *phaseReconciler) fetch(ctx context.Context) (reconcile.Result, error) {
func (p *phaseReconciler) preInstall(ctx context.Context) (reconcile.Result, error) {
log := ctrl.LoggerFrom(ctx)

needPreDelete, err := p.updateRequiresPreDeletion()
if err != nil || !needPreDelete {
return reconcile.Result{}, wrapPhaseError(err, "failed getting clusterctl Provider", operatorv1.ProviderInstalledCondition)
needPreDelete, err := p.versionChanged()
if err != nil {
return reconcile.Result{}, wrapPhaseError(err, "failed getting clusterctl Provider version", operatorv1.ProviderInstalledCondition)
}

// we need to delete existing components only if their version changes.
if !needPreDelete {
return reconcile.Result{}, nil
}

log.Info("Upgrade detected, deleting existing components")

return p.delete(ctx)
}

// updateRequiresPreDeletion try to get installed version from provider status and decide if it's an upgrade.
func (s *phaseReconciler) updateRequiresPreDeletion() (bool, error) {
// versionChanged try to get installed version from provider status and decide if it has changed.
func (s *phaseReconciler) versionChanged() (bool, error) {
installedVersion := s.provider.GetStatus().InstalledVersion
if installedVersion == nil {
return false, nil
Expand All @@ -368,6 +373,16 @@ func (s *phaseReconciler) updateRequiresPreDeletion() (bool, error) {
func (p *phaseReconciler) install(ctx context.Context) (reconcile.Result, error) {
log := ctrl.LoggerFrom(ctx)

versionChanged, err := p.versionChanged()
if err != nil {
return reconcile.Result{}, wrapPhaseError(err, "failed getting clusterctl Provider version", operatorv1.ProviderInstalledCondition)
}

// skip installation if the version hasn't changed.
if !versionChanged {
return reconcile.Result{}, nil
}

clusterClient := p.newClusterClient()

log.Info("Installing provider")
Expand Down

0 comments on commit 3f6d6e1

Please sign in to comment.