Skip to content

Commit 9c020d4

Browse files
Techassinightkrsbernauer
authored
feat: Add support for human-readable duration formats (#647)
* Update author constant * Add humantime Duration * Update changelog * Add `from_secs` and `from_millis` helper functions * Trim trailing whitespace using pre-commit hook * Fix markdownlint errors using pre-commit hook * Implement first iteration of custom parsing * Remove humantime dependency * Add `Display` impl, add various `ops` impls * Add negative tests * Rework `Duration` implementation based on @nightkr gist This reworks/simplifies the `Duration` implementation. Supported units are now clearly defned by an enum and the parsing/display mechanism is now way more explicit and defined in one place. Co-authored-by: Natalie Klestrup Röijezon <teo.roijezon@stackable.de> * Add documentation Co-authored-by: Natalie Klestrup Röijezon <teo.roijezon@stackable.de> * Fix module documentation links Co-authored-by: Natalie Klestrup Röijezon <teo.roijezon@stackable.de> * Fix bug We need to check if the iterator progressed based on the start index of the unit / the end index of the numeric value. * Update parser, add context to errors, add more tests This commit now parses durations in the Go format. This format doesn't use whitespaces to separate each fragment. Instead, all fragments are concated without any space between. The parser needs to be a little cleverer when trying to keep it streamlined. Additionally, the error variants now contain some more context to make it easier for the user to spot the error in the provided value. Co-authored-by: Natalie Klestrup Röijezon <teo.roijezon@stackable.de> * Update src/duration/mod.rs Co-authored-by: Sebastian Bernauer <sebastian.bernauer@stackable.de> * Re-add millisecond support, switch to Snafu * Fix markdown link references * duration::serde_impl exports nothing * Split duration parsing context selectors into a submodule * typo: "expected character" -> "unexpected character" * Fail if duration buffer is non-empty at the end of parsing * Use Debug impls to quote strings in errors * Non-ASCII input will be caught anyway, because it's never a valid character * DurationUnit doesn't need to be public * Add check for invalid unit order and duplicate units * Revert "Non-ASCII input will be caught anyway, because it's never a valid character" This reverts commit fe1911e. * Fix doc comment * Impl Mul and Div * Impl Mul and Div 2 * impl JsonSchema for Duration * Re-order `SubAssign` impl * Revert "Revert "Non-ASCII input will be caught anyway, because it's never a valid character"" This reverts commit 2d3d32c. * Remove `impl Div<Duration> for u32` * Fix scanning of multibyte chars --------- Co-authored-by: Natalie Klestrup Röijezon <teo.roijezon@stackable.de> Co-authored-by: Sebastian Bernauer <sebastian.bernauer@stackable.de>
1 parent f846302 commit 9c020d4

File tree

9 files changed

+453
-7
lines changed

9 files changed

+453
-7
lines changed

.github/pull_request_template.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## Description
1+
# Description
22

33
*Please add a description here. This will become the commit message of the merge request later.*
44

@@ -7,7 +7,6 @@
77
- Not all of these items are applicable to all PRs, the author should update this template to only leave the boxes in that are relevant
88
- Please make sure all these things are done and tick the boxes
99

10-
1110
```[tasklist]
1211
# Author
1312
- [ ] Changes are OpenShift compatible

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ All notable changes to this project will be documented in this file.
1010

1111
- `PodListeners` CRD ([#644]).
1212
- Add support for tls pkcs12 password to secret operator volume builder ([#645]).
13+
- Add `Duration` capable of parsing human-readable duration formats ([#647])
14+
15+
[#644]: https://github.com/stackabletech/operator-rs/pull/644
16+
[#645]: https://github.com/stackabletech/operator-rs/pull/645
17+
[#647]: https://github.com/stackabletech/operator-rs/pull/647
1318

1419
### Changed
1520

src/cli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ use std::{
116116
path::{Path, PathBuf},
117117
};
118118

119-
pub const AUTHOR: &str = "Stackable GmbH - info@stackable.de";
119+
pub const AUTHOR: &str = "Stackable GmbH - info@stackable.tech";
120120

121121
/// Framework-standardized commands
122122
///

src/commons/authentication/static_.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
//! The update time depends on the kubelet syncing period.
1818
//! This would need additional functionality in restart controller to white- or blacklist certain volumes. Additionally, we would need a sidecar container that
1919
//! periodically converts the secret contents to the required product format.
20-
//!
20+
//!
2121
//! See <https://github.com/stackabletech/operator-rs/issues/494>
2222
use schemars::JsonSchema;
2323
use serde::{Deserialize, Serialize};

src/commons/opa.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
//! )]
2323
//! #[serde(rename_all = "camelCase")]
2424
//! pub struct TestClusterSpec {
25-
//! opa: Option<OpaConfig>
25+
//! opa: Option<OpaConfig>
2626
//! }
2727
//!
2828
//! let cluster: TestCluster = serde_yaml::from_str(

0 commit comments

Comments
 (0)