From 4a3bc23a96cc1dce221c8c08eb4382422f89b9d8 Mon Sep 17 00:00:00 2001 From: Tiago Castro Date: Thu, 16 May 2024 11:19:20 +0100 Subject: [PATCH] feat(naming): make it easier to use custom names Would still require a lot of manual changes though as values are spread on many .yaml files, ie values.yaml product.yaml doc.yaml... A script would be the required to make all changes. Signed-off-by: Tiago Castro --- Cargo.lock | 15 +++++ call-home/Cargo.toml | 1 + call-home/src/bin/callhome/main.rs | 2 +- .../src/bin/callhome/transmitter/client.rs | 2 +- call-home/src/common/constants.rs | 13 ++--- chart/values.yaml | 2 +- constants/Cargo.toml | 10 ++++ constants/src/lib.rs | 51 +++++++++++++++++ dependencies/control-plane | 2 +- k8s/plugin/Cargo.toml | 1 + k8s/supportability/Cargo.toml | 2 + k8s/supportability/src/collect/constants.rs | 6 +- .../k8s_resources/k8s_resource_dump.rs | 7 +-- k8s/supportability/src/collect/logs/mod.rs | 14 ++--- k8s/upgrade/Cargo.toml | 2 + .../src/bin/upgrade-job/common/constants.rs | 19 ++++--- .../src/bin/upgrade-job/common/error.rs | 30 +++++----- .../bin/upgrade-job/events/event_recorder.rs | 8 +-- k8s/upgrade/src/bin/upgrade-job/main.rs | 6 +- k8s/upgrade/src/bin/upgrade-job/opts.rs | 4 +- k8s/upgrade/src/bin/upgrade-job/upgrade.rs | 21 +++---- .../src/bin/upgrade-job/upgrade/data_plane.rs | 57 +++++++++++-------- .../src/bin/upgrade-job/upgrade/path.rs | 6 +- .../src/bin/upgrade-job/upgrade/utils.rs | 11 ++-- k8s/upgrade/src/plugin/constants.rs | 31 ++++------ k8s/upgrade/src/plugin/objects.rs | 7 +-- k8s/upgrade/src/plugin/upgrade.rs | 22 +++---- 27 files changed, 220 insertions(+), 132 deletions(-) create mode 100644 constants/Cargo.toml create mode 100644 constants/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 59f393a4f..b816ae2ce 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -580,6 +580,7 @@ dependencies = [ "bytes", "chrono", "clap", + "constants", "events-api", "futures", "humantime", @@ -698,6 +699,14 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28c122c3980598d243d63d9a704629a2d748d101f278052ff068be5a4423ab6f" +[[package]] +name = "constants" +version = "0.1.0" +dependencies = [ + "convert_case", + "utils", +] + [[package]] name = "convert_case" version = "0.4.0" @@ -1833,6 +1842,7 @@ dependencies = [ "async-trait", "clap", "console-logger", + "constants", "humantime", "kube-proxy", "openapi", @@ -2598,6 +2608,7 @@ dependencies = [ "tonic", "tracing", "url", + "utils", "uuid", ] @@ -3345,6 +3356,7 @@ dependencies = [ "async-trait", "chrono", "clap", + "constants", "downcast-rs", "flate2", "futures", @@ -3369,6 +3381,7 @@ dependencies = [ "tokio", "tower", "urlencoding", + "utils", "uuid", "yaml-rust", ] @@ -3975,6 +3988,8 @@ dependencies = [ "async-trait", "clap", "console-logger", + "constants", + "convert_case", "http", "humantime", "hyper", diff --git a/call-home/Cargo.toml b/call-home/Cargo.toml index f6b204956..1e61e6488 100644 --- a/call-home/Cargo.toml +++ b/call-home/Cargo.toml @@ -18,6 +18,7 @@ name = "obs-callhome-stats" path = "src/bin/stats/main.rs" [dependencies] +constants = { path = "../constants" } openapi = {path = "../dependencies/control-plane/openapi"} kube = { version = "0.85.0", features = ["runtime", "derive"] } k8s-openapi = { version = "0.19.0", features = ["v1_20"] } diff --git a/call-home/src/bin/callhome/main.rs b/call-home/src/bin/callhome/main.rs index 6046163bd..1c8b56aa4 100644 --- a/call-home/src/bin/callhome/main.rs +++ b/call-home/src/bin/callhome/main.rs @@ -139,7 +139,7 @@ async fn generate_report( aggregator_url: Option, ) -> Report { let mut report = Report { - product_name: PRODUCT.to_string(), + product_name: product(), k8s_cluster_id, deploy_namespace, product_version, diff --git a/call-home/src/bin/callhome/transmitter/client.rs b/call-home/src/bin/callhome/transmitter/client.rs index 0e0be4d89..d76ead917 100644 --- a/call-home/src/bin/callhome/transmitter/client.rs +++ b/call-home/src/bin/callhome/transmitter/client.rs @@ -42,7 +42,7 @@ impl Receiver { .header("CAStor-Cluster-Id", &self.cluster_id) .header("CAStor-Version", release_version()) .header("CAStor-Report-Type", "health_report") - .header("CAStor-Product", PRODUCT) + .header("CAStor-Product", product()) .header("CAStor-Time", Utc::now().to_string()) .header("Content-Type", "text/PGP; charset=binary") .body(body) diff --git a/call-home/src/common/constants.rs b/call-home/src/common/constants.rs index e9abd8c78..5ff2e1a46 100644 --- a/call-home/src/common/constants.rs +++ b/call-home/src/common/constants.rs @@ -5,13 +5,12 @@ use std::{ use utils::version_info; /// PRODUCT is the name of the project for which this call-home component is deployed. -pub const PRODUCT: &str = "Mayastor"; - -/// Label for release name. -pub const HELM_RELEASE_NAME_LABEL: &str = "openebs.io/release"; +pub fn product() -> String { + ::constants::product_pascal() +} /// Defines the default helm chart release name. -pub const DEFAULT_RELEASE_NAME: &str = "mayastor"; +pub const DEFAULT_RELEASE_NAME: &str = ::constants::DEFAULT_RELEASE_NAME; /// Defines the Label select for mayastor REST API. pub const API_REST_LABEL_SELECTOR: &str = "app=api-rest"; @@ -34,7 +33,7 @@ pub const POOL_STATS: &str = "Pool stats"; /// Defines the help argument for nexus stats need for promethueus library. pub const NEXUS_STATS: &str = "Nexus stats"; -/// Variable label for promethueus library. +/// Variable label for prometheus library. pub const ACTION: &str = "action"; /// Create action for events. @@ -112,7 +111,7 @@ pub fn key_filepath() -> PathBuf { } /// RECEIVER_API_ENDPOINT is the URL to anonymous call-home metrics collection endpoint. -pub const RECEIVER_ENDPOINT: &str = "https://openebs.phonehome.datacore.com/openebs/report"; +pub const RECEIVER_ENDPOINT: &str = ::constants::CALL_HOME_ENDPOINT; /// CALL_HOME_FREQUENCY_IN_HOURS is the frequency of call-home metrics transmission, in hours. /// The function call_home_frequency() returns the frequency as an std::time::Duration. diff --git a/chart/values.yaml b/chart/values.yaml index dd3e8dfcd..2e693bd65 100644 --- a/chart/values.yaml +++ b/chart/values.yaml @@ -633,7 +633,7 @@ loki-stack: # -- The Loki address to post logs to - url: http://{{ .Release.Name }}-loki:3100/loki/api/v1/push snippets: - # Promtail will export logs to loki only based on based on below + # Promtail will export logs to loki only based on below # configuration, below scrape config will export only our services # which are labeled with openebs.io/logging=true scrapeConfigs: | diff --git a/constants/Cargo.toml b/constants/Cargo.toml new file mode 100644 index 000000000..53053fbbf --- /dev/null +++ b/constants/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "constants" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +utils = {path = "../dependencies/control-plane/utils/utils-lib" } +convert_case = "0.4.0" \ No newline at end of file diff --git a/constants/src/lib.rs b/constants/src/lib.rs new file mode 100644 index 000000000..5f4f48077 --- /dev/null +++ b/constants/src/lib.rs @@ -0,0 +1,51 @@ +use convert_case::Casing; +use utils::constants::PRODUCT_DOMAIN_NAME; +pub use utils::PRODUCT_NAME; + +/// Name of the product. +pub fn product_pascal() -> String { + PRODUCT_NAME.to_case(convert_case::Case::Pascal) +} + +/// Helm release name label's key. +pub fn helm_release_name_key() -> String { + format!("{PRODUCT_DOMAIN_NAME}/release") +} + +/// Upgrade job container image name. +pub fn upgrade_job_img() -> String { + format!("{PRODUCT_NAME}-upgrade-job") +} +/// Upgrade job container image name. +pub fn upgrade_job_container_name() -> String { + format!("{PRODUCT_NAME}-upgrade-job") +} +/// UPGRADE_EVENT_REASON is the reason field in upgrade job. +pub fn upgrade_event_reason() -> String { + format!("{}Upgrade", product_pascal()) +} +/// Upgrade job container image repository. +pub const UPGRADE_JOB_IMAGE_REPO: &str = "openebs"; +/// This is the user docs URL for the Umbrella chart. +pub const UMBRELLA_CHART_UPGRADE_DOCS_URL: &str = + "https://openebs.io/docs/user-guides/upgrade#mayastor-upgrade"; + +/// Defines the default helm chart release name. +pub const DEFAULT_RELEASE_NAME: &str = PRODUCT_NAME; + +/// Installed release version. +pub fn helm_release_version_key() -> String { + format!("{PRODUCT_DOMAIN_NAME}/version") +} + +/// Loki Logging key. +pub fn loki_logging_key() -> String { + format!("{PRODUCT_DOMAIN_NAME}/logging") +} + +/// This is the name of the Helm chart which included the core chart as a sub-chart. +/// Under the hood, this installs the Core Helm chart (see below). +pub const UMBRELLA_CHART_NAME: &str = "openebs"; + +/// RECEIVER_API_ENDPOINT is the URL to anonymous call-home metrics collection endpoint. +pub const CALL_HOME_ENDPOINT: &str = "https://openebs.phonehome.datacore.com/openebs/report"; diff --git a/dependencies/control-plane b/dependencies/control-plane index 92e4e994f..a207a0570 160000 --- a/dependencies/control-plane +++ b/dependencies/control-plane @@ -1 +1 @@ -Subproject commit 92e4e994ff1c4faccd9a52a9179770b010dfc20f +Subproject commit a207a0570f2fba3a4b4a398812ecc8a27e1ca064 diff --git a/k8s/plugin/Cargo.toml b/k8s/plugin/Cargo.toml index 7e9240eee..0352dfa84 100644 --- a/k8s/plugin/Cargo.toml +++ b/k8s/plugin/Cargo.toml @@ -19,6 +19,7 @@ tls = [ "openapi/tower-client-tls", "rest-plugin/tls" ] [dependencies] openapi = { path = "../../dependencies/control-plane/openapi", default-features = false, features = [ "tower-trace" ] } utils = { path = "../../dependencies/control-plane/utils/utils-lib" } +constants = { path = "../../constants" } rest-plugin = { path = "../../dependencies/control-plane/control-plane/plugin", default-features = false } console-logger = { path = "../../console-logger" } supportability = { path = "../supportability" } diff --git a/k8s/supportability/Cargo.toml b/k8s/supportability/Cargo.toml index 30d775a5a..30fffb5d8 100644 --- a/k8s/supportability/Cargo.toml +++ b/k8s/supportability/Cargo.toml @@ -46,3 +46,5 @@ platform = { path = "../../dependencies/control-plane/utils/platform" } openapi = { path = "../../dependencies/control-plane/openapi", default-features = false, features = [ "tower-client", "tower-trace" ] } kube-proxy = { path = "../proxy" } rest-plugin = { path = "../../dependencies/control-plane/control-plane/plugin", default-features = false } +utils = { path = "../../dependencies/control-plane/utils/utils-lib" } +constants = { path = "../../constants" } diff --git a/k8s/supportability/src/collect/constants.rs b/k8s/supportability/src/collect/constants.rs index 58c9617b3..f74521ccc 100644 --- a/k8s/supportability/src/collect/constants.rs +++ b/k8s/supportability/src/collect/constants.rs @@ -37,8 +37,10 @@ pub(crate) const MAYASTOR_SERVICE: &str = "io-engine"; /// Defines the name of mayastor-io container(dataplane container) pub(crate) const DATA_PLANE_CONTAINER_NAME: &str = "io-engine"; -/// Defines the logging label(key-value pair) on mayastor services -pub(crate) const LOGGING_LABEL_SELECTOR: &str = "openebs.io/logging=true"; +/// Defines the logging label(key-value pair) on services. +pub(crate) fn logging_label_selector() -> String { + format!("{}=true", ::constants::loki_logging_key()) +} /// Defines the name of upgrade service pub(crate) const UPGRADE_SERVICE: &str = "upgrade"; diff --git a/k8s/supportability/src/collect/k8s_resources/k8s_resource_dump.rs b/k8s/supportability/src/collect/k8s_resources/k8s_resource_dump.rs index 4560ee3b1..174978388 100644 --- a/k8s/supportability/src/collect/k8s_resources/k8s_resource_dump.rs +++ b/k8s/supportability/src/collect/k8s_resources/k8s_resource_dump.rs @@ -19,8 +19,7 @@ use std::{ iter::FromIterator, path::{Path, PathBuf}, }; - -const MAYASTOR_CSI_DRIVER: &str = "io.openebs.csi-mayastor"; +use utils::csi_plugin_name; /// K8s resource dumper client #[derive(Clone)] @@ -333,7 +332,7 @@ async fn get_k8s_vs_classes( ) -> Result<(), K8sResourceDumperError> { log("\t Collecting Kubernetes VolumeSnapshotClass resources".to_string()); match k8s_client - .list_volumesnapshot_classes(Some(MAYASTOR_CSI_DRIVER), None, None) + .list_volumesnapshot_classes(Some(&csi_plugin_name()), None, None) .await { Ok(vscs) => { @@ -356,7 +355,7 @@ async fn get_k8s_vsnapshot_contents( ) -> Result<(), K8sResourceDumperError> { log("\t Collecting Kubernetes VolumeSnapshotContents resources".to_string()); match k8s_client - .list_volumesnapshotcontents(Some(MAYASTOR_CSI_DRIVER), None, None) + .list_volumesnapshotcontents(Some(&csi_plugin_name()), None, None) .await { Ok(vscs) => { diff --git a/k8s/supportability/src/collect/logs/mod.rs b/k8s/supportability/src/collect/logs/mod.rs index 70a631fcf..a121e7f07 100644 --- a/k8s/supportability/src/collect/logs/mod.rs +++ b/k8s/supportability/src/collect/logs/mod.rs @@ -3,8 +3,8 @@ mod loki; use crate::collect::{ constants::{ - CALLHOME_JOB_SERVICE, CONTROL_PLANE_SERVICES, DATA_PLANE_SERVICES, - HOST_NAME_REQUIRED_SERVICES, LOGGING_LABEL_SELECTOR, NATS_JOB_SERVICE, UPGRADE_JOB_SERVICE, + logging_label_selector, CALLHOME_JOB_SERVICE, CONTROL_PLANE_SERVICES, DATA_PLANE_SERVICES, + HOST_NAME_REQUIRED_SERVICES, NATS_JOB_SERVICE, UPGRADE_JOB_SERVICE, }, k8s_resources::{ client::{ClientSet, K8sResourceError}, @@ -268,7 +268,7 @@ impl Logger for LogCollection { let pods = self .k8s_logger_client .get_k8s_clientset() - .get_pods(LOGGING_LABEL_SELECTOR, "") + .get_pods(&logging_label_selector(), "") .await?; let control_plane_pods = pods @@ -295,7 +295,7 @@ impl Logger for LogCollection { let pods = self .k8s_logger_client .get_k8s_clientset() - .get_pods(LOGGING_LABEL_SELECTOR, "") + .get_pods(&logging_label_selector(), "") .await?; let data_plane_pods = pods .into_iter() @@ -321,7 +321,7 @@ impl Logger for LogCollection { let pods = self .k8s_logger_client .get_k8s_clientset() - .get_pods(LOGGING_LABEL_SELECTOR, "") + .get_pods(&logging_label_selector(), "") .await?; let upgrade_pod = pods @@ -348,7 +348,7 @@ impl Logger for LogCollection { let pods = self .k8s_logger_client .get_k8s_clientset() - .get_pods(LOGGING_LABEL_SELECTOR, "") + .get_pods(&logging_label_selector(), "") .await?; let callhome_pod = pods @@ -375,7 +375,7 @@ impl Logger for LogCollection { let pods = self .k8s_logger_client .get_k8s_clientset() - .get_pods(LOGGING_LABEL_SELECTOR, "") + .get_pods(&logging_label_selector(), "") .await?; let nats_pods = pods diff --git a/k8s/upgrade/Cargo.toml b/k8s/upgrade/Cargo.toml index a54045e26..c8b38d50c 100644 --- a/k8s/upgrade/Cargo.toml +++ b/k8s/upgrade/Cargo.toml @@ -14,8 +14,10 @@ path = "src/lib.rs" [dependencies] openapi = { path = "../../dependencies/control-plane/openapi", default-features = false, features = [ "tower-trace" ] } utils = { path = "../../dependencies/control-plane/utils/utils-lib" } +constants = { path = "../../constants" } kube-proxy = { path = "../proxy" } console-logger = { path = "../../console-logger" } +convert_case = "0.4.0" kube = { version = "0.85.0", default-features = true, features = [ "derive", "runtime" ] } anyhow = "1.0.75" clap = { version = "4.4.6", features = ["derive", "env", "string", "color"] } diff --git a/k8s/upgrade/src/bin/upgrade-job/common/constants.rs b/k8s/upgrade/src/bin/upgrade-job/common/constants.rs index 387baf9b9..d81434874 100644 --- a/k8s/upgrade/src/bin/upgrade-job/common/constants.rs +++ b/k8s/upgrade/src/bin/upgrade-job/common/constants.rs @@ -1,14 +1,14 @@ use semver::Version; /// This is the name of the project that is being upgraded. -pub(crate) const PRODUCT: &str = "Mayastor"; +pub use constants::product_pascal; /// This is the name of the Helm chart which included the core chart as a sub-chart. /// Under the hood, this installs the Core Helm chart (see below). -pub(crate) const UMBRELLA_CHART_NAME: &str = "openebs"; +pub(crate) const UMBRELLA_CHART_NAME: &str = constants::UMBRELLA_CHART_NAME; /// This is the name of the Helm chart of this project. -pub(crate) const CORE_CHART_NAME: &str = "mayastor"; +pub(crate) const CORE_CHART_NAME: &str = constants::PRODUCT_NAME; /// This is the shared Pod label of the -io-engine DaemonSet. pub(crate) const IO_ENGINE_LABEL: &str = "app=io-engine"; @@ -17,20 +17,23 @@ pub(crate) const IO_ENGINE_LABEL: &str = "app=io-engine"; pub(crate) const AGENT_CORE_LABEL: &str = "app=agent-core"; /// This is the shared label across the helm chart components which carries the chart version. -pub(crate) const CHART_VERSION_LABEL_KEY: &str = "openebs.io/version"; +pub(crate) use constants::helm_release_version_key; /// This is the label set on a storage API Node resource when a 'Node Drain' is issued. -pub(crate) const DRAIN_FOR_UPGRADE: &str = "mayastor-upgrade"; +pub fn drain_for_upgrade() -> String { + format!("{CORE_CHART_NAME}-upgrade") +} /// This is the label set on a storage API Node resource when a 'Node Drain' is issued. -pub(crate) const CORDON_FOR_ANA_CHECK: &str = "mayastor-upgrade-nvme-ana-check"; +pub fn cordon_ana_check() -> String { + format!("{CORE_CHART_NAME}-upgrade-nvme-ana-check") +} /// This is the allowed upgrade to-version/to-version-range for the Umbrella chart. pub(crate) const TO_UMBRELLA_SEMVER: &str = "4.0.1"; /// This is the user docs URL for the Umbrella chart. -pub(crate) const UMBRELLA_CHART_UPGRADE_DOCS_URL: &str = - "https://openebs.io/docs/user-guides/upgrade#mayastor-upgrade"; +pub(crate) const UMBRELLA_CHART_UPGRADE_DOCS_URL: &str = constants::UMBRELLA_CHART_UPGRADE_DOCS_URL; /// This is the limit for the number of objects we want to collect over the network from /// the kubernetes api. diff --git a/k8s/upgrade/src/bin/upgrade-job/common/error.rs b/k8s/upgrade/src/bin/upgrade-job/common/error.rs index f079c2511..96824b36e 100644 --- a/k8s/upgrade/src/bin/upgrade-job/common/error.rs +++ b/k8s/upgrade/src/bin/upgrade-job/common/error.rs @@ -1,7 +1,7 @@ use crate::{ common::constants::{ - CHART_VERSION_LABEL_KEY, CORE_CHART_NAME, PRODUCT, TO_UMBRELLA_SEMVER, UMBRELLA_CHART_NAME, - UMBRELLA_CHART_UPGRADE_DOCS_URL, + helm_release_version_key, product_pascal, CORE_CHART_NAME, TO_UMBRELLA_SEMVER, + UMBRELLA_CHART_NAME, UMBRELLA_CHART_UPGRADE_DOCS_URL, }, events::event_recorder::EventNote, helm::chart::PromtailConfigClient, @@ -21,7 +21,7 @@ pub(crate) enum Error { /// Error for when the storage REST API URL is parsed. #[snafu(display( "Failed to parse {} REST API URL {}: {}", - PRODUCT, + product_pascal(), rest_endpoint, source ))] @@ -44,7 +44,7 @@ pub(crate) enum Error { /// Error for when REST API configuration fails. #[snafu(display( "Failed to configure {} REST API client with endpoint {}: {:?}", - PRODUCT, + product_pascal(), rest_endpoint, source, ))] @@ -244,7 +244,7 @@ pub(crate) enum Error { EmptyPodUid { name: String, namespace: String }, /// Error for when an uncordon request for a storage node fails. - #[snafu(display("Failed to uncordon {} Node {}: {}", PRODUCT, node_id, source))] + #[snafu(display("Failed to uncordon {} Node {}: {}", product_pascal(), node_id, source))] StorageNodeUncordon { source: openapi::tower::client::Error, node_id: String, @@ -259,37 +259,37 @@ pub(crate) enum Error { }, /// Error for when listing storage nodes fails. - #[snafu(display("Failed to list {} Nodes: {}", PRODUCT, source))] + #[snafu(display("Failed to list {} Nodes: {}", product_pascal(), source))] ListStorageNodes { source: openapi::tower::client::Error, }, /// Error for when GET-ing a storage node fails. - #[snafu(display("Failed to list {} Node {}: {}", PRODUCT, node_id, source))] + #[snafu(display("Failed to list {} Node {}: {}", product_pascal(), node_id, source))] GetStorageNode { source: openapi::tower::client::Error, node_id: String, }, /// Error for when the storage node's Spec is empty. - #[snafu(display("Failed to get {} Node {}", PRODUCT, node_id))] + #[snafu(display("Failed to get {} Node {}", product_pascal(), node_id))] EmptyStorageNodeSpec { node_id: String }, /// Error for when a GET request for a list of storage volumes fails. - #[snafu(display("Failed to list {} Volumes: {}", PRODUCT, source))] + #[snafu(display("Failed to list {} Volumes: {}", product_pascal(), source))] ListStorageVolumes { source: openapi::tower::client::Error, }, /// Error for when a storage node drain request fails. - #[snafu(display("Failed to drain {} Node {}: {}", PRODUCT, node_id, source))] + #[snafu(display("Failed to drain {} Node {}: {}", product_pascal(), node_id, source))] DrainStorageNode { source: openapi::tower::client::Error, node_id: String, }, /// Error for when a storage node cordon request fails. - #[snafu(display("Failed to cordon {} Node {}: {}", PRODUCT, node_id, source))] + #[snafu(display("Failed to cordon {} Node {}: {}", product_pascal(), node_id, source))] CordonStorageNode { source: openapi::tower::client::Error, node_id: String, @@ -364,7 +364,7 @@ pub(crate) enum Error { "'{}' is not a known {} helm chart, only helm charts '{}-' and '{}-' \ are supported", chart_name, - PRODUCT, + product_pascal(), CORE_CHART_NAME, UMBRELLA_CHART_NAME ))] @@ -399,7 +399,7 @@ pub(crate) enum Error { version_string: String, }, - /// Error for when the detected upgrade path for PRODUCT is not supported. + /// Error for when the detected upgrade path for product_pascal() is not supported. #[snafu(display("The upgrade path is invalid"))] InvalidUpgradePath, @@ -501,7 +501,7 @@ pub(crate) enum Error { /// Error for when the Storage REST API Deployment is absent. #[snafu(display( "Found no {} REST API Deployments in the namespace {} with labelSelector {}", - PRODUCT, + product_pascal(), namespace, label_selector ))] @@ -513,7 +513,7 @@ pub(crate) enum Error { /// Error for when the CHART_VERSION_LABEL_KEY is missing amongst the labels in a Deployment. #[snafu(display( "A label with the key {} was not found for Deployment {} in namespace {}", - CHART_VERSION_LABEL_KEY, + helm_release_version_key(), deployment_name, namespace ))] diff --git a/k8s/upgrade/src/bin/upgrade-job/events/event_recorder.rs b/k8s/upgrade/src/bin/upgrade-job/events/event_recorder.rs index 60477fadd..5fcd723b0 100644 --- a/k8s/upgrade/src/bin/upgrade-job/events/event_recorder.rs +++ b/k8s/upgrade/src/bin/upgrade-job/events/event_recorder.rs @@ -1,5 +1,5 @@ use crate::common::{ - constants::PRODUCT, + constants::product_pascal, error::{ EventChannelSend, EventPublish, EventRecorderOptionsAbsent, GetPod, JobPodHasTooManyOwners, JobPodOwnerIsNotJob, JobPodOwnerNotFound, Result, SerializeEventNote, @@ -205,7 +205,7 @@ impl EventRecorder { let note_s = serde_json::to_string(¬e).context(SerializeEventNote { note })?; self.publish(Event { type_: EventType::Normal, - reason: format!("{PRODUCT}Upgrade"), + reason: constants::upgrade_event_reason(), note: Some(note_s), action: action.to_string(), secondary: None, @@ -224,7 +224,7 @@ impl EventRecorder { let note_s = serde_json::to_string(¬e).context(SerializeEventNote { note })?; self.publish(Event { type_: EventType::Warning, - reason: format!("{PRODUCT}Upgrade"), + reason: constants::upgrade_event_reason(), note: Some(note_s), action: action.to_string(), secondary: None, @@ -245,7 +245,7 @@ impl EventRecorder { let _ = self .publish_warning(format!("Failed to upgrade: {err}"), action) .await - .map_err(|error| error!(%error, "Failed to upgrade {PRODUCT}")); + .map_err(|error| error!(%error, "Failed to upgrade {}", product_pascal())); } /// Shuts down the event channel which makes the event loop worker exit its loop and return. diff --git a/k8s/upgrade/src/bin/upgrade-job/main.rs b/k8s/upgrade/src/bin/upgrade-job/main.rs index bb7da193d..87eebb0d0 100644 --- a/k8s/upgrade/src/bin/upgrade-job/main.rs +++ b/k8s/upgrade/src/bin/upgrade-job/main.rs @@ -1,5 +1,5 @@ use crate::{ - common::{constants::PRODUCT, error::Result}, + common::{constants::product_pascal, error::Result}, opts::validators::{ validate_helm_chart_dir, validate_helm_release, validate_helmv3_in_path, validate_namespace, validate_rest_endpoint, @@ -26,12 +26,12 @@ async fn main() -> Result<()> { init_logging(); let opts = parse_cli_args().await.map_err(|error| { - error!(%error, "Failed to upgrade {PRODUCT}"); + error!(%error, "Failed to upgrade {}", product_pascal()); error })?; upgrade(&opts).await.map_err(|error| { - error!(%error, "Failed to upgrade {PRODUCT}"); + error!(%error, "Failed to upgrade {}", product_pascal()); flush_traces(); error }) diff --git a/k8s/upgrade/src/bin/upgrade-job/opts.rs b/k8s/upgrade/src/bin/upgrade-job/opts.rs index ea48285cf..50dd31a32 100644 --- a/k8s/upgrade/src/bin/upgrade-job/opts.rs +++ b/k8s/upgrade/src/bin/upgrade-job/opts.rs @@ -1,4 +1,4 @@ -use crate::common::constants::PRODUCT; +use crate::common::constants::product_pascal; use clap::Parser; use std::path::PathBuf; use utils::{package_description, tracing_telemetry::FmtStyle, version_info_str}; @@ -9,7 +9,7 @@ pub(crate) mod validators; /// These are the supported cli configuration options for upgrade. #[derive(Parser)] #[command(name = package_description!(), version = version_info_str!())] -#[command(about = format!("Upgrades {}", PRODUCT), long_about = None)] +#[command(about = format!("Upgrades {}", product_pascal()), long_about = None)] pub(crate) struct CliArgs { /// This is the URL for the storage REST API server. #[arg(short = 'e', long)] diff --git a/k8s/upgrade/src/bin/upgrade-job/upgrade.rs b/k8s/upgrade/src/bin/upgrade-job/upgrade.rs index 2417ea605..e582feb03 100644 --- a/k8s/upgrade/src/bin/upgrade-job/upgrade.rs +++ b/k8s/upgrade/src/bin/upgrade-job/upgrade.rs @@ -1,8 +1,8 @@ use crate::{ common::{ constants::{ - CHART_VERSION_LABEL_KEY, CORE_CHART_NAME, IO_ENGINE_LABEL, - PARTIAL_REBUILD_DISABLE_EXTENTS, PRODUCT, + helm_release_version_key, product_pascal, CORE_CHART_NAME, IO_ENGINE_LABEL, + PARTIAL_REBUILD_DISABLE_EXTENTS, }, error::{PartialRebuildNotAllowed, Result}, kube_client as KubeClient, @@ -78,14 +78,14 @@ async fn upgrade_product(opts: &CliArgs, event: &mut EventRecorder) -> Result<() event .publish_normal( - format!("Starting {PRODUCT} upgrade..."), + format!("Starting {} upgrade...", product_pascal()), EventAction::UpgradingCP, ) .await?; event .publish_normal( - format!("Upgrading {PRODUCT} control-plane"), + format!("Upgrading {} control-plane", product_pascal()), EventAction::UpgradingCP, ) .await?; @@ -101,7 +101,7 @@ async fn upgrade_product(opts: &CliArgs, event: &mut EventRecorder) -> Result<() event .publish_normal( - format!("Upgraded {PRODUCT} control-plane"), + format!("Upgraded {} control-plane", product_pascal()), EventAction::UpgradedCP, ) .await?; @@ -109,7 +109,8 @@ async fn upgrade_product(opts: &CliArgs, event: &mut EventRecorder) -> Result<() // Data plane containers are updated in this step. if !opts.skip_data_plane_restart() { let yet_to_upgrade_io_engine_label = format!( - "{IO_ENGINE_LABEL},{CHART_VERSION_LABEL_KEY}!={}", + "{IO_ENGINE_LABEL},{}!={}", + helm_release_version_key(), target_version.as_str() ); let yet_to_upgrade_io_engine_pods = KubeClient::list_pods( @@ -126,7 +127,7 @@ async fn upgrade_product(opts: &CliArgs, event: &mut EventRecorder) -> Result<() event .publish_normal( - format!("Upgrading {PRODUCT} data-plane"), + format!("Upgrading {} data-plane", product_pascal()), EventAction::UpgradingDP, ) .await?; @@ -147,7 +148,7 @@ async fn upgrade_product(opts: &CliArgs, event: &mut EventRecorder) -> Result<() event .publish_normal( - format!("Upgraded {PRODUCT} data-plane"), + format!("Upgraded {} data-plane", product_pascal()), EventAction::UpgradedDP, ) .await?; @@ -155,7 +156,7 @@ async fn upgrade_product(opts: &CliArgs, event: &mut EventRecorder) -> Result<() event .publish_normal( - format!("Successfully upgraded {PRODUCT}"), + format!("Successfully upgraded {}", product_pascal()), EventAction::Successful, ) .await?; @@ -169,7 +170,7 @@ fn partial_rebuild_check( ) -> Result<()> { let partial_rebuild_disable_required = yet_to_upgrade_io_engine_pods .iter() - .filter_map(|pod| pod.labels().get(CHART_VERSION_LABEL_KEY)) + .filter_map(|pod| pod.labels().get(&helm_release_version_key())) .any(|v| { let version = Version::parse(v).expect("failed to parse version from io-engine Pod label"); diff --git a/k8s/upgrade/src/bin/upgrade-job/upgrade/data_plane.rs b/k8s/upgrade/src/bin/upgrade-job/upgrade/data_plane.rs index 2b38bbb90..421f2bde5 100644 --- a/k8s/upgrade/src/bin/upgrade-job/upgrade/data_plane.rs +++ b/k8s/upgrade/src/bin/upgrade-job/upgrade/data_plane.rs @@ -1,8 +1,8 @@ use crate::{ common::{ constants::{ - AGENT_CORE_LABEL, CHART_VERSION_LABEL_KEY, CORDON_FOR_ANA_CHECK, DRAIN_FOR_UPGRADE, - IO_ENGINE_LABEL, PRODUCT, + cordon_ana_check, drain_for_upgrade, helm_release_version_key, product_pascal, + AGENT_CORE_LABEL, IO_ENGINE_LABEL, }, error::{ DrainStorageNode, EmptyPodNodeName, EmptyPodSpec, EmptyStorageNodeSpec, GetStorageNode, @@ -27,7 +27,7 @@ use snafu::ResultExt; use std::time::Duration; use tokio::time::sleep; use tracing::info; -use utils::{API_REST_LABEL, CSI_NODE_NVME_ANA, ETCD_LABEL}; +use utils::{csi_node_nvme_ana, API_REST_LABEL, ETCD_LABEL}; /// Upgrade data plane by controlled restart of io-engine pods pub(crate) async fn upgrade_data_plane( @@ -52,8 +52,9 @@ pub(crate) async fn upgrade_data_plane( info!("Starting data-plane upgrade..."); info!( - "Trying to remove upgrade {PRODUCT} Node Drain label from {PRODUCT} Nodes, \ - if any left over from previous upgrade attempts..." + "Trying to remove upgrade {product} Node Drain label from {product} Nodes, \ + if any left over from previous upgrade attempts...", + product = product_pascal() ); let storage_nodes_resp = rest_client @@ -137,7 +138,10 @@ pub(crate) async fn upgrade_data_plane( uncordon_drained_storage_node(node_name, &rest_client).await?; } - info!("Checking to see if new {PRODUCT} Nodes have been added to the cluster, which require upgrade"); + info!( + "Checking to see if new {} Nodes have been added to the cluster, which require upgrade", + product_pascal() + ); } info!("Successfully upgraded data-plane!"); @@ -147,7 +151,7 @@ pub(crate) async fn upgrade_data_plane( /// Uncordon storage Node by removing drain label. async fn uncordon_drained_storage_node(node_id: &str, rest_client: &RestClientSet) -> Result<()> { - let drain_label_for_upgrade: String = DRAIN_FOR_UPGRADE.to_string(); + let drain_label_for_upgrade: String = drain_for_upgrade(); let sleep_duration = Duration::from_secs(1_u64); loop { let storage_node = @@ -175,15 +179,15 @@ async fn uncordon_drained_storage_node(node_id: &str, rest_client: &RestClientSe { rest_client .nodes_api() - .delete_node_cordon(node_id, DRAIN_FOR_UPGRADE) + .delete_node_cordon(node_id, &drain_for_upgrade()) .await .context(StorageNodeUncordon { node_id: node_id.to_string(), })?; info!(node.id = %node_id, - label = %DRAIN_FOR_UPGRADE, - "Removed drain label from {PRODUCT} Node" + label = %drain_for_upgrade(), + "Removed drain label from {} Node", product_pascal() ); } _ => return Ok(()), @@ -251,7 +255,7 @@ async fn wait_for_rebuild(node_name: &str, rest_client: &RestClientSet) -> Resul /// Issue the node drain command on the node. async fn drain_storage_node(node_id: &str, rest_client: &RestClientSet) -> Result<()> { - let drain_label_for_upgrade: String = DRAIN_FOR_UPGRADE.to_string(); + let drain_label_for_upgrade: String = drain_for_upgrade(); let sleep_duration = Duration::from_secs(5_u64); loop { let storage_node = @@ -277,26 +281,26 @@ async fn drain_storage_node(node_id: &str, rest_client: &RestClientSet) -> Resul Some(CordonDrainState::drainingstate(drain_state)) if drain_state.drainlabels.contains(&drain_label_for_upgrade) => { - info!(node.id = %node_id, "Waiting for {PRODUCT} Node drain to complete"); + info!(node.id = %node_id, "Waiting for {} Node drain to complete", product_pascal()); // Wait for node drain to complete. sleep(sleep_duration).await; } Some(CordonDrainState::drainedstate(drain_state)) if drain_state.drainlabels.contains(&drain_label_for_upgrade) => { - info!(node.id = %node_id, "Drain completed for {PRODUCT} Node"); + info!(node.id = %node_id, "Drain completed for {} Node", product_pascal()); return Ok(()); } _ => { rest_client .nodes_api() - .put_node_drain(node_id, DRAIN_FOR_UPGRADE) + .put_node_drain(node_id, &drain_for_upgrade()) .await .context(DrainStorageNode { node_id: node_id.to_string(), })?; - info!(node.id = %node_id, "Drain started for {PRODUCT} Node"); + info!(node.id = %node_id, "Drain started for {} Node", product_pascal()); } } } @@ -309,7 +313,10 @@ async fn data_plane_pod_is_running( upgrade_target_version: &String, ) -> Result { let node_name_pod_field = format!("spec.nodeName={node}"); - let pod_label = format!("{IO_ENGINE_LABEL},{CHART_VERSION_LABEL_KEY}={upgrade_target_version}"); + let pod_label = format!( + "{IO_ENGINE_LABEL},{}={upgrade_target_version}", + helm_release_version_key() + ); let pod_list: Vec = KubeClient::list_pods(namespace, Some(pod_label), Some(node_name_pod_field)).await?; @@ -342,14 +349,18 @@ async fn control_plane_is_running( namespace: String, upgrade_target_version: &String, ) -> Result { - let agent_core_selector_label = - format!("{AGENT_CORE_LABEL},{CHART_VERSION_LABEL_KEY}={upgrade_target_version}"); + let agent_core_selector_label = format!( + "{AGENT_CORE_LABEL},{}={upgrade_target_version}", + helm_release_version_key() + ); let pod_list: Vec = KubeClient::list_pods(namespace.clone(), Some(agent_core_selector_label), None).await?; let core_is_ready = all_pods_are_ready(pod_list); - let api_rest_selector_label = - format!("{API_REST_LABEL},{CHART_VERSION_LABEL_KEY}={upgrade_target_version}"); + let api_rest_selector_label = format!( + "{API_REST_LABEL},{}={upgrade_target_version}", + helm_release_version_key() + ); let pod_list: Vec = KubeClient::list_pods(namespace.clone(), Some(api_rest_selector_label), None).await?; let rest_is_ready = all_pods_are_ready(pod_list); @@ -375,7 +386,7 @@ async fn is_node_drainable( return Ok(false); } - let ana_disabled_label = format!("{CSI_NODE_NVME_ANA}=false"); + let ana_disabled_label = format!("{}=false", csi_node_nvme_ana()); let ana_disabled_filter = ListParams::default().labels(ana_disabled_label.as_str()); let ana_disabled_nodes = k8s_nodes_api @@ -394,9 +405,9 @@ async fn is_node_drainable( return Ok(true); } - cordon_storage_node(node_name, CORDON_FOR_ANA_CHECK, rest_client).await?; + cordon_storage_node(node_name, &cordon_ana_check(), rest_client).await?; let result = frontend_nodes_ana_check(node_name, ana_disabled_nodes, rest_client).await; - uncordon_storage_node(node_name, CORDON_FOR_ANA_CHECK, rest_client).await?; + uncordon_storage_node(node_name, &cordon_ana_check(), rest_client).await?; result } diff --git a/k8s/upgrade/src/bin/upgrade-job/upgrade/path.rs b/k8s/upgrade/src/bin/upgrade-job/upgrade/path.rs index e383eb626..00118884b 100644 --- a/k8s/upgrade/src/bin/upgrade-job/upgrade/path.rs +++ b/k8s/upgrade/src/bin/upgrade-job/upgrade/path.rs @@ -1,6 +1,6 @@ use crate::{ common::{ - constants::CHART_VERSION_LABEL_KEY, + constants::helm_release_version_key, error::{ ListDeploymentsWithLabel, NoRestDeployment, NoVersionLabelInDeployment, ReadingFile, Result, SemverParse, YamlParseBufferForUnsupportedVersion, YamlParseFromFile, @@ -40,7 +40,7 @@ pub(crate) fn version_from_chart_yaml_file(path: PathBuf) -> Result { /// Generate a semver::Version from the CHART_VERSION_LABEL_KEY label on the Storage REST API /// Deployment. pub(crate) async fn version_from_rest_deployment_label(ns: &str) -> Result { - let labels = format!("{API_REST_LABEL},{CHART_VERSION_LABEL_KEY}"); + let labels = format!("{API_REST_LABEL},{}", helm_release_version_key()); let deployments_api = KubeClient::deployments_api(ns).await?; let mut deploy_list = deployments_api @@ -76,7 +76,7 @@ pub(crate) async fn version_from_rest_deployment_label(ns: &str) -> Result { - info!(node.id = %node_id, "{PRODUCT} Node is already cordoned"); + info!(node.id = %node_id, "{} Node is already cordoned", product_pascal()); } _ => { rest_client @@ -216,7 +216,7 @@ pub(crate) async fn cordon_storage_node( node_id: node_id.to_string(), })?; - info!(node.id = %node_id, "Put cordon label for {PRODUCT} Node"); + info!(node.id = %node_id, "Put cordon label for {} Node", product_pascal()); } } @@ -263,13 +263,14 @@ pub(crate) async fn uncordon_storage_node( info!( node.id = %node_id, label = %cordon_label, - "Removed cordon label from {PRODUCT} Node" + "Removed cordon label from {} Node", + product_pascal() ); } _ => info!( node.id = %node_id, label = %cordon_label, - "Cordon label absent from {PRODUCT} Node" + "Cordon label absent from {} Node", product_pascal() ), } diff --git a/k8s/upgrade/src/plugin/constants.rs b/k8s/upgrade/src/plugin/constants.rs index c361bd54b..70ccaead2 100644 --- a/k8s/upgrade/src/plugin/constants.rs +++ b/k8s/upgrade/src/plugin/constants.rs @@ -3,15 +3,16 @@ use utils::version_info; /// This is used to create labels for the upgrade job. #[macro_export] macro_rules! upgrade_labels { - () => { + () => {{ + let log = constants::loki_logging_key(); btreemap! { "app" => UPGRADE_JOB_NAME_SUFFIX, - "openebs.io/logging" => "true", + log.as_str() => "true", } .iter() .map(|(k, v)| (k.to_string(), v.to_string())) .collect() - }; + }}; } /// Append the release name to k8s objects. @@ -63,18 +64,15 @@ pub(crate) fn upgrade_event_selector(release_name: &str, component_name: &str) - format!("{kind},{name_key}={name_value}") } -pub(crate) const HELM_RELEASE_NAME_LABEL: &str = "openebs.io/release"; - pub(crate) const DEFAULT_IMAGE_REGISTRY: &str = "docker.io"; /// The upgrade job will use the UPGRADE_JOB_IMAGE_NAME image (below) with this tag. pub(crate) const UPGRADE_JOB_IMAGE_TAG: &str = "develop"; /// Upgrade job container image repository. -pub(crate) const UPGRADE_JOB_IMAGE_REPO: &str = "openebs"; +pub(crate) const UPGRADE_JOB_IMAGE_REPO: &str = constants::UPGRADE_JOB_IMAGE_REPO; -/// Upgrade job container image name. -pub(crate) const UPGRADE_JOB_IMAGE_NAME: &str = "mayastor-upgrade-job"; +pub(crate) use constants::upgrade_job_img; /// Upgrade job name suffix. pub(crate) const UPGRADE_JOB_NAME_SUFFIX: &str = "upgrade"; @@ -100,33 +98,26 @@ pub(crate) const UPGRADE_CONFIG_MAP_NAME_SUFFIX: &str = "upgrade-config-map"; /// Upgrade job binary name. pub(crate) const UPGRADE_BINARY_NAME: &str = "upgrade-job"; -/// Upgrade job container name. -pub(crate) const UPGRADE_JOB_CONTAINER_NAME: &str = "mayastor-upgrade-job"; +pub(crate) use constants::upgrade_job_container_name; /// Defines the Label select for mayastor REST API. pub(crate) const API_REST_LABEL_SELECTOR: &str = "app=api-rest"; /// Defines the default helm chart release name. -pub(crate) const DEFAULT_RELEASE_NAME: &str = "mayastor"; +pub(crate) const DEFAULT_RELEASE_NAME: &str = constants::DEFAULT_RELEASE_NAME; /// Volumes with one replica pub(crate) const SINGLE_REPLICA_VOLUME: u8 = 1; -/// IO_ENGINE_POD_LABEL is the Kubernetes Pod label set on mayastor-io-engine Pods. +/// IO_ENGINE_POD_LABEL is the Kubernetes Pod label set on io-engine Pods. pub(crate) const IO_ENGINE_POD_LABEL: &str = "app=io-engine"; -/// AGENT_CORE_POD_LABEL is the Kubernetes Pod label set on mayastor-agent-core Pods. +/// AGENT_CORE_POD_LABEL is the Kubernetes Pod label set on agent-core Pods. pub(crate) const AGENT_CORE_POD_LABEL: &str = "app=agent-core"; -/// API_REST_POD_LABEL is the Kubernetes Pod label set on mayastor-api-rest Pods. +/// API_REST_POD_LABEL is the Kubernetes Pod label set on api-rest Pods. pub(crate) const API_REST_POD_LABEL: &str = "app=api-rest"; -/// UPGRADE_EVENT_REASON is the reason field in upgrade job. -pub(crate) const UPGRADE_EVENT_REASON: &str = "MayastorUpgrade"; - -/// Installed release version. -pub(crate) const HELM_RELEASE_VERSION_LABEL: &str = "openebs.io/version"; - /// Upgrade to develop. pub(crate) const UPGRADE_TO_DEVELOP_BRANCH: &str = "develop"; diff --git a/k8s/upgrade/src/plugin/objects.rs b/k8s/upgrade/src/plugin/objects.rs index e64620d8b..6472979a1 100644 --- a/k8s/upgrade/src/plugin/objects.rs +++ b/k8s/upgrade/src/plugin/objects.rs @@ -1,10 +1,9 @@ use crate::{ plugin::constants::{ - upgrade_name_concat, UPGRADE_BINARY_NAME, UPGRADE_CONFIG_MAP, + upgrade_job_container_name, upgrade_name_concat, UPGRADE_BINARY_NAME, UPGRADE_CONFIG_MAP, UPGRADE_CONFIG_MAP_MOUNT_PATH, UPGRADE_CONFIG_MAP_NAME_SUFFIX, UPGRADE_JOB_CLUSTERROLEBINDING_NAME_SUFFIX, UPGRADE_JOB_CLUSTERROLE_NAME_SUFFIX, - UPGRADE_JOB_CONTAINER_NAME, UPGRADE_JOB_NAME_SUFFIX, - UPGRADE_JOB_SERVICEACCOUNT_NAME_SUFFIX, + UPGRADE_JOB_NAME_SUFFIX, UPGRADE_JOB_SERVICEACCOUNT_NAME_SUFFIX, }, upgrade::UpgradeArgs, upgrade_labels, @@ -321,7 +320,7 @@ pub(crate) fn upgrade_job( args: Some(job_args), image: Some(upgrade_image), image_pull_policy, - name: UPGRADE_JOB_CONTAINER_NAME.to_string(), + name: upgrade_job_container_name(), env: Some(vec![ EnvVar { name: "RUST_LOG".to_string(), diff --git a/k8s/upgrade/src/plugin/upgrade.rs b/k8s/upgrade/src/plugin/upgrade.rs index d8c80a884..05dcf4c4d 100644 --- a/k8s/upgrade/src/plugin/upgrade.rs +++ b/k8s/upgrade/src/plugin/upgrade.rs @@ -1,13 +1,11 @@ use crate::plugin::{ constants::{ - get_image_version_tag, upgrade_event_selector, upgrade_image_concat, upgrade_name_concat, - AGENT_CORE_POD_LABEL, API_REST_LABEL_SELECTOR, API_REST_POD_LABEL, DEFAULT_IMAGE_REGISTRY, - DEFAULT_RELEASE_NAME, HELM_RELEASE_NAME_LABEL, HELM_RELEASE_VERSION_LABEL, - IO_ENGINE_POD_LABEL, MAX_RETRY_ATTEMPTS, UPGRADE_CONFIG_MAP_MOUNT_PATH, - UPGRADE_CONFIG_MAP_NAME_SUFFIX, UPGRADE_EVENT_REASON, + get_image_version_tag, upgrade_event_selector, upgrade_image_concat, upgrade_job_img, + upgrade_name_concat, AGENT_CORE_POD_LABEL, API_REST_LABEL_SELECTOR, API_REST_POD_LABEL, + DEFAULT_IMAGE_REGISTRY, DEFAULT_RELEASE_NAME, IO_ENGINE_POD_LABEL, MAX_RETRY_ATTEMPTS, + UPGRADE_CONFIG_MAP_MOUNT_PATH, UPGRADE_CONFIG_MAP_NAME_SUFFIX, UPGRADE_JOB_CLUSTERROLEBINDING_NAME_SUFFIX, UPGRADE_JOB_CLUSTERROLE_NAME_SUFFIX, - UPGRADE_JOB_IMAGE_NAME, UPGRADE_JOB_IMAGE_REPO, UPGRADE_JOB_NAME_SUFFIX, - UPGRADE_JOB_SERVICEACCOUNT_NAME_SUFFIX, + UPGRADE_JOB_IMAGE_REPO, UPGRADE_JOB_NAME_SUFFIX, UPGRADE_JOB_SERVICEACCOUNT_NAME_SUFFIX, }, error, objects, user_prompt::{ @@ -16,6 +14,8 @@ use crate::plugin::{ UPGRADE_DRY_RUN_SUMMARY, UPGRADE_JOB_STARTED, }, }; +use ::constants::helm_release_name_key; +use constants::upgrade_event_reason; use k8s_openapi::api::{ apps::v1::Deployment, batch::v1::Job, @@ -330,7 +330,7 @@ impl UpgradeEventClient { .await .context(error::ListEventsWithFieldSelector { field: selector })? .into_iter() - .filter(|e| e.reason == Some(UPGRADE_EVENT_REASON.to_string())) + .filter(|e| e.reason == Some(upgrade_event_reason())) .collect::>(); event_list.sort_by(|a, b| b.event_time.cmp(&a.event_time)); @@ -717,7 +717,7 @@ impl UpgradeResources { upgrade_image_concat( registry, UPGRADE_JOB_IMAGE_REPO, - UPGRADE_JOB_IMAGE_NAME, + &upgrade_job_img(), upgrade_job_image_tag.as_str(), ), self.release_name.clone(), @@ -834,7 +834,7 @@ pub(crate) async fn get_deployment_for_rest(ns: &str) -> error::Result error::Result { let deployment = get_deployment_for_rest(ns).await?; match &deployment.metadata.labels { - Some(label) => match label.get(HELM_RELEASE_NAME_LABEL) { + Some(label) => match label.get(&helm_release_name_key()) { Some(value) => Ok(value.to_string()), None => Ok(DEFAULT_RELEASE_NAME.to_string()), }, @@ -944,7 +944,7 @@ pub(crate) async fn get_source_version(ns: &str) -> error::Result { .metadata .labels .ok_or(error::NoDeploymentPresent.build())? - .get(HELM_RELEASE_VERSION_LABEL) + .get(&constants::helm_release_name_key()) .ok_or(error::NoDeploymentPresent.build())? .to_string(); Ok(value.to_string())