From 1ac55fcf1ffd4687fb4c5bf7f80b6577bd35382d Mon Sep 17 00:00:00 2001 From: Niladri Halder Date: Mon, 9 Dec 2024 09:48:13 +0000 Subject: [PATCH] refactor(upgrade): expose modules to pub scope Signed-off-by: Niladri Halder --- k8s/upgrade/src/bin/upgrade-job/main.rs | 9 +-- k8s/upgrade/src/bin/upgrade-job/opts.rs | 2 +- .../src/bin/upgrade-job/opts/validators.rs | 12 ++-- .../{upgrade.rs => product_upgrade.rs} | 24 ++----- .../src/{bin/upgrade-job => }/common.rs | 14 ++-- .../{bin/upgrade-job => }/common/constants.rs | 14 ++-- .../src/{bin/upgrade-job => }/common/error.rs | 7 +- .../src/{bin/upgrade-job => }/common/file.rs | 2 +- .../src/{bin/upgrade-job => }/common/kube.rs | 2 +- .../upgrade-job => }/common/kube/client.rs | 35 +++++----- .../{bin/upgrade-job => }/common/macros.rs | 2 + .../src/{bin/upgrade-job => }/common/regex.rs | 7 +- .../upgrade-job => }/common/rest_client.rs | 8 +-- .../src/{bin/upgrade-job => }/events.rs | 2 +- .../upgrade-job => }/events/event_recorder.rs | 30 ++++----- k8s/upgrade/src/{bin/upgrade-job => }/helm.rs | 6 +- .../src/{bin/upgrade-job => }/helm/chart.rs | 28 +++++--- .../src/{bin/upgrade-job => }/helm/client.rs | 64 +++++++++---------- .../src/{bin/upgrade-job => }/helm/upgrade.rs | 38 +++++------ .../src/{bin/upgrade-job => }/helm/values.rs | 0 .../src/{bin/upgrade-job => }/helm/yaml.rs | 0 .../src/{bin/upgrade-job => }/helm/yaml/yq.rs | 23 ++++--- k8s/upgrade/src/lib.rs | 13 ++++ .../data_plane.rs => upgrade_data_plane.rs} | 4 +- .../upgrade/path.rs => upgrade_path.rs} | 9 ++- .../upgrade/utils.rs => upgrade_utils.rs} | 0 26 files changed, 184 insertions(+), 171 deletions(-) rename k8s/upgrade/src/bin/upgrade-job/{upgrade.rs => product_upgrade.rs} (95%) rename k8s/upgrade/src/{bin/upgrade-job => }/common.rs (67%) rename k8s/upgrade/src/{bin/upgrade-job => }/common/constants.rs (83%) rename k8s/upgrade/src/{bin/upgrade-job => }/common/error.rs (99%) rename k8s/upgrade/src/{bin/upgrade-job => }/common/file.rs (88%) rename k8s/upgrade/src/{bin/upgrade-job => }/common/kube.rs (74%) rename k8s/upgrade/src/{bin/upgrade-job => }/common/kube/client.rs (91%) rename k8s/upgrade/src/{bin/upgrade-job => }/common/macros.rs (88%) rename k8s/upgrade/src/{bin/upgrade-job => }/common/regex.rs (81%) rename k8s/upgrade/src/{bin/upgrade-job => }/common/rest_client.rs (78%) rename k8s/upgrade/src/{bin/upgrade-job => }/events.rs (67%) rename k8s/upgrade/src/{bin/upgrade-job => }/events/event_recorder.rs (90%) rename k8s/upgrade/src/{bin/upgrade-job => }/helm.rs (85%) rename k8s/upgrade/src/{bin/upgrade-job => }/helm/chart.rs (96%) rename k8s/upgrade/src/{bin/upgrade-job => }/helm/client.rs (88%) rename k8s/upgrade/src/{bin/upgrade-job => }/helm/upgrade.rs (93%) rename k8s/upgrade/src/{bin/upgrade-job => }/helm/values.rs (100%) rename k8s/upgrade/src/{bin/upgrade-job => }/helm/yaml.rs (100%) rename k8s/upgrade/src/{bin/upgrade-job => }/helm/yaml/yq.rs (97%) rename k8s/upgrade/src/{bin/upgrade-job/upgrade/data_plane.rs => upgrade_data_plane.rs} (99%) rename k8s/upgrade/src/{bin/upgrade-job/upgrade/path.rs => upgrade_path.rs} (86%) rename k8s/upgrade/src/{bin/upgrade-job/upgrade/utils.rs => upgrade_utils.rs} (100%) diff --git a/k8s/upgrade/src/bin/upgrade-job/main.rs b/k8s/upgrade/src/bin/upgrade-job/main.rs index a2447fce3..c1c4f30f2 100644 --- a/k8s/upgrade/src/bin/upgrade-job/main.rs +++ b/k8s/upgrade/src/bin/upgrade-job/main.rs @@ -1,24 +1,21 @@ use crate::{ - common::{constants::product_train, error::Result}, opts::validators::{ validate_helm_chart_dir, validate_helm_release, validate_helmv3_in_path, validate_namespace, validate_rest_endpoint, }, - upgrade::upgrade, + product_upgrade::upgrade, }; use clap::Parser; use opts::CliArgs; use tracing::{error, info}; +use upgrade::common::{constants::product_train, error::Result}; use utils::{ print_package_info, raw_version_str, tracing_telemetry::{default_tracing_tags, flush_traces, TracingTelemetry}, }; -mod common; -mod events; -mod helm; mod opts; -mod upgrade; +mod product_upgrade; #[tokio::main] async fn main() -> Result<()> { diff --git a/k8s/upgrade/src/bin/upgrade-job/opts.rs b/k8s/upgrade/src/bin/upgrade-job/opts.rs index a9083ea0d..a2e92dc99 100644 --- a/k8s/upgrade/src/bin/upgrade-job/opts.rs +++ b/k8s/upgrade/src/bin/upgrade-job/opts.rs @@ -1,6 +1,6 @@ -use crate::common::constants::product_train; use clap::Parser; use std::path::PathBuf; +use upgrade::common::constants::product_train; use utils::{package_description, tracing_telemetry::FmtStyle, version_info_str}; /// Validate input whose validation depends on other inputs. diff --git a/k8s/upgrade/src/bin/upgrade-job/opts/validators.rs b/k8s/upgrade/src/bin/upgrade-job/opts/validators.rs index d62ead99e..b385f53a6 100644 --- a/k8s/upgrade/src/bin/upgrade-job/opts/validators.rs +++ b/k8s/upgrade/src/bin/upgrade-job/opts/validators.rs @@ -1,4 +1,8 @@ -use crate::{ +use regex::bytes::Regex; +use snafu::{ensure, ResultExt}; +use std::{fs, path::PathBuf, process::Command, str}; +use tracing::debug; +use upgrade::{ common::{ constants::CORE_CHART_NAME, error::{ @@ -8,15 +12,11 @@ use crate::{ YamlParseFromFile, }, kube::client as KubeClient, + macros::vec_to_strings, rest_client::RestClientSet, }, helm::chart::Chart, - vec_to_strings, }; -use regex::bytes::Regex; -use snafu::{ensure, ResultExt}; -use std::{fs, path::PathBuf, process::Command, str}; -use tracing::debug; /// Validate that the helm release specified in the CLI options exists in the namespace, /// which is also specified in the CLI options. diff --git a/k8s/upgrade/src/bin/upgrade-job/upgrade.rs b/k8s/upgrade/src/bin/upgrade-job/product_upgrade.rs similarity index 95% rename from k8s/upgrade/src/bin/upgrade-job/upgrade.rs rename to k8s/upgrade/src/bin/upgrade-job/product_upgrade.rs index 196bb2c85..77a31329f 100644 --- a/k8s/upgrade/src/bin/upgrade-job/upgrade.rs +++ b/k8s/upgrade/src/bin/upgrade-job/product_upgrade.rs @@ -1,4 +1,8 @@ -use crate::{ +use crate::opts::CliArgs; +use constants::DS_CONTROLLER_REVISION_HASH_LABEL_KEY; +use semver::Version; +use tracing::error; +use upgrade::{ common::{ constants::{ product_train, CORE_CHART_NAME, IO_ENGINE_LABEL, PARTIAL_REBUILD_DISABLE_EXTENTS, @@ -8,22 +12,8 @@ use crate::{ }, events::event_recorder::{EventAction, EventRecorder}, helm::upgrade::{HelmUpgradeRunner, HelmUpgraderBuilder}, - opts::CliArgs, + upgrade_data_plane::upgrade_data_plane, }; -use constants::DS_CONTROLLER_REVISION_HASH_LABEL_KEY; -use data_plane::upgrade_data_plane; - -use semver::Version; -use tracing::error; - -/// Contains the data-plane upgrade logic. -pub(crate) mod data_plane; - -/// Contains upgrade utilities. -pub(crate) mod utils; - -/// Tools to validate upgrade path. -pub(crate) mod path; /// This function starts and sees upgrade through to the end. pub(crate) async fn upgrade(opts: &CliArgs) -> Result<()> { @@ -190,7 +180,7 @@ fn partial_rebuild_check(source_version: &Version, partial_rebuild_is_enabled: b mod tests { #[test] fn test_partial_rebuild_check() { - use crate::upgrade::partial_rebuild_check; + use crate::product_upgrade::partial_rebuild_check; use semver::Version; let source = Version::new(2, 1, 0); diff --git a/k8s/upgrade/src/bin/upgrade-job/common.rs b/k8s/upgrade/src/common.rs similarity index 67% rename from k8s/upgrade/src/bin/upgrade-job/common.rs rename to k8s/upgrade/src/common.rs index 01df88a9e..f4a24a299 100644 --- a/k8s/upgrade/src/bin/upgrade-job/common.rs +++ b/k8s/upgrade/src/common.rs @@ -1,20 +1,20 @@ /// Contains constant values which are used as arguments to functions and in log messages. -pub(crate) mod constants; +pub mod constants; /// Contains the error handling tooling. -pub(crate) mod error; +pub mod error; /// Contains tools to work with Kubernetes APIs. -pub(crate) mod kube; +pub mod kube; /// Contains macros. -pub(crate) mod macros; +pub mod macros; /// Contains tools to create storage API clients. -pub(crate) mod rest_client; +pub mod rest_client; /// Contains tools for working with files. -pub(crate) mod file; +pub mod file; /// Contains a wrapper around regex::Regex. -pub(crate) mod regex; +pub mod regex; diff --git a/k8s/upgrade/src/bin/upgrade-job/common/constants.rs b/k8s/upgrade/src/common/constants.rs similarity index 83% rename from k8s/upgrade/src/bin/upgrade-job/common/constants.rs rename to k8s/upgrade/src/common/constants.rs index 293802e6c..518cf58e7 100644 --- a/k8s/upgrade/src/bin/upgrade-job/common/constants.rs +++ b/k8s/upgrade/src/common/constants.rs @@ -5,24 +5,24 @@ pub use constants::product_train; /// 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 = constants::UMBRELLA_CHART_NAME; +pub 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 = constants::PRODUCT_NAME; +pub 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"; +pub const IO_ENGINE_LABEL: &str = "app=io-engine"; /// This is the shared Pod label of the -agent-core Deployment. -pub(crate) const AGENT_CORE_LABEL: &str = "app=agent-core"; +pub const AGENT_CORE_LABEL: &str = "app=agent-core"; /// This is the label set on a storage API Node resource when a 'Node Drain' is issued. -pub fn drain_for_upgrade() -> String { +pub(crate) 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 fn cordon_ana_check() -> String { +pub(crate) fn cordon_ana_check() -> String { format!("{CORE_CHART_NAME}-upgrade-nvme-ana-check") } @@ -34,7 +34,7 @@ pub(crate) const UMBRELLA_CHART_UPGRADE_DOCS_URL: &str = constants::UMBRELLA_CHA pub(crate) const KUBE_API_PAGE_SIZE: u32 = 500; /// The Core chart version limits for requiring partial rebuild to be disabled for upgrade. -pub(crate) const PARTIAL_REBUILD_DISABLE_EXTENTS: (Version, Version) = +pub const PARTIAL_REBUILD_DISABLE_EXTENTS: (Version, Version) = (Version::new(2, 2, 0), Version::new(2, 5, 0)); /// Version value for the earliest possible 2.0 release. diff --git a/k8s/upgrade/src/bin/upgrade-job/common/error.rs b/k8s/upgrade/src/common/error.rs similarity index 99% rename from k8s/upgrade/src/bin/upgrade-job/common/error.rs rename to k8s/upgrade/src/common/error.rs index 072252df4..ff771c0a9 100644 --- a/k8s/upgrade/src/bin/upgrade-job/common/error.rs +++ b/k8s/upgrade/src/common/error.rs @@ -14,9 +14,10 @@ use url::Url; /// defined withing the same scope and must return to the outer scope (calling scope) using /// the try operator -- '?'. #[derive(Debug, Snafu)] -#[snafu(visibility(pub(crate)))] +#[snafu(visibility(pub))] #[snafu(context(suffix(false)))] -pub(crate) enum Error { +#[allow(unused)] +pub enum Error { /// Error for when the storage REST API URL is parsed. #[snafu(display( "Failed to parse {} REST API URL {rest_endpoint}: {source}", @@ -665,4 +666,4 @@ pub(crate) enum Error { } /// A wrapper type to remove repeated Result returns. -pub(crate) type Result = std::result::Result; +pub type Result = std::result::Result; diff --git a/k8s/upgrade/src/bin/upgrade-job/common/file.rs b/k8s/upgrade/src/common/file.rs similarity index 88% rename from k8s/upgrade/src/bin/upgrade-job/common/file.rs rename to k8s/upgrade/src/common/file.rs index 1b3d81727..e920353e0 100644 --- a/k8s/upgrade/src/bin/upgrade-job/common/file.rs +++ b/k8s/upgrade/src/common/file.rs @@ -5,7 +5,7 @@ use tempfile::NamedTempFile as TempFile; /// Write buffer to an existing temporary file if a path is provided as an argument, else /// create a new temporary file and write to it. Returns the file handle. -pub(crate) fn write_to_tempfile

(file_dir: Option

, buf: &[u8]) -> Result +pub fn write_to_tempfile

(file_dir: Option

, buf: &[u8]) -> Result where P: AsRef, { diff --git a/k8s/upgrade/src/bin/upgrade-job/common/kube.rs b/k8s/upgrade/src/common/kube.rs similarity index 74% rename from k8s/upgrade/src/bin/upgrade-job/common/kube.rs rename to k8s/upgrade/src/common/kube.rs index 526490322..db4cd93ee 100644 --- a/k8s/upgrade/src/bin/upgrade-job/common/kube.rs +++ b/k8s/upgrade/src/common/kube.rs @@ -1,2 +1,2 @@ /// This contains tools for working with the Kubernetes REST API. -pub(crate) mod client; +pub mod client; diff --git a/k8s/upgrade/src/bin/upgrade-job/common/kube/client.rs b/k8s/upgrade/src/common/kube/client.rs similarity index 91% rename from k8s/upgrade/src/bin/upgrade-job/common/kube/client.rs rename to k8s/upgrade/src/common/kube/client.rs index c887417d7..045436c54 100644 --- a/k8s/upgrade/src/bin/upgrade-job/common/kube/client.rs +++ b/k8s/upgrade/src/common/kube/client.rs @@ -23,46 +23,46 @@ use serde::de::DeserializeOwned; use snafu::{ensure, ErrorCompat, IntoError, ResultExt}; /// Generate a new kube::Client. -pub(crate) async fn client() -> Result { +pub async fn client() -> Result { Client::try_default().await.context(K8sClientGeneration) } /// Generate the Node api client. -pub(crate) async fn nodes_api() -> Result> { +pub async fn nodes_api() -> Result> { Ok(Api::all(client().await?)) } /// Generate the Namespace api client. -pub(crate) async fn namespaces_api() -> Result> { +pub async fn namespaces_api() -> Result> { Ok(Api::all(client().await?)) } /// Generate the CustomResourceDefinition api client. -pub(crate) async fn crds_api() -> Result> { +pub async fn crds_api() -> Result> { Ok(Api::all(client().await?)) } /// Generate ControllerRevision api client. -pub(crate) async fn controller_revisions_api(namespace: &str) -> Result> { +pub async fn controller_revisions_api(namespace: &str) -> Result> { Ok(Api::namespaced(client().await?, namespace)) } /// Generate the Pod api client. -pub(crate) async fn pods_api(namespace: &str) -> Result> { +pub async fn pods_api(namespace: &str) -> Result> { Ok(Api::namespaced(client().await?, namespace)) } /// Generate the Secret api client. -pub(crate) async fn secrets_api(namespace: &str) -> Result> { +pub async fn secrets_api(namespace: &str) -> Result> { Ok(Api::namespaced(client().await?, namespace)) } /// Generate the Configmap api client. -pub(crate) async fn configmaps_api(namespace: &str) -> Result> { +pub async fn configmaps_api(namespace: &str) -> Result> { Ok(Api::namespaced(client().await?, namespace)) } -pub(crate) async fn list_pods( +pub async fn list_pods( namespace: String, label_selector: Option, field_selector: Option, @@ -91,7 +91,7 @@ pub(crate) async fn list_pods( } /// List Nodes metadata in the kubernetes cluster. -pub(crate) async fn list_nodes_metadata( +pub async fn list_nodes_metadata( label_selector: Option, field_selector: Option, ) -> Result>> { @@ -124,7 +124,7 @@ pub(crate) async fn list_nodes_metadata( } /// List ControllerRevisions in a Kubernetes namespace. -pub(crate) async fn list_controller_revisions( +pub async fn list_controller_revisions( namespace: String, label_selector: Option, field_selector: Option, @@ -159,7 +159,7 @@ pub(crate) async fn list_controller_revisions( } /// Returns the controller-revision-hash of the latest revision of a resource's ControllerRevisions. -pub(crate) async fn latest_controller_revision_hash( +pub async fn latest_controller_revision_hash( namespace: String, label_selector: Option, field_selector: Option, @@ -199,7 +199,7 @@ pub(crate) async fn latest_controller_revision_hash( } /// This returns a list of Secrets based on filtering criteria. Returns all if criteria is absent. -pub(crate) async fn list_secrets( +pub async fn list_secrets( namespace: String, label_selector: Option, field_selector: Option, @@ -235,7 +235,7 @@ pub(crate) async fn list_secrets( /// This returns a list of ConfigMaps based on filtering criteria. Returns all if criteria is /// absent. -pub(crate) async fn list_configmaps( +pub async fn list_configmaps( namespace: String, label_selector: Option, field_selector: Option, @@ -270,10 +270,7 @@ pub(crate) async fn list_configmaps( } /// GET the helm release secret for a helm release in a namespace. -pub(crate) async fn get_helm_release_secret( - release_name: String, - namespace: String, -) -> Result { +pub async fn get_helm_release_secret(release_name: String, namespace: String) -> Result { let secrets = list_secrets( namespace.clone(), Some(format!("name={release_name},status=deployed")), @@ -294,7 +291,7 @@ pub(crate) async fn get_helm_release_secret( } /// GET the helm release configmap for a helm release in a namespace. -pub(crate) async fn get_helm_release_configmap( +pub async fn get_helm_release_configmap( release_name: String, namespace: String, ) -> Result { diff --git a/k8s/upgrade/src/bin/upgrade-job/common/macros.rs b/k8s/upgrade/src/common/macros.rs similarity index 88% rename from k8s/upgrade/src/bin/upgrade-job/common/macros.rs rename to k8s/upgrade/src/common/macros.rs index 9466b44ad..b64805258 100644 --- a/k8s/upgrade/src/bin/upgrade-job/common/macros.rs +++ b/k8s/upgrade/src/common/macros.rs @@ -3,3 +3,5 @@ macro_rules! vec_to_strings { ($($x:expr),*) => (vec![$($x.to_string()),*]); } + +pub use vec_to_strings; diff --git a/k8s/upgrade/src/bin/upgrade-job/common/regex.rs b/k8s/upgrade/src/common/regex.rs similarity index 81% rename from k8s/upgrade/src/bin/upgrade-job/common/regex.rs rename to k8s/upgrade/src/common/regex.rs index b64346049..351e61b81 100644 --- a/k8s/upgrade/src/bin/upgrade-job/common/regex.rs +++ b/k8s/upgrade/src/common/regex.rs @@ -3,7 +3,7 @@ use regex::Regex as BackendRegex; use snafu::ResultExt; /// This is a wrapper around regex::Regex. -pub(crate) struct Regex { +pub struct Regex { inner: BackendRegex, } @@ -11,10 +11,11 @@ impl Regex { /// This is a wrapper around regex::Regex::new(). It handles errors, so that crate-wide /// if statements can look prettier: /// + /// use upgrade::common::regex::Regex /// if Regex::new(r"^yay$")?.is_match("yay") { /// todo!(); /// } - pub(crate) fn new(expr: &str) -> Result { + pub fn new(expr: &str) -> Result { let regex = BackendRegex::new(expr).context(RegexCompile { expression: expr.to_string(), })?; @@ -23,7 +24,7 @@ impl Regex { } /// This is a wrapper around regex::Regex::is_match(). - pub(crate) fn is_match(&self, haystack: &str) -> bool { + pub fn is_match(&self, haystack: &str) -> bool { self.inner.is_match(haystack) } } diff --git a/k8s/upgrade/src/bin/upgrade-job/common/rest_client.rs b/k8s/upgrade/src/common/rest_client.rs similarity index 78% rename from k8s/upgrade/src/bin/upgrade-job/common/rest_client.rs rename to k8s/upgrade/src/common/rest_client.rs index 9d0918b38..1756c19b4 100644 --- a/k8s/upgrade/src/bin/upgrade-job/common/rest_client.rs +++ b/k8s/upgrade/src/common/rest_client.rs @@ -5,13 +5,13 @@ use std::time::Duration; use url::Url; /// This is a wrapper for the openapi::tower::client::ApiClient. -pub(crate) struct RestClientSet { +pub struct RestClientSet { client: ApiClient, } impl RestClientSet { /// Build the RestConfig, and the eventually the ApiClient. Fails if configuration is invalid. - pub(crate) fn new_with_url(rest_endpoint: String) -> Result { + pub fn new_with_url(rest_endpoint: String) -> Result { let rest_url = Url::try_from(rest_endpoint.as_str()).context(RestUrlParse { rest_endpoint })?; @@ -31,11 +31,11 @@ impl RestClientSet { Ok(RestClientSet { client }) } - pub(crate) fn nodes_api(&self) -> &dyn openapi::apis::nodes_api::tower::client::Nodes { + pub fn nodes_api(&self) -> &dyn openapi::apis::nodes_api::tower::client::Nodes { self.client.nodes_api() } - pub(crate) fn volumes_api(&self) -> &dyn openapi::apis::volumes_api::tower::client::Volumes { + pub fn volumes_api(&self) -> &dyn openapi::apis::volumes_api::tower::client::Volumes { self.client.volumes_api() } } diff --git a/k8s/upgrade/src/bin/upgrade-job/events.rs b/k8s/upgrade/src/events.rs similarity index 67% rename from k8s/upgrade/src/bin/upgrade-job/events.rs rename to k8s/upgrade/src/events.rs index a883324f0..aa8643fde 100644 --- a/k8s/upgrade/src/bin/upgrade-job/events.rs +++ b/k8s/upgrade/src/events.rs @@ -1,2 +1,2 @@ /// This contains the builder and the Events helper functions. -pub(crate) mod event_recorder; +pub mod event_recorder; diff --git a/k8s/upgrade/src/bin/upgrade-job/events/event_recorder.rs b/k8s/upgrade/src/events/event_recorder.rs similarity index 90% rename from k8s/upgrade/src/bin/upgrade-job/events/event_recorder.rs rename to k8s/upgrade/src/events/event_recorder.rs index 593d8e4bf..82307e5ed 100644 --- a/k8s/upgrade/src/bin/upgrade-job/events/event_recorder.rs +++ b/k8s/upgrade/src/events/event_recorder.rs @@ -16,7 +16,7 @@ use tracing::error; #[derive(Serialize, Debug)] #[serde(rename_all(serialize = "camelCase"))] -pub(crate) struct EventNote { +pub struct EventNote { from_version: String, to_version: String, message: String, @@ -41,7 +41,7 @@ impl EventNote { /// A builder for the Kubernetes event publisher. #[derive(Default)] -pub(crate) struct EventRecorderBuilder { +pub struct EventRecorderBuilder { pod_name: Option, namespace: Option, source_version: Option, @@ -52,7 +52,7 @@ impl EventRecorderBuilder { /// This is a builder option to set the namespace of the object /// which will become the 'involvedObject' for the Event. #[must_use] - pub(crate) fn with_namespace(mut self, namespace: T) -> Self + pub fn with_namespace(mut self, namespace: T) -> Self where T: ToString, { @@ -63,7 +63,7 @@ impl EventRecorderBuilder { /// This is a builder option to add the name of this Pod. The owner Job of this Pod /// will be the object whose events the publisher will create. #[must_use] - pub(crate) fn with_pod_name(mut self, pod_name: T) -> Self + pub fn with_pod_name(mut self, pod_name: T) -> Self where T: ToString, { @@ -74,7 +74,7 @@ impl EventRecorderBuilder { // TODO: Make the builder option validations error out at compile-time, using std::compile_error // or something similar. /// This builds the EventRecorder. This fails if Kubernetes API requests fail. - pub(crate) async fn build(&self) -> Result { + pub async fn build(&self) -> Result { ensure!( self.pod_name.is_some() && self.namespace.is_some(), EventRecorderOptionsAbsent @@ -172,7 +172,7 @@ impl EventRecorderBuilder { } /// This is a wrapper around a kube::runtime::events::Recorder. -pub(crate) struct EventRecorder { +pub struct EventRecorder { event_sender: Option>, event_loop_handle: tokio::task::JoinHandle<()>, source_version: String, @@ -181,7 +181,7 @@ pub(crate) struct EventRecorder { impl EventRecorder { /// Creates an empty builder. - pub(crate) fn builder() -> EventRecorderBuilder { + pub fn builder() -> EventRecorderBuilder { EventRecorderBuilder::default() } @@ -196,7 +196,7 @@ impl EventRecorder { /// This is a helper method with calls the publish method above and fills out the boilerplate /// Event fields. type is set to publish a Normal event. - pub(crate) async fn publish_normal(&self, note: J, action: K) -> Result<()> + pub async fn publish_normal(&self, note: J, action: K) -> Result<()> where J: ToString, K: ToString, @@ -215,7 +215,7 @@ impl EventRecorder { /// This is a helper method with calls the publish method above and fills out the boilerplate /// Event fields. type is set to publish a Warning event. - pub(crate) async fn publish_warning(&self, note: J, action: K) -> Result<()> + pub async fn publish_warning(&self, note: J, action: K) -> Result<()> where J: ToString, K: ToString, @@ -233,7 +233,7 @@ impl EventRecorder { } /// This method is intended for use when upgrade fails. - pub(crate) async fn publish_unrecoverable(&self, err: &Error, validation_error: bool) + pub async fn publish_unrecoverable(&self, err: &Error, validation_error: bool) where Error: Display, { @@ -249,7 +249,7 @@ impl EventRecorder { } /// Shuts down the event channel which makes the event loop worker exit its loop and return. - pub(crate) async fn shutdown_worker(mut self) { + pub async fn shutdown_worker(mut self) { // Dropping the sender, to signify no more channel messages. let _ = self.event_sender.take(); @@ -257,13 +257,13 @@ impl EventRecorder { let _ = self.event_loop_handle.await; } - /// Updates the EventRecorder's source_version memeber with a new value. - pub(crate) fn set_source_version(&mut self, version: String) { + /// Updates the EventRecorder's source_version member with a new value. + pub fn set_source_version(&mut self, version: String) { self.source_version = version } - /// Updates the EventRecorder's target_version memeber with a new value. - pub(crate) fn set_target_version(&mut self, version: String) { + /// Updates the EventRecorder's target_version member with a new value. + pub fn set_target_version(&mut self, version: String) { self.target_version = version } } diff --git a/k8s/upgrade/src/bin/upgrade-job/helm.rs b/k8s/upgrade/src/helm.rs similarity index 85% rename from k8s/upgrade/src/bin/upgrade-job/helm.rs rename to k8s/upgrade/src/helm.rs index 1687be328..fd01cbfb9 100644 --- a/k8s/upgrade/src/bin/upgrade-job/helm.rs +++ b/k8s/upgrade/src/helm.rs @@ -1,9 +1,9 @@ /// Contains the structs required to deserialize yaml files from the helm charts. -pub(crate) mod chart; +pub mod chart; /// Contains the HelmReleaseClient. Used for interacting with installed helm chart releases. -pub(crate) mod client; +pub mod client; /// Contains helm chart upgrade logic. -pub(crate) mod upgrade; +pub mod upgrade; /// Contains validation and logic to generate helm values options for the `helm upgrade` command. pub(crate) mod values; /// This contains tools for use with yaml files. diff --git a/k8s/upgrade/src/bin/upgrade-job/helm/chart.rs b/k8s/upgrade/src/helm/chart.rs similarity index 96% rename from k8s/upgrade/src/bin/upgrade-job/helm/chart.rs rename to k8s/upgrade/src/helm/chart.rs index 3b9889dfa..127314c03 100644 --- a/k8s/upgrade/src/bin/upgrade-job/helm/chart.rs +++ b/k8s/upgrade/src/helm/chart.rs @@ -7,7 +7,7 @@ use std::{fs::read, path::Path, str}; /// This struct is used to deserialize helm charts' Chart.yaml file. #[derive(Deserialize)] -pub(crate) struct Chart { +pub struct Chart { /// This is the name of the helm chart. name: String, /// This is the version of the helm chart. @@ -16,19 +16,19 @@ pub(crate) struct Chart { impl Chart { /// This is a getter for the helm chart name. - pub(crate) fn name(&self) -> &str { + pub fn name(&self) -> &str { self.name.as_str() } /// This is a getter for the helm chart version. - pub(crate) fn version(&self) -> &Version { + pub fn version(&self) -> &Version { &self.version } } /// This is a set of tools for types whose instances are created /// by deserializing a helm chart's values.yaml files. -pub(crate) trait HelmValuesCollection { +pub trait HelmValuesCollection { /// This is a getter for state of the 'ha' feature (enabled/disabled). fn ha_is_enabled(&self) -> bool; /// This is a getter for the partial-rebuild toggle value. @@ -299,6 +299,9 @@ impl CoreValues { self.base.deprecated_log_silence_level() } + /// Retrieves the image tag of the Jaeger operator. + /// Useful when updating the Jaeger operator dependency chart to ensure the new chart uses the + /// updated image tag. pub(crate) fn jaeger_operator_image_tag(&self) -> &str { self.jaeger_operator.image_tag() } @@ -317,6 +320,7 @@ impl Agents { self.ha.enabled() } + /// Returns true if partial rebuild is enabled. fn partial_rebuild_is_enabled(&self) -> bool { self.core.partial_rebuild_is_enabled() } @@ -325,6 +329,7 @@ impl Agents { /// This is used to deserialize the yaml object base. #[derive(Deserialize)] struct Base { + /// This is the older helm value.yaml key for configuring log silence level. #[serde(default, rename(deserialize = "logSilenceLevel"))] deprecated_log_silence_level: String, } @@ -344,6 +349,7 @@ struct Core { } impl Core { + /// Returns true if partial rebuild is enabled. fn partial_rebuild_is_enabled(&self) -> bool { self.rebuild.partial_is_enabled() } @@ -356,6 +362,7 @@ struct Rebuild { } impl Rebuild { + /// Returns true if partial rebuild is enabled. fn partial_is_enabled(&self) -> bool { self.partial.enabled() } @@ -373,9 +380,6 @@ impl Default for RebuildPartial { /// assuming that partial rebuild is enabled, if the YAML object for Rebuild is missing. /// The Rebuild type will be deserialized with a default value if it's absent from the /// helm values. - /// - /// #[serde(default)] - /// rebuild: Rebuild, fn default() -> Self { Self { enabled: true } } @@ -872,6 +876,7 @@ struct PrometheusAlertmanager { } impl PrometheusAlertmanager { + /// This is the prometheus alert manager container image tag. fn image_tag(&self) -> &str { self.image.tag() } @@ -885,6 +890,7 @@ struct PrometheusNodeExporter { } impl PrometheusNodeExporter { + /// This is the Prometheus Node Exporter container image tag. fn image_tag(&self) -> &str { self.image.tag() } @@ -898,6 +904,7 @@ struct PrometheusPushgateway { } impl PrometheusPushgateway { + /// This is the Prometheus Push gateway container image tag. fn image_tag(&self) -> &str { self.image.tag() } @@ -911,6 +918,7 @@ struct PrometheusServer { } impl PrometheusServer { + /// This is the Prometheus Server image tag. fn image_tag(&self) -> &str { self.image.tag() } @@ -941,10 +949,13 @@ impl Promtail { self.config.deprecated_extra_client_configs() } + /// This is the deprecated field for the loki address in an older loki-stack helm chart. fn deprecated_loki_address(&self) -> &str { self.config.deprecated_loki_address() } + /// This returns the promtail init container configuration from both the older deprecated + /// loki-stack chart and the newer loki-stack chart. fn init_container(&self) -> Vec { match &self.init_container { PromtailInitContainer::DeprecatedInitContainer {} => Vec::::default(), @@ -952,6 +963,7 @@ impl Promtail { } } + /// This returns the readiness probe http get path for the loki-stack promtail. fn readiness_probe_http_get_path(&self) -> String { self.readiness_probe .http_get @@ -1031,7 +1043,7 @@ impl Default for PromtailInitContainer { /// This is used to serialize the config.clients yaml object in promtail chart v6.13.1 /// when migrating from promtail v3.11.0 to v6.13.1. #[derive(Debug, Serialize)] -pub(crate) struct PromtailConfigClient { +pub struct PromtailConfigClient { url: String, } diff --git a/k8s/upgrade/src/bin/upgrade-job/helm/client.rs b/k8s/upgrade/src/helm/client.rs similarity index 88% rename from k8s/upgrade/src/bin/upgrade-job/helm/client.rs rename to k8s/upgrade/src/helm/client.rs index f5d9bc194..bc6634c63 100644 --- a/k8s/upgrade/src/bin/upgrade-job/helm/client.rs +++ b/k8s/upgrade/src/helm/client.rs @@ -1,15 +1,13 @@ -use crate::{ - common::{ - error::{ - Base64DecodeHelmStorage, DeserializaHelmStorageData, GzipDecoderReadToEnd, - HelmClientNs, HelmCommand, HelmGetValuesCommand, HelmListCommand, HelmRelease, - HelmStorageNoData, HelmStorageNoReleaseValue, HelmUpgradeCommand, - MissingMemberInHelmStorageData, NoHelmStorageDriver, Result, U8VectorToString, - UnsupportedStorageDriver, YamlParseFromSlice, - }, - kube::client as KubeClient, +use crate::common::{ + error::{ + Base64DecodeHelmStorage, DeserializaHelmStorageData, GzipDecoderReadToEnd, HelmClientNs, + HelmCommand, HelmGetValuesCommand, HelmListCommand, HelmRelease, HelmStorageNoData, + HelmStorageNoReleaseValue, HelmUpgradeCommand, MissingMemberInHelmStorageData, + NoHelmStorageDriver, Result, U8VectorToString, UnsupportedStorageDriver, + YamlParseFromSlice, }, - vec_to_strings, + kube::client as KubeClient, + macros::vec_to_strings, }; use base64::engine::{general_purpose::STANDARD, Engine as base64_engine}; use flate2::read::GzDecoder; @@ -34,37 +32,37 @@ macro_rules! extract_data { /// This is used to deserialize the JSON data in a helm storage resource (secret or configmap). #[derive(Debug, Deserialize)] -pub(crate) struct HelmChartRelease { +pub struct HelmChartRelease { chart: Option, } /// This is used to deserialize release.chart. #[derive(Debug, Deserialize)] -pub(crate) struct HelmChartReleaseChart { +pub struct HelmChartReleaseChart { metadata: HelmChartReleaseChartMetadata, } /// This is used to deserialize release.chart.metadata. #[derive(Debug, Deserialize)] -pub(crate) struct HelmChartReleaseChartMetadata { +pub struct HelmChartReleaseChartMetadata { dependencies: Option>, } /// This is used to deserialize release.chart.metadata.dependency[]. #[derive(Debug, Deserialize)] -pub(crate) struct HelmChartReleaseChartMetadataDependency { +pub struct HelmChartReleaseChartMetadataDependency { name: String, version: Option, } impl HelmChartReleaseChartMetadataDependency { /// Returns the name of the dependency chart. - pub(crate) fn name(&self) -> &str { + pub fn name(&self) -> &str { self.name.as_str() } /// Returns the version of the dependency chart. - pub(crate) fn version(self) -> Option { + pub fn version(self) -> Option { self.version } } @@ -104,26 +102,26 @@ fn dependencies_from_release_data( /// This struct is used to deserialize the output of `helm list -n --deployed -o yaml`. #[derive(Clone, Deserialize)] -pub(crate) struct HelmListReleaseElement { +pub struct HelmListReleaseElement { name: String, chart: String, } impl HelmListReleaseElement { /// This is a getter function for the name of the release. - pub(crate) fn name(&self) -> &str { + pub fn name(&self) -> &str { self.name.as_str() } /// This is a getter function for the chart_name of the release. This also containers the chart /// version. - pub(crate) fn chart(&self) -> &str { + pub fn chart(&self) -> &str { self.chart.as_str() } } /// This is a builder for HelmReleaseClient. #[derive(Default)] -pub(crate) struct HelmReleaseClientBuilder { +pub struct HelmReleaseClientBuilder { namespace: Option, storage_driver: Option, } @@ -132,7 +130,7 @@ impl HelmReleaseClientBuilder { /// This is a builder option to add Namespace. This is mandatory, /// because all helm releases are tied to a Namespace. #[must_use] - pub(crate) fn with_namespace(mut self, ns: J) -> Self + pub fn with_namespace(mut self, ns: J) -> Self where J: ToString, { @@ -142,13 +140,13 @@ impl HelmReleaseClientBuilder { /// Set the storage driver to use with helm commands. #[must_use] - pub(crate) fn with_storage_driver(mut self, driver: String) -> Self { + pub fn with_storage_driver(mut self, driver: String) -> Self { self.storage_driver = Some(driver); self } /// Build the HelmReleaseClient. - pub(crate) fn build(self) -> Result { + pub fn build(self) -> Result { let namespace = self.namespace.ok_or(HelmClientNs.build())?; let storage_driver = self.storage_driver.ok_or(NoHelmStorageDriver.build())?; Ok(HelmReleaseClient { @@ -161,21 +159,21 @@ impl HelmReleaseClientBuilder { /// This type has functions which execute helm commands to fetch info about and modify helm /// releases. #[derive(Clone)] -pub(crate) struct HelmReleaseClient { - pub(crate) namespace: String, +pub struct HelmReleaseClient { + pub namespace: String, /// This is the information that Helm stores on the cluster about the state of a helm release. /// Ref: https://github.com/helm/helm/blob/v3.15.0/pkg/action/action.go#L383 - pub(crate) storage_driver: String, + pub storage_driver: String, } impl HelmReleaseClient { /// This creates an empty builder. - pub(crate) fn builder() -> HelmReleaseClientBuilder { + pub fn builder() -> HelmReleaseClientBuilder { HelmReleaseClientBuilder::default() } /// Runs command `helm get values -n --all -o yaml`. - pub(crate) fn get_values_as_yaml( + pub fn get_values_as_yaml( &self, release_name: A, maybe_extra_args: Option>, @@ -229,7 +227,7 @@ impl HelmReleaseClient { } /// Runs command `helm list -n --deployed -o yaml`. - pub(crate) fn list_as_yaml( + pub fn list_as_yaml( &self, maybe_extra_args: Option>, ) -> Result> @@ -279,7 +277,7 @@ impl HelmReleaseClient { } /// Reads from the helm storage driver and returns a type with info. about dependencies. - pub(crate) async fn get_dependencies( + pub async fn get_dependencies( &self, release_name: &str, ) -> Result> { @@ -321,7 +319,7 @@ impl HelmReleaseClient { } /// Runs command `helm upgrade -n `. - pub(crate) async fn upgrade( + pub async fn upgrade( &self, release_name: A, chart_dir: P, @@ -375,7 +373,7 @@ impl HelmReleaseClient { } /// Fetches info about a Helm release in the Namespace, if it exists. - pub(crate) fn release_info(&self, release_name: A) -> Result + pub fn release_info(&self, release_name: A) -> Result where A: ToString, { diff --git a/k8s/upgrade/src/bin/upgrade-job/helm/upgrade.rs b/k8s/upgrade/src/helm/upgrade.rs similarity index 93% rename from k8s/upgrade/src/bin/upgrade-job/helm/upgrade.rs rename to k8s/upgrade/src/helm/upgrade.rs index 1c18c8b27..3191da610 100644 --- a/k8s/upgrade/src/bin/upgrade-job/helm/upgrade.rs +++ b/k8s/upgrade/src/helm/upgrade.rs @@ -6,6 +6,7 @@ use crate::{ InvalidUpgradePath, NoHelmStorageDriver, NoInputHelmChartDir, NotAKnownHelmChart, Result, RollbackForbidden, UmbrellaChartNotUpgraded, }, + macros::vec_to_strings, regex::Regex, }, helm::{ @@ -13,11 +14,10 @@ use crate::{ client::HelmReleaseClient, values::generate_values_yaml_file, }, - upgrade::path::{ - core_version_from_umbrella_release, is_valid_for_core_chart, version_from_chart_yaml_file, - version_from_core_chart_release, + upgrade_path::{ + core_version_from_umbrella_release, is_valid_for_core_chart, version_from_chart_name, + version_from_chart_yaml_file, }, - vec_to_strings, }; use async_trait::async_trait; use semver::Version; @@ -28,14 +28,13 @@ use tracing::info; /// HelmUpgradeRunner is returned after an upgrade is validated and dry-run-ed. Running /// it carries out helm upgrade. -pub(crate) type HelmUpgradeRunner = - Pin>>>>; +pub type HelmUpgradeRunner = Pin>>>>; /// A trait object of type HelmUpgrader is either CoreHelmUpgrader or an UmbrellaHelmUpgrader. /// They either deal with upgrading the Core helm chart or the Umbrella helm chart respectively. /// The Umbrella helm chart is not upgraded using this binary, as it is out of scope. #[async_trait] -pub(crate) trait HelmUpgrader { +pub trait HelmUpgrader { /// Returns a closure which runs the real upgrade, post-dry-run. async fn dry_run(self: Box) -> Result; @@ -48,7 +47,7 @@ pub(crate) trait HelmUpgrader { /// This is a builder for the Helm chart upgrade. #[derive(Default)] -pub(crate) struct HelmUpgraderBuilder { +pub struct HelmUpgraderBuilder { release_name: Option, namespace: Option, core_chart_dir: Option, @@ -63,7 +62,7 @@ pub(crate) struct HelmUpgraderBuilder { impl HelmUpgraderBuilder { /// This is a builder option to add the Namespace of the helm chart to be upgraded. #[must_use] - pub(crate) fn with_namespace(mut self, ns: J) -> Self + pub fn with_namespace(mut self, ns: J) -> Self where J: ToString, { @@ -73,7 +72,7 @@ impl HelmUpgraderBuilder { /// This is a builder option to add the release name of the helm chart to be upgraded. #[must_use] - pub(crate) fn with_release_name(mut self, release_name: J) -> Self + pub fn with_release_name(mut self, release_name: J) -> Self where J: ToString, { @@ -83,23 +82,20 @@ impl HelmUpgraderBuilder { /// This is a builder option to set the directory path of the Umbrella helm chart CLI option. #[must_use] - pub(crate) fn with_core_chart_dir(mut self, dir: PathBuf) -> Self { + pub fn with_core_chart_dir(mut self, dir: PathBuf) -> Self { self.core_chart_dir = Some(dir); self } /// This sets the flag to skip upgrade path validation. #[must_use] - pub(crate) fn with_skip_upgrade_path_validation( - mut self, - skip_upgrade_path_validation: bool, - ) -> Self { + pub fn with_skip_upgrade_path_validation(mut self, skip_upgrade_path_validation: bool) -> Self { self.skip_upgrade_path_validation = skip_upgrade_path_validation; self } /// This is a builder option to add set flags during helm upgrade. - pub(crate) fn with_helm_args_set(mut self, helm_args_set: J) -> Self + pub fn with_helm_args_set(mut self, helm_args_set: J) -> Self where J: ToString, { @@ -108,7 +104,7 @@ impl HelmUpgraderBuilder { } /// This is a builder option to add set-file options during helm upgrade. - pub(crate) fn with_helm_args_set_file(mut self, helm_args_set_file: J) -> Self + pub fn with_helm_args_set_file(mut self, helm_args_set_file: J) -> Self where J: ToString, { @@ -118,19 +114,19 @@ impl HelmUpgraderBuilder { /// This is a builder option to add the value of the helm storage driver. #[must_use] - pub(crate) fn with_helm_storage_driver(mut self, driver: String) -> Self { + pub fn with_helm_storage_driver(mut self, driver: String) -> Self { self.helm_storage_driver = Some(driver); self } /// This is a builder option to enable the use of the helm --reset-then-reuse-values flag. - pub(crate) fn with_helm_reset_then_reuse_values(mut self, use_it: bool) -> Self { + pub fn with_helm_reset_then_reuse_values(mut self, use_it: bool) -> Self { self.helm_reset_then_reuse_values = use_it; self } /// This builds the HelmUpgrade object. - pub(crate) async fn build(self) -> Result> { + pub async fn build(self) -> Result> { // Unwrapping builder inputs. Fails for mandatory inputs. let release_name = self .release_name @@ -220,7 +216,7 @@ impl HelmUpgraderBuilder { } else if Regex::new(core_regex.as_str())?.is_match(chart) { // The version of the Core helm chart (installed as the parent chart) // which is installed in the cluster. - let source_version = version_from_core_chart_release(chart)?; + let source_version = version_from_chart_name(chart)?; info!(version=%source_version, "Found version of chart {CORE_CHART_NAME}"); // Skip upgrade-path validation and allow all upgrades for the Core helm chart, if diff --git a/k8s/upgrade/src/bin/upgrade-job/helm/values.rs b/k8s/upgrade/src/helm/values.rs similarity index 100% rename from k8s/upgrade/src/bin/upgrade-job/helm/values.rs rename to k8s/upgrade/src/helm/values.rs diff --git a/k8s/upgrade/src/bin/upgrade-job/helm/yaml.rs b/k8s/upgrade/src/helm/yaml.rs similarity index 100% rename from k8s/upgrade/src/bin/upgrade-job/helm/yaml.rs rename to k8s/upgrade/src/helm/yaml.rs diff --git a/k8s/upgrade/src/bin/upgrade-job/helm/yaml/yq.rs b/k8s/upgrade/src/helm/yaml/yq.rs similarity index 97% rename from k8s/upgrade/src/bin/upgrade-job/helm/yaml/yq.rs rename to k8s/upgrade/src/helm/yaml/yq.rs index 9b62fc305..b34e1c4bf 100644 --- a/k8s/upgrade/src/bin/upgrade-job/helm/yaml/yq.rs +++ b/k8s/upgrade/src/helm/yaml/yq.rs @@ -1,10 +1,10 @@ -use crate::{ - common::error::{ +use crate::common::{ + error::{ NotAValidYamlKeyForStringValue, NotYqV4, RegexCompile, Result, U8VectorToString, YqAppendToArrayCommand, YqAppendToObjectCommand, YqCommandExec, YqDeleteObjectCommand, YqMergeCommand, YqSetCommand, YqVersionCommand, }, - vec_to_strings, + macros::vec_to_strings, }; use regex::Regex; use snafu::{ensure, ResultExt}; @@ -192,31 +192,34 @@ impl YqV4 { /// this function is the one called 'high_priority' and the other file is the 'low_priority' /// one. /// E.g: - /// high_priority file: - /// =================== + /// // high_priority_file: + /// ```yaml /// foo: /// bar: "foobar" /// baz: /// - "alpha" /// - "beta" + /// ``` /// - /// low_priority file: - /// ================== + /// // low_priority_file: + /// ```yaml /// foo: /// bar: "foobaz" /// baz: /// - "gamma" /// - "delta" - /// friend: "ferris" + /// friend: "ferris" + /// ``` /// - /// result: - /// ======= + /// // result: + /// ```yaml /// foo: /// bar: "foobar" /// baz: /// - "alpha" /// - "beta" /// friend: "ferris" + /// ``` /// /// Special case: When the default value has changed, and the user has not customised that /// option, special upgrade values yaml updates have to be added to single out specific cases diff --git a/k8s/upgrade/src/lib.rs b/k8s/upgrade/src/lib.rs index 8e1789b41..ccc0f5c2f 100644 --- a/k8s/upgrade/src/lib.rs +++ b/k8s/upgrade/src/lib.rs @@ -11,3 +11,16 @@ pub use plugin::constants; /// Module for upgrade client errors. pub use plugin::error; + +/// Contains libraries for error handling, interacting with k8s, etc. +pub mod common; +/// Contains APIs for publishing progress on to kubernetes Events. +pub mod events; +/// Contains APIs for interacting with helm releases and registries. +pub mod helm; +/// Contains the data-plane upgrade logic. +pub mod upgrade_data_plane; +/// Tools to validate upgrade path. +pub mod upgrade_path; +/// Contains upgrade utilities. +pub(crate) mod upgrade_utils; diff --git a/k8s/upgrade/src/bin/upgrade-job/upgrade/data_plane.rs b/k8s/upgrade/src/upgrade_data_plane.rs similarity index 99% rename from k8s/upgrade/src/bin/upgrade-job/upgrade/data_plane.rs rename to k8s/upgrade/src/upgrade_data_plane.rs index 7d7200651..52a22fd1a 100644 --- a/k8s/upgrade/src/bin/upgrade-job/upgrade/data_plane.rs +++ b/k8s/upgrade/src/upgrade_data_plane.rs @@ -10,7 +10,7 @@ use crate::{ kube::client as KubeClient, rest_client::RestClientSet, }, - upgrade::utils::{ + upgrade_utils::{ all_pods_are_ready, cordon_storage_node, list_all_volumes, rebuild_result, uncordon_storage_node, RebuildResult, }, @@ -26,7 +26,7 @@ use tracing::info; 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( +pub async fn upgrade_data_plane( namespace: String, rest_endpoint: String, latest_io_engine_ctrl_rev_hash: String, diff --git a/k8s/upgrade/src/bin/upgrade-job/upgrade/path.rs b/k8s/upgrade/src/upgrade_path.rs similarity index 86% rename from k8s/upgrade/src/bin/upgrade-job/upgrade/path.rs rename to k8s/upgrade/src/upgrade_path.rs index 432f2c9d8..016ab413c 100644 --- a/k8s/upgrade/src/bin/upgrade-job/upgrade/path.rs +++ b/k8s/upgrade/src/upgrade_path.rs @@ -16,14 +16,14 @@ use std::{fs, path::PathBuf}; /// Validates the upgrade path from 'from' Version to 'to' Version for the Core helm chart. pub(crate) fn is_valid_for_core_chart(from: &Version) -> Result { let unsupported_version_buf = - &include_bytes!("../../../../../upgrade/config/unsupported_versions.yaml")[..]; + &include_bytes!("../../upgrade/config/unsupported_versions.yaml")[..]; let unsupported_versions = UnsupportedVersions::try_from(unsupported_version_buf) .context(YamlParseBufferForUnsupportedVersion)?; Ok(!unsupported_versions.contains(from)) } /// Generate a semver::Version from the helm chart in local directory. -pub(crate) fn version_from_chart_yaml_file(path: PathBuf) -> Result { +pub fn version_from_chart_yaml_file(path: PathBuf) -> Result { let values_yaml = fs::read(path.as_path()).context(ReadingFile { filepath: path.clone(), })?; @@ -36,7 +36,7 @@ pub(crate) fn version_from_chart_yaml_file(path: PathBuf) -> Result { /// Generate a semver::Version from the 'chart' member of the Helm chart's ReleaseElement. /// The output of `helm ls -n -o yaml` is a list of ReleaseElements. -pub(crate) fn version_from_core_chart_release(chart_name: &str) -> Result { +pub fn version_from_chart_name(chart_name: &str) -> Result { let delimiter: char = '-'; // e.g. -1.2.3-rc.5 -- here the 2nd chunk is the version let (_, version) = chart_name.split_once(delimiter).ok_or( @@ -52,6 +52,9 @@ pub(crate) fn version_from_core_chart_release(chart_name: &str) -> Result