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

Downgrade support #575

Closed
wants to merge 15 commits into from
33 changes: 17 additions & 16 deletions controllers/csm_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,7 @@ func (r *ContainerStorageModuleReconciler) PreChecks(ctx context.Context, cr *cs
return fmt.Errorf("unsupported driver type %s", cr.Spec.Driver.CSIDriverType)
}

upgradeValid, err := checkUpgrade(ctx, cr, operatorConfig)
upgradeValid, err := r.checkUpgrade(ctx, cr, operatorConfig)
if err != nil {
return fmt.Errorf("failed upgrade check: %v", err)
} else if !upgradeValid {
Expand Down Expand Up @@ -1357,7 +1357,7 @@ func (r *ContainerStorageModuleReconciler) PreChecks(ctx context.Context, cr *cs
}

// Check for upgrade/if upgrade is appropriate
func checkUpgrade(ctx context.Context, cr *csmv1.ContainerStorageModule, operatorConfig utils.OperatorConfig) (bool, error) {
func (r *ContainerStorageModuleReconciler) checkUpgrade(ctx context.Context, cr *csmv1.ContainerStorageModule, operatorConfig utils.OperatorConfig) (bool, error) {
log := logger.GetLogger(ctx)

// If it is an upgrade/downgrade, check to see if we meet the minimum version using GetUpgradeInfo, which returns the minimum version required
Expand All @@ -1378,38 +1378,39 @@ func checkUpgrade(ctx context.Context, cr *csmv1.ContainerStorageModule, operato
}
newVersion := cr.Spec.Driver.ConfigVersion
return utils.IsValidUpgrade(ctx, oldVersion, newVersion, driverType, operatorConfig)

}
log.Infow("proceeding with fresh driver install")
return true, nil
}

// TODO: refactor this
// applyConfigVersionAnnotations - applies the config version annotation to the instance.
func applyConfigVersionAnnotations(ctx context.Context, instance *csmv1.ContainerStorageModule) bool {
log := logger.GetLogger(ctx)

// If driver/module has not been initialized yet, we first annotate the component with the config version annotation

annotations := instance.GetAnnotations()
isUpdated := false
if annotations == nil {
annotations = make(map[string]string)
}

annotations[CSMVersionKey] = CSMVersion

if _, ok := annotations[configVersionKey]; !ok {
configVersion := ""
if instance.HasModule(csmv1.AuthorizationServer) {
configVersion = instance.GetModule(csmv1.AuthorizationServer).ConfigVersion
} else {
configVersion = instance.Spec.Driver.ConfigVersion
}
var configVersion string
if instance.HasModule(csmv1.AuthorizationServer) {
configVersion = instance.GetModule(csmv1.AuthorizationServer).ConfigVersion
} else {
configVersion = instance.Spec.Driver.ConfigVersion
}

if annotations[configVersionKey] != configVersion {
annotations[configVersionKey] = configVersion
isUpdated = true
log.Infof("Installing csm component %s with config Version %s. Updating Annotations with Config Version",
instance.GetName(), configVersion)
instance.SetAnnotations(annotations)
return true
}
instance.SetAnnotations(annotations)
return isUpdated

return false
}

// GetClient - returns the split client
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@

minUpgradePath: v2.9.1
minUpgradePath: v2.8.0
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@

minUpgradePath: v2.7.0
minUpgradePath: v2.6.0
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@

minUpgradePath: v2.8.0
minUpgradePath: v2.7.0
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@

minUpgradePath: v2.8.0
minUpgradePath: v2.7.0
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@

minUpgradePath: v2.8.0
minUpgradePath: v2.7.0
43 changes: 31 additions & 12 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -863,18 +863,20 @@ func versionParser(version string) (int, int, error) {

// MinVersionCheck takes a driver name and a version of the form "vA.B.C" and checks it against the minimum version for the specified driver
func MinVersionCheck(minVersion string, version string) (bool, error) {
minVersionA, minVersionB, err := versionParser(minVersion)
minMajorVersion, minMinorVersion, err := versionParser(minVersion)
if err != nil {
return false, err
}

versionA, versionB, err := versionParser(version)
majorVersion, minorVersion, err := versionParser(version)
if err != nil {
return false, err
}

// compare each part according to minimum driver version
if versionA >= minVersionA && versionB >= minVersionB {
if majorVersion > minMajorVersion {
return true, nil
} else if majorVersion == minMajorVersion && minorVersion >= minMinorVersion {
return true, nil
}
return false, nil
Expand Down Expand Up @@ -1126,22 +1128,39 @@ func IsValidUpgrade[T csmv1.CSMComponentType](ctx context.Context, oldVersion, n
return true, nil
}

// if not equal, it is an upgrade/downgrade
// get minimum required version for upgrade
minUpgradePath, err := getUpgradeInfo(ctx, operatorConfig, csmComponentType, newVersion)
var minUpgradePath string
var minDowngradePath string
var err error
var isUpgradeValid bool
var isDowngradeValid bool

log.Info("####oldVersion: ", oldVersion, " ###newVersion: ", newVersion)

isUpgrade, _ := MinVersionCheck(oldVersion, newVersion)

// if it is an upgrade
if isUpgrade {
log.Info("proceeding with valid upgrade of driver/module")
minUpgradePath, err = getUpgradeInfo(ctx, operatorConfig, csmComponentType, newVersion)
isUpgradeValid, _ = MinVersionCheck(minUpgradePath, oldVersion)
} else {
// if it is a downgrade
log.Info("proceeding with valid downgrade of driver/module")
minDowngradePath, err = getUpgradeInfo(ctx, operatorConfig, csmComponentType, oldVersion)
isDowngradeValid, _ = MinVersionCheck(minDowngradePath, newVersion)
}

if err != nil {
log.Infow("getUpgradeInfo not successful")
return false, err
}

isUpgradeValid, _ := MinVersionCheck(minUpgradePath, oldVersion)
if isUpgradeValid {
log.Infof("proceeding with valid upgrade of %s from version %s to version %s", csmComponentType, oldVersion, newVersion)
return isUpgradeValid, nil
if isUpgradeValid || isDowngradeValid {
log.Infof("proceeding with valid upgrade/downgrade of %s from version %s to version %s", csmComponentType, oldVersion, newVersion)
return isUpgradeValid || isDowngradeValid, nil
}

log.Infof("not proceeding with invalid driver/module upgrade")
return isUpgradeValid, fmt.Errorf("upgrade of %s from version %s to %s not valid", csmComponentType, oldVersion, newVersion)
return isUpgradeValid, fmt.Errorf("upgrade/downgrade of %s from version %s to %s not valid", csmComponentType, oldVersion, newVersion)
}

func getUpgradeInfo[T csmv1.CSMComponentType](ctx context.Context, operatorConfig OperatorConfig, csmCompType T, oldVersion string) (string, error) {
Expand Down
1 change: 1 addition & 0 deletions scripts/external-snapshotter
Submodule external-snapshotter added at f6f16c
Loading