Skip to content

Commit

Permalink
chore(bors): merge pull request #248
Browse files Browse the repository at this point in the history
248: Cherry pick PR #245 and  #247 to release/2.2 branch r=sinhaashish a=sinhaashish

This PR cherry-picks the following commit(s) to release/2.2:
 - [beb02c9](beb02c9)
 -  [8df03fc](8df03fc)


Co-authored-by: sinhaashish <ashi.sinha.87@gmail.com>
  • Loading branch information
mayastor-bors and sinhaashish committed May 25, 2023
2 parents f459637 + 2e90f52 commit bf0999d
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 76 deletions.
103 changes: 68 additions & 35 deletions k8s/plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ Commands:
scale 'Scale' resources
cordon 'Cordon' resources
uncordon 'Uncordon' resources
dump `Dump` resources
install `Install` resources
uninstall `Uninstall` resources
upgrade `Upgrade` resources
help Print this message or the help of the given subcommand(s)
dump 'Dump' resources
upgrade 'Upgrade' the deployment
delete 'Delete' the upgrade resources
help Print this message or the help of the given subcommand(s)
Options:
-r, --rest <REST>
Expand All @@ -46,7 +45,7 @@ Options:
-t, --timeout <TIMEOUT>
Timeout for the REST operations [default: 10s]
-n, --namespace <NAMESPACE>
Kubernetes namespace of mayastor service, defaults to mayastor [default: mayastor]
Kubernetes namespace of mayastor service
-h, --help
Print help
-V, --version
Expand Down Expand Up @@ -278,7 +277,7 @@ Options:
-d, --output-directory-path <OUTPUT_DIRECTORY_PATH>
Output directory path to store archive file [default: ./]
-n, --namespace <NAMESPACE>
Kubernetes namespace of mayastor service, defaults to mayastor [default: mayastor]
Kubernetes namespace of mayastor service[default: mayastor]
-o, --output <OUTPUT>
The Output, viz yaml, json [default: none]
-j, --jaeger <JAEGER>
Expand Down Expand Up @@ -347,57 +346,91 @@ Supportability - collects state & log information of services and dumps it to a
kubectl mayastor dump volume volume-1 -d /mayastor-dump -r http://127.0.0.1:30011 -l http://127.0.0.1:3100 -e http://127.0.0.1:2379 -n mayastor
```
</details>
<details>
<summary> Upgrade operations </summary>
**Examples**:
1. To install upgrade resources need for executing upgrade operation
```sh
## Command
kubectl mayastor install upgrade-operator -n <mayastor_namespace>
```
2. To uninstall upgrade resources need for executing upgrade operation
```sh
## Command
kubectl mayastor uninstall upgrade-operator -n <mayastor_namespace>
```
1. To upgrade the installation
```sh
1. Upgrade deployment
```
## Command
kubectl mayastor upgrade
`Upgrade` the deployment
Usage: kubectl-mayastor upgrade [OPTIONS]
Options:
-d, --dry-run
-d, --dry-run
Display all the validations output but will not execute upgrade
-r, --rest <REST>
-r, --rest <REST>
The rest endpoint to connect to
-k, --kube-config-path <KUBE_CONFIG_PATH>
Path to kubeconfig file
-s, --skip-data-plane-restart
-D, --skip-data-plane-restart
If set then upgrade will skip the io-engine pods restart
--skip-single-replica-volume-validation
-k, --kube-config-path <KUBE_CONFIG_PATH>
Path to kubeconfig file
-S, --skip-single-replica-volume-validation
If set then it will continue with upgrade without validating singla replica volume
--skip-replica-rebuild
-R, --skip-replica-rebuild
If set then upgrade will skip the repilca rebuild in progress validation
-o, --output <OUTPUT>
-C, --skip-cordoned-node-validation
If set then upgrade will skip the cordoned node validation
-o, --output <OUTPUT>
The Output, viz yaml, json [default: none]
-j, --jaeger <JAEGER>
-j, --jaeger <JAEGER>
Trace rest requests to the Jaeger endpoint agent
-n, --namespace <NAMESPACE>
Kubernetes namespace of mayastor service, defaults to mayastor [default: mayastor]
-h, --help
-n, --namespace <NAMESPACE>
Kubernetes namespace of mayastor service [default: mayastor]
-h, --help
Print help
```
4. To get the upgrade status
```sh
2. Get the upgrade status
```
## Command
kubectl mayastor get upgrade-status
`Get` the upgrade status
Usage: kubectl-mayastor get upgrade-status [OPTIONS]
Options:
-r, --rest <REST>
The rest endpoint to connect to
-k, --kube-config-path <KUBE_CONFIG_PATH>
Path to kubeconfig file
-o, --output <OUTPUT>
The Output, viz yaml, json [default: none]
-j, --jaeger <JAEGER>
Trace rest requests to the Jaeger endpoint agent
-n, --namespace <NAMESPACE>
Kubernetes namespace of mayastor service [default: mayastor]
-h, --help
Print help
```
3. Delete upgrade resources
```
## Command
kubectl mayastor delete upgrade
`Delete` the upgrade resources
Usage: kubectl-mayastor delete upgrade [OPTIONS]
Options:
-f, --force
If true, immediately remove upgrade resources bypass graceful deletion
-r, --rest <REST>
The rest endpoint to connect to
-k, --kube-config-path <KUBE_CONFIG_PATH>
Path to kubeconfig file
-o, --output <OUTPUT>
The Output, viz yaml, json [default: none]
-j, --jaeger <JAEGER>
Trace rest requests to the Jaeger endpoint agent
-n, --namespace <NAMESPACE>
Kubernetes namespace of mayastor service [default: mayastor]
-h, --help
Print help
```
</details>
2 changes: 1 addition & 1 deletion k8s/plugin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct CliArgs {
#[clap(long, short, default_value = "10s")]
timeout: humantime::Duration,

/// Kubernetes namespace of mayastor service, defaults to mayastor
/// Kubernetes namespace of mayastor service
#[clap(global = true, long, short = 'n', default_value = "mayastor")]
namespace: String,
}
Expand Down
2 changes: 1 addition & 1 deletion k8s/plugin/src/resources/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub enum Operations {
Dump(DumpArgs),
/// `Upgrade` the deployment.
Upgrade(UpgradeArgs),
/// `Delete` the resources.
/// `Delete` the upgrade resources.
#[clap(subcommand)]
Delete(DeleteResources),
}
2 changes: 1 addition & 1 deletion k8s/supportability/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub struct SupportArgs {
#[clap(global = true, long, short = 'd', default_value = "./")]
output_directory_path: String,

/// Kubernetes namespace of mayastor service, defaults to mayastor
/// Kubernetes namespace of mayastor service
#[clap(global = true, long, short = 'n', default_value = "mayastor")]
namespace: String,
}
Expand Down
8 changes: 4 additions & 4 deletions k8s/upgrade/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ pub enum Error {
#[snafu(display("Upgrade Job: {} status not present.", name))]
UpgradeJobStatusNotPresent { name: String },

/// Error for when the job.status is a None.
#[snafu(display("Upgrade Job: {} not completed.", name))]
UpgradeJobNotCompleted { name: String },
/// Error for when the upgrade job is not present.
#[snafu(display("Upgrade Job: {} in namespace {} does not exist.", name, namespace))]
UpgradeJobNotPresent { name: String, namespace: String },

/// Error for when a Kubernetes API request for GET-ing a list of Pods filtered by label(s)
/// fails.
Expand Down Expand Up @@ -260,7 +260,7 @@ impl From<Error> for i32 {
Error::NodeSpecNotPresent { .. } => 423,
Error::PodNameNotPresent { .. } => 424,
Error::UpgradeJobStatusNotPresent { .. } => 425,
Error::UpgradeJobNotCompleted { .. } => 426,
Error::UpgradeJobNotPresent { .. } => 426,
Error::ListPodsWithLabel { .. } => 427,
Error::ListDeploymantsWithLabel { .. } => 428,
Error::ListEventsWithFieldSelector { .. } => 429,
Expand Down
62 changes: 30 additions & 32 deletions k8s/upgrade/src/upgrade_resources/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ use crate::{
upgrade_resources::objects,
user_prompt::{
upgrade_dry_run_summary, CONTROL_PLANE_PODS_LIST, DATA_PLANE_PODS_LIST,
DATA_PLANE_PODS_LIST_SKIP_RESTART, UPGRADE_DRY_RUN_SUMMARY, UPGRADE_JOB_STARTED,
DATA_PLANE_PODS_LIST_SKIP_RESTART, DELETE_INCOMPLETE_JOB, UPGRADE_DRY_RUN_SUMMARY,
UPGRADE_JOB_STARTED,
},
};
use k8s_openapi::api::{
Expand All @@ -38,16 +39,21 @@ pub enum DeleteResources {

/// Delete Upgrade resource.
#[derive(clap::Args, Debug)]
pub struct DeleteUpgradeArgs {}
pub struct DeleteUpgradeArgs {
/// If true, immediately remove upgrade resources bypass graceful deletion.
#[clap(global = false, long, short, default_value_t = false)]
pub force: bool,
}

impl DeleteUpgradeArgs {
/// Delete the upgrade resources
pub async fn delete(&self, ns: &str) {
// Delete upgrade resources once job completes

match is_upgrade_job_completed(ns).await {
Ok(job_completed) => {
if job_completed {
if !job_completed && !self.force {
console_logger::error("", DELETE_INCOMPLETE_JOB);
}
if job_completed || self.force {
_ = UpgradeResources::delete_upgrade_resources(ns)
.await
.map_err(|error| {
Expand All @@ -56,9 +62,8 @@ impl DeleteUpgradeArgs {
}
}
Err(error) => {
eprintln!(
"error occured while fetching the completion status of upgrade job {error}"
);
eprintln!("error : {error}");
std::process::exit(error.into());
}
}
}
Expand Down Expand Up @@ -663,33 +668,26 @@ pub async fn is_upgrade_job_completed(ns: &str) -> error::Result<bool> {
})?;
match option_job {
Some(job) => {
if matches!(
job.status
.as_ref()
.ok_or(
error::UpgradeJobStatusNotPresent {
name: job_name.clone()
}
.build()
)?
.succeeded
.as_ref()
.ok_or(
error::UpgradeJobNotCompleted {
name: job_name.clone()
}
.build()
)?,
1
) {
return Ok(true);
}
let status = job.status.as_ref().ok_or(
error::UpgradeJobStatusNotPresent {
name: job_name.clone(),
}
.build(),
)?;

let is_job_completed = match status.succeeded {
None => false,
Some(count) => count == 1,
};
Ok(is_job_completed)
}
None => {
eprintln!("Upgrade job {job_name} in namespace {ns} does not exist");

None => error::UpgradeJobNotPresent {
name: job_name,
namespace: ns,
}
.fail(),
}
Ok(false)
}

struct ImageProperties {
Expand Down
8 changes: 6 additions & 2 deletions k8s/upgrade/src/user_prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ pub const UPGRADE_JOB_STARTED: &str =
pub const UPGRADE_PATH_NOT_VALID: &str =
"\nThe upgrade path is not valid. The source version is in the list of unsupported versions:";

/// Upgrade to unsuppoted version not valid.
/// Upgrade to unsupported version not valid.
pub const UPGRADE_TO_UNSUPPORTED_VERSION: &str =
"\nUpgrade failed as destination version is unsupported. Please try with `--skip-upgrade-path-validation-for-unsupported-version`";
"\nUpgrade failed as destination version is unsupported. Please try with `--skip-upgrade-path-validation-for-unsupported-version.`";

/// Delete an incomplete job.
pub const DELETE_INCOMPLETE_JOB: &str =
"\n Cant delete an incomplete upgrade job. Please try with `--force` flag to forcefully remove upgrade resources and bypass graceful deletion.";

0 comments on commit bf0999d

Please sign in to comment.