diff --git a/controllers/csm_controller.go b/controllers/csm_controller.go index 855515cf4..d1560dbf2 100644 --- a/controllers/csm_controller.go +++ b/controllers/csm_controller.go @@ -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 { @@ -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 @@ -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 diff --git a/operatorconfig/driverconfig/powerflex/v2.10.0/upgrade-path.yaml b/operatorconfig/driverconfig/powerflex/v2.10.0/upgrade-path.yaml index add639c8b..1a1170a4f 100644 --- a/operatorconfig/driverconfig/powerflex/v2.10.0/upgrade-path.yaml +++ b/operatorconfig/driverconfig/powerflex/v2.10.0/upgrade-path.yaml @@ -1,2 +1,2 @@ -minUpgradePath: v2.9.1 +minUpgradePath: v2.8.0 diff --git a/operatorconfig/driverconfig/powerflex/v2.8.0/upgrade-path.yaml b/operatorconfig/driverconfig/powerflex/v2.8.0/upgrade-path.yaml index f6ba20f92..624d827ab 100644 --- a/operatorconfig/driverconfig/powerflex/v2.8.0/upgrade-path.yaml +++ b/operatorconfig/driverconfig/powerflex/v2.8.0/upgrade-path.yaml @@ -1,2 +1,2 @@ -minUpgradePath: v2.7.0 +minUpgradePath: v2.6.0 diff --git a/operatorconfig/driverconfig/powerflex/v2.9.0/upgrade-path.yaml b/operatorconfig/driverconfig/powerflex/v2.9.0/upgrade-path.yaml index 1a1170a4f..f6ba20f92 100644 --- a/operatorconfig/driverconfig/powerflex/v2.9.0/upgrade-path.yaml +++ b/operatorconfig/driverconfig/powerflex/v2.9.0/upgrade-path.yaml @@ -1,2 +1,2 @@ -minUpgradePath: v2.8.0 +minUpgradePath: v2.7.0 diff --git a/operatorconfig/driverconfig/powerflex/v2.9.1/upgrade-path.yaml b/operatorconfig/driverconfig/powerflex/v2.9.1/upgrade-path.yaml index 1a1170a4f..f6ba20f92 100644 --- a/operatorconfig/driverconfig/powerflex/v2.9.1/upgrade-path.yaml +++ b/operatorconfig/driverconfig/powerflex/v2.9.1/upgrade-path.yaml @@ -1,2 +1,2 @@ -minUpgradePath: v2.8.0 +minUpgradePath: v2.7.0 diff --git a/operatorconfig/driverconfig/powerflex/v2.9.2/upgrade-path.yaml b/operatorconfig/driverconfig/powerflex/v2.9.2/upgrade-path.yaml index 1a1170a4f..f6ba20f92 100644 --- a/operatorconfig/driverconfig/powerflex/v2.9.2/upgrade-path.yaml +++ b/operatorconfig/driverconfig/powerflex/v2.9.2/upgrade-path.yaml @@ -1,2 +1,2 @@ -minUpgradePath: v2.8.0 +minUpgradePath: v2.7.0 diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index ccbc62a3f..1ec868e59 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -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 @@ -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) { diff --git a/scripts/external-snapshotter b/scripts/external-snapshotter new file mode 160000 index 000000000..f6f16cdbd --- /dev/null +++ b/scripts/external-snapshotter @@ -0,0 +1 @@ +Subproject commit f6f16cdbd5f958209a4b279a78d52ad4214ca82c