Skip to content
This repository was archived by the owner on Feb 16, 2024. It is now read-only.

Commit 15cb701

Browse files
committed
Sort operator versions descending (#102)
## Description For better readable output
1 parent dc84571 commit 15cb701

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
- Print Nifi adminuser credentials within services command ([#80](https://github.com/stackabletech/stackablectl/pull/80))
88

9+
### Changed
10+
11+
- Sort operator versions descending ([#102](https://github.com/stackabletech/stackablectl/pull/102))
12+
913
### Removed
1014
- Remove Spark from supported operators ([#100](https://github.com/stackabletech/stackablectl/pull/100))
1115

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ lazy_static = "1.4"
2020
log = "0.4"
2121
openssl = { version = "0.10.36", features = ["vendored"] } # Must match version from kube
2222
which = "4.2"
23+
semver = "1.0"
2324
serde = { version = "1.0", features = ["derive"]}
2425
serde_json = "1.0"
2526
serde_yaml = "0.9"

src/operator.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::{arguments::OutputType, helm, helm::HELM_REPOS, kind, AVAILABLE_OPERA
22
use clap::{Parser, ValueHint};
33
use indexmap::IndexMap;
44
use log::{info, warn};
5+
use semver::Version;
56
use serde::Serialize;
67
use std::{error::Error, str::FromStr};
78

@@ -167,6 +168,8 @@ async fn describe_operator(operator: &str, output_type: &OutputType) -> Result<(
167168
Ok(())
168169
}
169170

171+
/// Returns list of available versions for a specific operator within a helm repo.
172+
/// Uses the semver crate to parse and sort the versions descending.
170173
async fn get_versions_from_repo(
171174
operator: &str,
172175
helm_repo_name: &str,
@@ -188,11 +191,18 @@ async fn get_versions_from_repo(
188191
warn!("Could not find {operator} operator (chart name {chart_name}) in helm repo {helm_repo_name}");
189192
Ok(vec![])
190193
}
191-
Some(versions) => Ok(versions
192-
.iter()
193-
.map(|entry| entry.version.clone())
194-
.rev()
195-
.collect()),
194+
Some(repo_entries) => {
195+
let mut versions = repo_entries
196+
.iter()
197+
.map(|entry| Version::parse(&entry.version))
198+
.collect::<Result<Vec<Version>, _>>()?;
199+
versions.sort();
200+
Ok(versions
201+
.iter()
202+
.rev()
203+
.map(|version| version.to_string())
204+
.collect())
205+
}
196206
}
197207
}
198208

0 commit comments

Comments
 (0)