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 834284ba6..8c0b0e257 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, @@ -7,23 +11,11 @@ use crate::{ kube::client as KubeClient, }, events::event_recorder::{EventAction, EventRecorder}, +}; +use upgrade::{ 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 +182,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 67% rename from k8s/upgrade/src/bin/upgrade-job/common/constants.rs rename to k8s/upgrade/src/common/constants.rs index a4c87a022..4d2b65367 100644 --- a/k8s/upgrade/src/bin/upgrade-job/common/constants.rs +++ b/k8s/upgrade/src/common/constants.rs @@ -5,16 +5,16 @@ 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 { @@ -27,30 +27,30 @@ pub fn cordon_ana_check() -> String { } /// This is the user docs URL for the Umbrella chart. -pub(crate) const UMBRELLA_CHART_UPGRADE_DOCS_URL: &str = constants::UMBRELLA_CHART_UPGRADE_DOCS_URL; +pub 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. -pub(crate) const KUBE_API_PAGE_SIZE: u32 = 500; +pub 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. -pub(crate) const TWO_DOT_O_RC_ONE: &str = "2.0.0-rc.1"; +pub const TWO_DOT_O_RC_ONE: &str = "2.0.0-rc.1"; /// Version value for the earliest possible 2.1 release (there were no pre-releases). -pub(crate) const TWO_DOT_ONE: &str = "2.1.0"; +pub const TWO_DOT_ONE: &str = "2.1.0"; /// Version value for the earliest possible 2.3 release (there were no pre-releases). -pub(crate) const TWO_DOT_THREE: &str = "2.3.0"; +pub const TWO_DOT_THREE: &str = "2.3.0"; /// Version value for the earliest possible 2.4 release (there were no pre-releases). -pub(crate) const TWO_DOT_FOUR: &str = "2.4.0"; +pub const TWO_DOT_FOUR: &str = "2.4.0"; /// Version value for the earliest possible 2.5 release. -pub(crate) const TWO_DOT_FIVE: &str = "2.5.0"; +pub const TWO_DOT_FIVE: &str = "2.5.0"; /// Version value for the earliest possible 2.6 release. -pub(crate) const TWO_DOT_SIX: &str = "2.6.0"; +pub const TWO_DOT_SIX: &str = "2.6.0"; 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 7d307c475..7543ba21b 100644 --- a/k8s/upgrade/src/bin/upgrade-job/common/error.rs +++ b/k8s/upgrade/src/common/error.rs @@ -14,10 +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)))] #[allow(unused)] -pub(crate) enum Error { +pub enum Error { /// Error for when the storage REST API URL is parsed. #[snafu(display( "Failed to parse {} REST API URL {rest_endpoint}: {source}", @@ -666,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 83% rename from k8s/upgrade/src/bin/upgrade-job/common/regex.rs rename to k8s/upgrade/src/common/regex.rs index b64346049..984c7610b 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, } @@ -14,7 +14,7 @@ impl 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 +23,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 92% rename from k8s/upgrade/src/bin/upgrade-job/events/event_recorder.rs rename to k8s/upgrade/src/events/event_recorder.rs index 6bf75862a..cac8abc9b 100644 --- a/k8s/upgrade/src/bin/upgrade-job/events/event_recorder.rs +++ b/k8s/upgrade/src/events/event_recorder.rs @@ -19,7 +19,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, @@ -44,7 +44,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, @@ -55,7 +55,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, { @@ -66,7 +66,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, { @@ -77,7 +77,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 @@ -175,7 +175,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, @@ -184,7 +184,7 @@ pub(crate) struct EventRecorder { impl EventRecorder { /// Creates an empty builder. - pub(crate) fn builder() -> EventRecorderBuilder { + pub fn builder() -> EventRecorderBuilder { EventRecorderBuilder::default() } @@ -199,7 +199,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, @@ -218,7 +218,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, @@ -236,7 +236,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, { @@ -252,7 +252,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(); @@ -261,12 +261,12 @@ impl EventRecorder { } /// Updates the EventRecorder's source_version memeber with a new value. - pub(crate) fn set_source_version(&mut self, version: String) { + 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) { + 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 76% rename from k8s/upgrade/src/bin/upgrade-job/helm.rs rename to k8s/upgrade/src/helm.rs index 1687be328..9c620afd5 100644 --- a/k8s/upgrade/src/bin/upgrade-job/helm.rs +++ b/k8s/upgrade/src/helm.rs @@ -1,10 +1,10 @@ /// 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; +pub mod values; /// This contains tools for use with yaml files. -pub(crate) mod yaml; +pub mod yaml; diff --git a/k8s/upgrade/src/bin/upgrade-job/helm/chart.rs b/k8s/upgrade/src/helm/chart.rs similarity index 93% rename from k8s/upgrade/src/bin/upgrade-job/helm/chart.rs rename to k8s/upgrade/src/helm/chart.rs index 3b9889dfa..3c22a97e9 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. @@ -39,7 +39,7 @@ pub(crate) trait HelmValuesCollection { /// chart is a sub-chart for the Umbrella chart, so the Core chart values structure is embedded /// into the UmbrellaValues structure. #[derive(Deserialize)] -pub(crate) struct UmbrellaValues { +pub struct UmbrellaValues { #[serde(rename(deserialize = "mayastor"))] core: CoreValues, } @@ -66,7 +66,7 @@ impl HelmValuesCollection for UmbrellaValues { /// This is used to deserialize the values.yaml of the Core chart. #[derive(Deserialize)] -pub(crate) struct CoreValues { +pub struct CoreValues { /// This contains values for all the agents. agents: Agents, /// This contains values for all the base components. @@ -128,178 +128,178 @@ impl HelmValuesCollection for CoreValues { impl CoreValues { /// This is a getter for the container image tag of the Core chart. - pub(crate) fn image_tag(&self) -> &str { + pub fn image_tag(&self) -> &str { self.image.tag() } /// This is a getter for the control-plane repoTag image tag set on a helm chart. - pub(crate) fn control_plane_repotag(&self) -> &str { + pub fn control_plane_repotag(&self) -> &str { self.image.control_plane_repotag() } /// This is a getter for the data-plane repoTag image tag set on a helm chart. - pub(crate) fn data_plane_repotag(&self) -> &str { + pub fn data_plane_repotag(&self) -> &str { self.image.data_plane_repotag() } /// This is a getter for the extensions repoTag image tag set on a helm chart. - pub(crate) fn extensions_repotag(&self) -> &str { + pub fn extensions_repotag(&self) -> &str { self.image.extensions_repotag() } /// This is a getter for the io-engine DaemonSet Pods' logLevel. - pub(crate) fn io_engine_log_level(&self) -> &str { + pub fn io_engine_log_level(&self) -> &str { self.io_engine.log_level() } /// This is a getter for the eventing installation enable/disable state. - pub(crate) fn eventing_enabled(&self) -> bool { + pub fn eventing_enabled(&self) -> bool { self.eventing.enabled() } /// This is a getter for the sig-storage/csi-provisioner image tag. - pub(crate) fn csi_provisioner_image_tag(&self) -> &str { + pub fn csi_provisioner_image_tag(&self) -> &str { self.csi.provisioner_image_tag() } /// This is a getter for the sig-storage/csi-attacher image tag. - pub(crate) fn csi_attacher_image_tag(&self) -> &str { + pub fn csi_attacher_image_tag(&self) -> &str { self.csi.attacher_image_tag() } /// This is a getter for the sig-storage/csi-snapshotter image tag. - pub(crate) fn csi_snapshotter_image_tag(&self) -> &str { + pub fn csi_snapshotter_image_tag(&self) -> &str { self.csi.snapshotter_image_tag() } /// This is a getter for the sig-storage/snapshot-controller image tag. - pub(crate) fn csi_snapshot_controller_image_tag(&self) -> &str { + pub fn csi_snapshot_controller_image_tag(&self) -> &str { self.csi.snapshot_controller_image_tag() } /// This is a getter for the sig-storage/csi-node-driver-registrar image tag. - pub(crate) fn csi_node_driver_registrar_image_tag(&self) -> &str { + pub fn csi_node_driver_registrar_image_tag(&self) -> &str { self.csi.node_driver_registrar_image_tag() } /// This is a getter for the sig-storage/csi-resizer image tag. - pub(crate) fn csi_resizer_image_tag(&self) -> &str { + pub fn csi_resizer_image_tag(&self) -> &str { self.csi.resizer_image_tag() } /// This is a getter for the CSI node's NVMe io_timeout. - pub(crate) fn csi_node_nvme_io_timeout(&self) -> &str { + pub fn csi_node_nvme_io_timeout(&self) -> &str { 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 { + pub 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 { + pub fn loki_stack_loki_image_tag(&self) -> &str { self.loki_stack.loki_image_tag() } /// This is a getter for the promtail scrapeConfigs. - pub(crate) fn loki_stack_promtail_scrape_configs(&self) -> &str { + pub fn loki_stack_promtail_scrape_configs(&self) -> &str { self.loki_stack.promtail_scrape_configs() } /// This returns the value of 'promtail.config.file'. - pub(crate) fn loki_stack_promtail_config_file(&self) -> &str { + pub fn loki_stack_promtail_config_file(&self) -> &str { self.loki_stack.promtail_config_file() } /// This returns the value of the deprecated promtail helm chart field 'config.lokiAddress'. - pub(crate) fn loki_stack_promtail_loki_address(&self) -> &str { + pub fn loki_stack_promtail_loki_address(&self) -> &str { self.loki_stack.deprecated_promtail_loki_address() } /// This returns the config.snippets.extraClientConfigs from the promtail helm chart v3.11.0. - pub(crate) fn promtail_extra_client_configs(&self) -> &str { + pub fn promtail_extra_client_configs(&self) -> &str { self.loki_stack.deprecated_promtail_extra_client_configs() } /// This returns the initContainers array from the promtail chart v6.13.1. - pub(crate) fn promtail_init_container(&self) -> Vec { + pub fn promtail_init_container(&self) -> Vec { self.loki_stack.promtail_init_container() } /// This returns the readinessProbe HTTP Get path from the promtail chart v6.13.1. - pub(crate) fn promtail_readiness_probe_http_get_path(&self) -> String { + pub fn promtail_readiness_probe_http_get_path(&self) -> String { self.loki_stack.promtail_readiness_probe_http_get_path() } /// This returns the image tag from the filebeat helm chart. Filebeat is a part of the /// loki-stack chart. - pub(crate) fn filebeat_image_tag(&self) -> &str { + pub fn filebeat_image_tag(&self) -> &str { self.loki_stack.filebeat_image_tag() } /// This returns the image tag from the logstash helm chart. Logstash is a part of the /// loki-stack chart. - pub(crate) fn logstash_image_tag(&self) -> &str { + pub fn logstash_image_tag(&self) -> &str { self.loki_stack.logstash_image_tag() } /// This returns the image tag for the curlimages/curl container. - pub(crate) fn grafana_download_dashboards_image_tag(&self) -> &str { + pub fn grafana_download_dashboards_image_tag(&self) -> &str { self.loki_stack.grafana_download_dashboards_image_tag() } /// This returns the image tag for the grafana/grafana container. - pub(crate) fn grafana_image_tag(&self) -> &str { + pub fn grafana_image_tag(&self) -> &str { self.loki_stack.grafana_image_tag() } /// This returns the image tag for the kiwigrid/k8s-sidecar container. - pub(crate) fn grafana_sidecar_image_tag(&self) -> &str { + pub fn grafana_sidecar_image_tag(&self) -> &str { self.loki_stack.grafana_sidecar_image_tag() } /// This is a getter for the localpv-provisioner sub-chart's release version. - pub(crate) fn localpv_release_version(&self) -> &str { + pub fn localpv_release_version(&self) -> &str { self.localpv_provisioner.release_version() } /// This is a getter for the container image tag of the hostpath localpv provisioner. - pub(crate) fn localpv_provisioner_image_tag(&self) -> &str { + pub fn localpv_provisioner_image_tag(&self) -> &str { self.localpv_provisioner.provisioner_image_tag() } /// This is a getter for the image tag of the localpv helper container. - pub(crate) fn localpv_helper_image_tag(&self) -> &str { + pub fn localpv_helper_image_tag(&self) -> &str { self.localpv_provisioner.helper_image_tag() } /// This is a getter for the prometheus/alertmanager container's image tag. - pub(crate) fn prometheus_alertmanager_image_tag(&self) -> &str { + pub fn prometheus_alertmanager_image_tag(&self) -> &str { self.loki_stack.prometheus_alertmanager_image_tag() } /// This is a getter for the prometheus/node-exporter container's image tag. - pub(crate) fn prometheus_node_exporter_image_tag(&self) -> &str { + pub fn prometheus_node_exporter_image_tag(&self) -> &str { self.loki_stack.prometheus_node_exporter_image_tag() } /// This is a getter for the prom/pushgateway container's image tag. - pub(crate) fn prometheus_pushgateway_image_tag(&self) -> &str { + pub fn prometheus_pushgateway_image_tag(&self) -> &str { self.loki_stack.prometheus_pushgateway_image_tag() } /// This is a getter for the prometheus/prometheus container's image tag. - pub(crate) fn prometheus_server_image_tag(&self) -> &str { + pub 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 { + pub fn deprecated_log_silence_level(&self) -> &str { self.base.deprecated_log_silence_level() } - pub(crate) fn jaeger_operator_image_tag(&self) -> &str { + pub fn jaeger_operator_image_tag(&self) -> &str { self.jaeger_operator.image_tag() } } @@ -1031,13 +1031,13 @@ 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, } impl PromtailConfigClient { /// Create a new PromtailConfigClient with a url. - pub(crate) fn with_url(url: U) -> Self + pub fn with_url(url: U) -> Self where U: ToString, { 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..e22b38874 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::{ + upgrade_path::{ core_version_from_umbrella_release, is_valid_for_core_chart, version_from_chart_yaml_file, version_from_core_chart_release, }, - 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 @@ -295,7 +291,7 @@ impl HelmUpgraderBuilder { /// This is a HelmUpgrader for the core helm chart. Unlike the UmbrellaHelmUpgrader, /// this actually can set up a helm upgrade. -pub(crate) struct CoreHelmUpgrader { +pub struct CoreHelmUpgrader { chart_dir: PathBuf, release_name: String, client: HelmReleaseClient, @@ -364,7 +360,7 @@ impl HelmUpgrader for CoreHelmUpgrader { /// This is a HelmUpgrader for the Umbrella chart. This gathers information, and doesn't /// set up a helm upgrade or a dry-run in any way. -pub(crate) struct UmbrellaHelmUpgrader { +pub struct UmbrellaHelmUpgrader { release_name: String, client: HelmReleaseClient, source_version: Version, diff --git a/k8s/upgrade/src/bin/upgrade-job/helm/values.rs b/k8s/upgrade/src/helm/values.rs similarity index 99% rename from k8s/upgrade/src/bin/upgrade-job/helm/values.rs rename to k8s/upgrade/src/helm/values.rs index eb89f83ae..34fd76411 100644 --- a/k8s/upgrade/src/bin/upgrade-job/helm/values.rs +++ b/k8s/upgrade/src/helm/values.rs @@ -46,7 +46,7 @@ use tempfile::NamedTempFile as TempFile; /// chart_dir --> This is the path to a directory that yq-go may use to write its output file /// into. The output file will be a merged values.yaml with special values set as per requirement /// (based on source_version and target_version). -pub(crate) async fn generate_values_yaml_file( +pub async fn generate_values_yaml_file( source_version: &Version, target_version: &Version, source_values: &CoreValues, diff --git a/k8s/upgrade/src/bin/upgrade-job/helm/yaml.rs b/k8s/upgrade/src/helm/yaml.rs similarity index 70% rename from k8s/upgrade/src/bin/upgrade-job/helm/yaml.rs rename to k8s/upgrade/src/helm/yaml.rs index 495e0a11d..ba7702f78 100644 --- a/k8s/upgrade/src/bin/upgrade-job/helm/yaml.rs +++ b/k8s/upgrade/src/helm/yaml.rs @@ -1,2 +1,2 @@ /// This contains apis to use the yq binary. -pub(crate) mod yq; +pub mod yq; diff --git a/k8s/upgrade/src/bin/upgrade-job/helm/yaml/yq.rs b/k8s/upgrade/src/helm/yaml/yq.rs similarity index 94% rename from k8s/upgrade/src/bin/upgrade-job/helm/yaml/yq.rs rename to k8s/upgrade/src/helm/yaml/yq.rs index 9b62fc305..bf39e50b9 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}; @@ -18,7 +18,7 @@ use std::{ /// This is a container for the String of an input yaml key. #[derive(Clone)] -pub(crate) struct YamlKey(String); +pub struct YamlKey(String); impl TryFrom<&str> for YamlKey { type Error = crate::common::error::Error; @@ -54,14 +54,14 @@ impl Deref for YamlKey { } /// This type is for running `yq` v4.x.y commands. -pub(crate) struct YqV4 { +pub struct YqV4 { /// This is the name of the binary, for use when running `yq` Commands. command_name: String, } impl YqV4 { /// Run the `yq -V` command to check if yq exists and it's version is v4.x.y. - pub(crate) fn new() -> Result { + pub fn new() -> Result { let yq_v4 = Self { command_name: String::from("yq"), }; @@ -100,7 +100,7 @@ impl YqV4 { } /// Append objects to yaml arrays. - pub(crate) fn append_to_array(&self, key: YamlKey, value: V, filepath: P) -> Result<()> + pub fn append_to_array(&self, key: YamlKey, value: V, filepath: P) -> Result<()> where V: Display + Sized, P: AsRef, @@ -127,7 +127,7 @@ impl YqV4 { } /// Append fields to yaml objects. - pub(crate) fn append_to_object(&self, key: YamlKey, value: V, filepath: P) -> Result<()> + pub fn append_to_object(&self, key: YamlKey, value: V, filepath: P) -> Result<()> where V: Display + Sized, P: AsRef, @@ -154,7 +154,7 @@ impl YqV4 { } /// Use the yq 'del' operator to delete objects from a yaml file. - pub(crate) fn delete_object

(&self, key: YamlKey, filepath: P) -> Result<()> + pub fn delete_object

(&self, key: YamlKey, filepath: P) -> Result<()> where P: AsRef, { @@ -223,7 +223,7 @@ impl YqV4 { /// and migrate the older default to the newer one. E.g.: the .io_engine.logLevel is set to /// 'info' deliberately if the upgrade source file is seen to contain the value /// 'info,io_engine=info' and the target yaml is seen to not contain it. - pub(crate) fn merge_files(&self, high_priority: P, low_priority: Q) -> Result> + pub fn merge_files(&self, high_priority: P, low_priority: Q) -> Result> where P: AsRef, Q: AsRef, @@ -251,7 +251,7 @@ impl YqV4 { } /// This sets in-place yaml values in yaml files. - pub(crate) fn set_literal_value(&self, key: YamlKey, value: V, filepath: P) -> Result<()> + pub fn set_literal_value(&self, key: YamlKey, value: V, filepath: P) -> Result<()> where V: Display + Sized, P: AsRef, diff --git a/k8s/upgrade/src/lib.rs b/k8s/upgrade/src/lib.rs index 8e1789b41..0062899af 100644 --- a/k8s/upgrade/src/lib.rs +++ b/k8s/upgrade/src/lib.rs @@ -11,3 +11,15 @@ pub use plugin::constants; /// Module for upgrade client errors. pub use plugin::error; + +pub mod helm; + +pub mod common; + +pub mod events; +/// Contains the data-plane upgrade logic. +pub mod upgrade_data_plane; +/// Tools to validate upgrade path. +pub mod upgrade_path; +/// Contains upgrade utilities. +pub 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 87% rename from k8s/upgrade/src/bin/upgrade-job/upgrade/path.rs rename to k8s/upgrade/src/upgrade_path.rs index 432f2c9d8..956a5192d 100644 --- a/k8s/upgrade/src/bin/upgrade-job/upgrade/path.rs +++ b/k8s/upgrade/src/upgrade_path.rs @@ -14,16 +14,16 @@ use snafu::ResultExt; 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 { +pub 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_core_chart_release(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,7 +52,7 @@ pub(crate) fn version_from_core_chart_release(chart_name: &str) -> Result Result { diff --git a/k8s/upgrade/src/bin/upgrade-job/upgrade/utils.rs b/k8s/upgrade/src/upgrade_utils.rs similarity index 94% rename from k8s/upgrade/src/bin/upgrade-job/upgrade/utils.rs rename to k8s/upgrade/src/upgrade_utils.rs index 76ab4abc4..ed802ea6f 100644 --- a/k8s/upgrade/src/bin/upgrade-job/upgrade/utils.rs +++ b/k8s/upgrade/src/upgrade_utils.rs @@ -15,13 +15,13 @@ use tracing::{info, warn}; /// Contains the Rebuild Results. #[derive(Default)] -pub(crate) struct RebuildResult { - pub(crate) rebuilding: bool, - pub(crate) discarded_volumes: Vec, +pub struct RebuildResult { + pub rebuilding: bool, + pub discarded_volumes: Vec, } /// Function to check for any volume rebuild in progress across the cluster. -pub(crate) async fn rebuild_result( +pub async fn rebuild_result( rest_client: &RestClientSet, stale_volumes: &mut Vec, node_name: &str, @@ -83,7 +83,7 @@ pub(crate) async fn rebuild_result( } /// Return the list of unhealthy volumes. -pub(crate) async fn list_unhealthy_volumes( +pub async fn list_unhealthy_volumes( rest_client: &RestClientSet, discarded_volumes: &[Volume], ) -> Result> { @@ -116,7 +116,7 @@ pub(crate) async fn list_unhealthy_volumes( } /// Count of number of replica rebuilding. -pub(crate) fn replica_rebuild_count(volume: &Volume) -> i32 { +pub fn replica_rebuild_count(volume: &Volume) -> i32 { let mut rebuild_count = 0; if let Some(target) = &volume.state.target { for child in target.children.iter() { @@ -138,7 +138,7 @@ pub(crate) fn replica_rebuild_count(volume: &Volume) -> i32 { /// This function returns 'true' only if all of the containers in the Pods contained in the /// ObjectList have their Ready status.condition value set to true. -pub(crate) fn all_pods_are_ready(pod_list: Vec) -> bool { +pub fn all_pods_are_ready(pod_list: Vec) -> bool { let not_ready_warning = |pod_name: &String, namespace: &String| { warn!( "Couldn't verify the ready condition of Pod '{}' in namespace '{}' to be true", @@ -176,7 +176,7 @@ pub(crate) fn all_pods_are_ready(pod_list: Vec) -> bool { } /// Cordon storage node. -pub(crate) async fn cordon_storage_node( +pub async fn cordon_storage_node( node_id: &str, cordon_label: &str, rest_client: &RestClientSet, @@ -224,7 +224,7 @@ pub(crate) async fn cordon_storage_node( } /// Uncordon storage Node. -pub(crate) async fn uncordon_storage_node( +pub async fn uncordon_storage_node( node_id: &str, cordon_label: &str, rest_client: &RestClientSet, @@ -278,7 +278,7 @@ pub(crate) async fn uncordon_storage_node( } /// List all Storage volumes. Paginated responses from the Storage REST. -pub(crate) async fn list_all_volumes(rest_client: &RestClientSet) -> Result> { +pub async fn list_all_volumes(rest_client: &RestClientSet) -> Result> { let mut volumes: Vec = Vec::new(); // The number of volumes to get per request. let max_entries = 200;