Skip to content

Commit

Permalink
chore(bors): merge pull request #333
Browse files Browse the repository at this point in the history
333: Cherry-pick PR #319 into release/2.4 r=avishnu a=niladrih

Cherry-picks the commits from the following PR(s) into release/2.4:
- #319 

Co-authored-by: Niladri Halder <niladri.halder26@gmail.com>
  • Loading branch information
mayastor-bors and niladrih committed Aug 29, 2023
2 parents 907858c + 1cb0853 commit 6288411
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 28 deletions.
40 changes: 20 additions & 20 deletions k8s/upgrade/src/bin/upgrade-job/events/event_recorder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,35 +71,25 @@ impl EventRecorderBuilder {
self
}

/// This is a builder option add the from-version in upgrade.
#[must_use]
pub(crate) fn with_from_version(mut self, from: String) -> Self {
self.from_version = Some(from);
self
}

/// This is a builder option add the to-version in upgrade.
#[must_use]
pub(crate) fn with_to_version(mut self, to: String) -> Self {
self.to_version = Some(to);
self
}

// 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<EventRecorder> {
ensure!(
self.pod_name.is_some()
&& self.namespace.is_some()
&& self.from_version.is_some()
&& self.to_version.is_some(),
self.pod_name.is_some() && self.namespace.is_some(),
EventRecorderOptionsAbsent
);
let pod_name = self.pod_name.clone().unwrap();
let namespace = self.namespace.clone().unwrap();
let from_version = self.from_version.clone().unwrap();
let to_version = self.to_version.clone().unwrap();

// Initialize version to '--'. These can be updated later with set_from_version()
// and set_to_version() EventRecorder methods.
let vers_placeholder = "--".to_string();
let from_version = self
.from_version
.clone()
.unwrap_or(vers_placeholder.clone());
let to_version = self.to_version.clone().unwrap_or(vers_placeholder);

let k8s_client = KubeClientSet::builder()
.with_namespace(namespace.as_str())
Expand Down Expand Up @@ -274,6 +264,16 @@ impl EventRecorder {
// Wait for event loop to publish its last events and exit.
let _ = self.event_loop_handle.await;
}

/// Updates the EventRecorder's from_version memeber with a new value.
pub(crate) fn set_from_version(&mut self, version: String) {
self.from_version = version
}

/// Updates the EventRecorder's to_version memeber with a new value.
pub(crate) fn set_to_version(&mut self, version: String) {
self.to_version = version
}
}

/// current volume status
Expand Down
31 changes: 23 additions & 8 deletions k8s/upgrade/src/bin/upgrade-job/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,24 @@ pub(crate) mod path;

/// This function starts and sees upgrade through to the end.
pub(crate) async fn upgrade(opts: &CliArgs) -> Result<()> {
let mut event = EventRecorder::builder()
.with_pod_name(&opts.pod_name())
.with_namespace(&opts.namespace())
.build()
.await?;

let result = upgrade_product(opts, &mut event).await;

// This makes sure that the event worker attempts to publish
// all of its events. It waits for the event worker to exit.
event.shutdown_worker().await;

result
}

/// This carries out the helm upgrade validation, actual helm upgrade, and the io-engine Pod
/// restarts.
async fn upgrade_product(opts: &CliArgs, event: &mut EventRecorder) -> Result<()> {
let helm_upgrade = HelmUpgrade::builder()
.with_namespace(opts.namespace())
.with_release_name(opts.release_name())
Expand All @@ -29,13 +47,11 @@ pub(crate) async fn upgrade(opts: &CliArgs) -> Result<()> {
let from_version = helm_upgrade.upgrade_from_version();
let to_version = helm_upgrade.upgrade_to_version();

let event = EventRecorder::builder()
.with_pod_name(&opts.pod_name())
.with_namespace(&opts.namespace())
.with_from_version(from_version)
.with_to_version(to_version.clone())
.build()
.await?;
// Updating the EventRecorder with version values from the HelmUpgrade.
// These two operations are thread-safe. The EventRecorder itself is not
// shared with any other tokio task.
event.set_from_version(from_version.clone());
event.set_to_version(to_version.clone());

// Dry-run helm upgrade.
let dry_run_result: Result<HelmUpgradeRunner> = helm_upgrade.dry_run().await;
Expand Down Expand Up @@ -105,6 +121,5 @@ pub(crate) async fn upgrade(opts: &CliArgs) -> Result<()> {
)
.await?;

event.shutdown_worker().await;
Ok(())
}

0 comments on commit 6288411

Please sign in to comment.