Skip to content

Commit

Permalink
feat(upgrade-job): add migration for logSilenceLevel and pluginMounth…
Browse files Browse the repository at this point in the history
…Path

Signed-off-by: Niladri Halder <niladri.halder26@gmail.com>
  • Loading branch information
niladrih committed Mar 18, 2024
1 parent ee21d5d commit 81cb201
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 7 deletions.
40 changes: 39 additions & 1 deletion k8s/upgrade/src/bin/upgrade-job/helm/chart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ impl HelmValuesCollection for UmbrellaValues {
/// This is used to deserialize the values.yaml of the Core chart.
#[derive(Deserialize)]
pub(crate) struct CoreValues {
/// This contains values for all of the agents.
/// This contains values for all the agents.
agents: Agents,
/// This contains values for all the base components.
base: Base,
/// This is the yaml object which contains values for the container image registry, repository,
/// tag, etc.
image: Image,
Expand Down Expand Up @@ -182,6 +184,11 @@ impl CoreValues {
self.csi.node_nvme_io_timeout()
}

/// This returns the value of the removed key for CSI socket mount path.
pub(crate) fn deprecated_node_csi_mount_path(&self) -> &str {
self.csi.deprecated_node_csi_mount_path()
}

/// This is a getter for the grafana/loki container image tag.
pub(crate) fn loki_stack_loki_image_tag(&self) -> &str {
self.loki_stack.loki_image_tag()
Expand Down Expand Up @@ -298,6 +305,11 @@ impl CoreValues {
pub(crate) fn prometheus_server_image_tag(&self) -> &str {
self.loki_stack.prometheus_server_image_tag()
}

/// This is the value of the deprecated key for log silence configuration.
pub(crate) fn deprecated_log_silence_level(&self) -> &str {
self.base.deprecated_log_silence_level()
}
}

/// This is used to deserialize the yaml object agents.
Expand All @@ -313,6 +325,20 @@ impl Agents {
}
}

/// This is used to deserialize the yaml object base.
#[derive(Deserialize)]
struct Base {
#[serde(default, rename(deserialize = "logSilenceLevel"))]
deprecated_log_silence_level: String,
}

impl Base {
/// This returns the value for the removed base.logSilenceLevel YAML key.
fn deprecated_log_silence_level(&self) -> &str {
self.deprecated_log_silence_level.as_str()
}
}

/// This is used to deserialize the yaml object 'agents.ha'.
#[derive(Deserialize)]
struct Ha {
Expand Down Expand Up @@ -475,6 +501,11 @@ impl Csi {
fn node_nvme_io_timeout(&self) -> &str {
self.node.nvme_io_timeout()
}

/// This returns the mount path value's key, the old one with the typo.
fn deprecated_node_csi_mount_path(&self) -> &str {
self.node.deprecated_plugin_mount_path()
}
}

/// This contains the image tags for the CSI sidecar containers.
Expand Down Expand Up @@ -534,13 +565,20 @@ impl CsiImage {
#[derive(Deserialize)]
struct CsiNode {
nvme: CsiNodeNvme,
#[serde(default, rename(deserialize = "pluginMounthPath"))]
deprecated_plugin_mount_path: String,
}

impl CsiNode {
/// This is a getter for the NVMe IO timeout.
fn nvme_io_timeout(&self) -> &str {
self.nvme.io_timeout()
}

/// This returns the csi node mount path key's value. The key had a typo, it's been removed.
fn deprecated_plugin_mount_path(&self) -> &str {
self.deprecated_plugin_mount_path.as_str()
}
}

/// This is used to deserialize the yaml object 'csi.node.nvme'.
Expand Down
30 changes: 24 additions & 6 deletions k8s/upgrade/src/bin/upgrade-job/helm/values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,7 @@ where
upgrade_values_file.path(),
)?;
}
}

// 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) {
// Switch out image tag for the latest one.
yq.set_literal_value(
YamlKey::try_from(".loki-stack.loki.image.tag")?,
Expand Down Expand Up @@ -361,6 +355,30 @@ where
target_values.promtail_readiness_probe_http_get_path(),
upgrade_values_file.path(),
)?;

// This helm value key was changed:
// Ref: https://github.com/openebs/mayastor-extensions/pull/419
yq.set_literal_value(
YamlKey::try_from(".base.logging.silenceLevel")?,
source_values.deprecated_log_silence_level(),
upgrade_values_file.path(),
)?;
yq.delete_object(
YamlKey::try_from(".base.logSilenceLevel")?,
upgrade_values_file.path(),
)?;

// This is a fix for a typo in the .csi.node.pluginMounthPath key.
// It was fixed, and the key now is called .csi.node.pluginMountPath.
yq.set_literal_value(
YamlKey::try_from(".csi.node.pluginMountPath")?,
source_values.deprecated_node_csi_mount_path(),
upgrade_values_file.path(),
)?;
yq.delete_object(
YamlKey::try_from(".csi.node.pluginMounthPath")?,
upgrade_values_file.path(),
)?;
}

// Default options.
Expand Down

0 comments on commit 81cb201

Please sign in to comment.