Skip to content

Commit

Permalink
refactor(upgrade): remove unnecessary type conversion during Version …
Browse files Browse the repository at this point in the history
…object creation

Signed-off-by: Niladri Halder <[email protected]>
  • Loading branch information
niladrih committed Feb 3, 2025
1 parent e8c9343 commit bf5afc2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 37 deletions.
14 changes: 7 additions & 7 deletions k8s/upgrade/src/common/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,22 @@ pub const PARTIAL_REBUILD_DISABLE_EXTENTS: (Version, Version) =
pub(crate) const TWO_DOT_O_RC_ONE: &str = "2.0.0-rc.1";

/// Version value for the earliest possible 2.1 release (there were no pre-releases).
pub(crate) const TWO_DOT_ONE: &str = "2.1.0";
pub(crate) const TWO_DOT_ONE: Version = Version::new(2, 1, 0);

/// Version value for the earliest possible 2.3 release (there were no pre-releases).
pub(crate) const TWO_DOT_THREE: &str = "2.3.0";
pub(crate) const TWO_DOT_THREE: Version = Version::new(2, 3, 0);

/// Version value for the earliest possible 2.4 release (there were no pre-releases).
pub(crate) const TWO_DOT_FOUR: &str = "2.4.0";
pub(crate) const TWO_DOT_FOUR: Version = Version::new(2, 4, 0);

/// Version value for the earliest possible 2.5 release.
pub(crate) const TWO_DOT_FIVE: &str = "2.5.0";
pub(crate) const TWO_DOT_FIVE: Version = Version::new(2, 5, 0);

/// Version value for the earliest possible 2.6 release.
pub(crate) const TWO_DOT_SIX: &str = "2.6.0";
pub(crate) const TWO_DOT_SIX: Version = Version::new(2, 6, 0);

/// Version value for 2.7.2 release.
pub(crate) const TWO_DOT_SEVEN_DOT_TWO: &str = "2.7.2";
pub(crate) const TWO_DOT_SEVEN_DOT_TWO: Version = Version::new(2, 7, 2);

/// Version value for 2.7.3.
pub(crate) const TWO_DOT_SEVEN_DOT_THREE: &str = "2.7.3";
pub(crate) const TWO_DOT_SEVEN_DOT_THREE: Version = Version::new(2, 7, 3);
40 changes: 10 additions & 30 deletions k8s/upgrade/src/helm/values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,11 @@ where
// below comparisons because of this.

// Specific special-case values for version 2.0.x.
let two_dot_o_rc_zero = Version::parse(TWO_DOT_O_RC_ONE).context(SemverParse {
let two_dot_o_rc_one = Version::parse(TWO_DOT_O_RC_ONE).context(SemverParse {
version_string: TWO_DOT_O_RC_ONE.to_string(),
})?;
let two_dot_one = Version::parse(TWO_DOT_ONE).context(SemverParse {
version_string: TWO_DOT_ONE.to_string(),
})?;
if source_version.ge(&two_dot_o_rc_zero) && source_version.lt(&two_dot_one) {

if source_version.ge(&two_dot_o_rc_one) && source_version.lt(&TWO_DOT_ONE) {
let log_level_to_replace = "info,io_engine=info";

if source_values.io_engine_log_level().eq(log_level_to_replace)
Expand All @@ -99,7 +97,7 @@ where
}

// Specific special-case values for to-version >=2.1.x.
if target_version.ge(&two_dot_one) {
if target_version.ge(&TWO_DOT_ONE) {
// RepoTags fields will also be set to the values found in the target helm values file
// (low_priority file). This is so integration tests which use specific repo commits can
// upgrade to a custom helm chart.
Expand All @@ -121,14 +119,8 @@ where
}

// Specific special-case values for version 2.3.x.
let two_dot_three = Version::parse(TWO_DOT_THREE).context(SemverParse {
version_string: TWO_DOT_THREE.to_string(),
})?;
let two_dot_four = Version::parse(TWO_DOT_FOUR).context(SemverParse {
version_string: TWO_DOT_FOUR.to_string(),
})?;
if source_version.ge(&two_dot_three)
&& source_version.lt(&two_dot_four)
if source_version.ge(&TWO_DOT_THREE)
&& source_version.lt(&TWO_DOT_FOUR)
&& source_values
.eventing_enabled()
.ne(&target_values.eventing_enabled())
Expand All @@ -141,10 +133,7 @@ where
}

// Special-case values for 2.5.x.
let two_dot_five = Version::parse(TWO_DOT_FIVE).context(SemverParse {
version_string: TWO_DOT_FIVE.to_string(),
})?;
if source_version.ge(&two_dot_o_rc_zero) && source_version.lt(&two_dot_five) {
if source_version.ge(&two_dot_o_rc_one) && source_version.lt(&TWO_DOT_FIVE) {
// promtail
let scrape_configs_to_replace = r"- job_name: {{ .Release.Name }}-pods-name
pipeline_stages:
Expand Down Expand Up @@ -216,10 +205,7 @@ where
}

// Special-case values for 2.6.x.
let two_dot_six = Version::parse(TWO_DOT_SIX).context(SemverParse {
version_string: TWO_DOT_SIX.to_string(),
})?;
if source_version.ge(&two_dot_o_rc_zero) && source_version.lt(&two_dot_six) {
if source_version.ge(&two_dot_o_rc_one) && source_version.lt(&TWO_DOT_SIX) {
// LocalPV Device mode was removed in OpenEBS/Dynamic LocalPV v4.0.0.
// Mayastor 2.6 uses Dynamic LocalPV v4.0.0 as a dependency.
yq.delete_object(
Expand Down Expand Up @@ -360,10 +346,7 @@ where
}

// Special-case values for 2.7.2.
let two_dot_seven_dot_two = Version::parse(TWO_DOT_SEVEN_DOT_TWO).context(SemverParse {
version_string: TWO_DOT_SEVEN_DOT_TWO.to_string(),
})?;
if source_version.ge(&two_dot_o_rc_zero) && source_version.lt(&two_dot_seven_dot_two) {
if source_version.ge(&two_dot_o_rc_one) && source_version.lt(&TWO_DOT_SEVEN_DOT_TWO) {
yq.delete_object(
YamlKey::try_from(".localpv-provisioner.release")?,
upgrade_values_file.path(),
Expand Down Expand Up @@ -512,10 +495,7 @@ where
}

// Special-case values for 2.7.3.
let two_dot_seven_dot_three = Version::parse(TWO_DOT_SEVEN_DOT_THREE).context(SemverParse {
version_string: TWO_DOT_SEVEN_DOT_THREE.to_string(),
})?;
if source_version.ge(&two_dot_o_rc_zero) && source_version.lt(&two_dot_seven_dot_three) {
if source_version.ge(&two_dot_o_rc_one) && source_version.lt(&TWO_DOT_SEVEN_DOT_THREE) {
yq.delete_object(
YamlKey::try_from(".etcd.initialClusterState")?,
upgrade_values_file.path(),
Expand Down

0 comments on commit bf5afc2

Please sign in to comment.