Skip to content

Commit 2bac6b3

Browse files
authored
Revert "refactor: Replace lazy_static with std::sync::LazyLock (#827)" (#835)
* Revert "refactor: Replace lazy_static with std::sync::LazyLock (#827)" This reverts commit f15a9a3. We still need Rust 1.79.0 compatibility until 1.80 percolates into Nixpkgs. * Changelog
1 parent 12395a0 commit 2bac6b3

File tree

22 files changed

+91
-101
lines changed

22 files changed

+91
-101
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ env:
1717
CARGO_TERM_COLOR: always
1818
CARGO_INCREMENTAL: '0'
1919
CARGO_PROFILE_DEV_DEBUG: '0'
20-
RUST_TOOLCHAIN_VERSION: "1.80.0"
20+
RUST_TOOLCHAIN_VERSION: "1.79.0"
2121
RUSTFLAGS: "-D warnings"
2222
RUSTDOCFLAGS: "-D warnings"
2323
RUST_LOG: "info"
@@ -37,7 +37,7 @@ jobs:
3737
- uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3
3838
with:
3939
key: udeps
40-
- run: cargo install --locked [email protected].50
40+
- run: cargo install --locked [email protected].47
4141
- run: cargo udeps --all-targets
4242

4343
run_cargodeny:

.github/workflows/pr_pre-commit.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66

77
env:
88
CARGO_TERM_COLOR: always
9-
RUST_TOOLCHAIN_VERSION: "1.80.0"
9+
RUST_TOOLCHAIN_VERSION: "1.79.0"
1010

1111
jobs:
1212
pre-commit:

Cargo.lock

Lines changed: 2 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
@@ -32,6 +32,7 @@ json-patch = "2.0.0"
3232
k8s-openapi = { version = "0.22.0", default-features = false, features = ["schemars", "v1_30"] }
3333
# We use rustls instead of openssl for easier portablitly, e.g. so that we can build stackablectl without the need to vendor (build from source) openssl
3434
kube = { version = "0.93.1", default-features = false, features = ["client", "jsonpatch", "runtime", "derive", "rustls-tls"] }
35+
lazy_static = "1.5.0"
3536
opentelemetry = "0.23.0"
3637
opentelemetry_sdk = { version = "0.23.0", features = ["rt-tokio"] }
3738
opentelemetry-appender-tracing = "0.4.0"

crates/k8s-version/CHANGELOG.md

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

55
## [Unreleased]
66

7-
### Changed
8-
9-
- Replace `lazy_static` with `std::cell::LazyCell` ([#827]).
10-
11-
[#827]: https://github.com/stackabletech/operator-rs/pull/827
12-
137
## [0.1.1] - 2024-07-10
148

159
### Changed

crates/k8s-version/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ darling = ["dep:darling"]
1111

1212
[dependencies]
1313
darling = { workspace = true, optional = true }
14+
lazy_static.workspace = true
1415
regex.workspace = true
1516
snafu.workspace = true
1617

crates/k8s-version/src/group.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
use std::{fmt, ops::Deref, str::FromStr, sync::LazyLock};
1+
use std::{fmt, ops::Deref, str::FromStr};
22

3+
use lazy_static::lazy_static;
34
use regex::Regex;
45
use snafu::{ensure, Snafu};
56

67
const MAX_GROUP_LENGTH: usize = 253;
78

8-
static API_GROUP_REGEX: LazyLock<Regex> = LazyLock::new(|| {
9-
Regex::new(r"^(?:(?:[a-z0-9][a-z0-9-]{0,61}[a-z0-9])\.?)+$")
10-
.expect("failed to compile API group regex")
11-
});
9+
lazy_static! {
10+
static ref API_GROUP_REGEX: Regex =
11+
Regex::new(r"^(?:(?:[a-z0-9][a-z0-9-]{0,61}[a-z0-9])\.?)+$")
12+
.expect("failed to compile API group regex");
13+
}
1214

1315
/// Error variants which can be encountered when creating a new [`Group`] from
1416
/// unparsed input.

crates/k8s-version/src/level.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,19 @@ use std::{
44
num::ParseIntError,
55
ops::{Add, AddAssign, Sub, SubAssign},
66
str::FromStr,
7-
sync::LazyLock,
87
};
98

9+
use lazy_static::lazy_static;
1010
use regex::Regex;
1111
use snafu::{OptionExt, ResultExt, Snafu};
1212

1313
#[cfg(feature = "darling")]
1414
use darling::FromMeta;
1515

16-
static LEVEL_REGEX: LazyLock<Regex> = LazyLock::new(|| {
17-
Regex::new(r"^(?P<identifier>[a-z]+)(?P<version>\d+)$").expect("failed to compile level regex")
18-
});
16+
lazy_static! {
17+
static ref LEVEL_REGEX: Regex = Regex::new(r"^(?P<identifier>[a-z]+)(?P<version>\d+)$")
18+
.expect("failed to compile level regex");
19+
}
1920

2021
/// Error variants which can be encountered when creating a new [`Level`] from
2122
/// unparsed input.

crates/k8s-version/src/version.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
use std::{cmp::Ordering, fmt::Display, num::ParseIntError, str::FromStr, sync::LazyLock};
1+
use std::{cmp::Ordering, fmt::Display, num::ParseIntError, str::FromStr};
22

3+
use lazy_static::lazy_static;
34
use regex::Regex;
45
use snafu::{OptionExt, ResultExt, Snafu};
56

@@ -8,10 +9,11 @@ use darling::FromMeta;
89

910
use crate::{Level, ParseLevelError};
1011

11-
static VERSION_REGEX: LazyLock<Regex> = LazyLock::new(|| {
12-
Regex::new(r"^v(?P<major>\d+)(?P<level>[a-z0-9][a-z0-9-]{0,60}[a-z0-9])?$")
13-
.expect("failed to compile version regex")
14-
});
12+
lazy_static! {
13+
static ref VERSION_REGEX: Regex =
14+
Regex::new(r"^v(?P<major>\d+)(?P<level>[a-z0-9][a-z0-9-]{0,60}[a-z0-9])?$")
15+
.expect("failed to compile version regex");
16+
}
1517

1618
/// Error variants which can be encountered when creating a new [`Version`] from
1719
/// unparsed input.

crates/stackable-operator/CHANGELOG.md

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

99
- Rollout tracker for `StatefulSet` ([#833]).
1010

11+
### Changed
12+
13+
- Reverted [#827], in order to restore Rust 1.79 compatibility for now ([#835]).
14+
1115
### Fixed
1216

1317
- Invalid CRD schema for `StackableAffinity` contents. This was caused by the fields being optional and defaulting to `null`, while the custom schema marked the field as required ([#836]).
1418

1519
[#833]: https://github.com/stackabletech/operator-rs/pull/833
20+
[#835]: https://github.com/stackabletech/operator-rs/pull/835
1621
[#836]: https://github.com/stackabletech/operator-rs/pull/836
1722

1823
## [0.72.0] - 2024-08-05

crates/stackable-operator/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ futures.workspace = true
2424
json-patch.workspace = true
2525
k8s-openapi.workspace = true
2626
kube.workspace = true
27+
lazy_static.workspace = true
2728
opentelemetry_sdk.workspace = true
2829
opentelemetry-jaeger.workspace = true
2930
product-config.workspace = true

crates/stackable-operator/src/client.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -373,15 +373,15 @@ impl Client {
373373

374374
/// There are four different patch strategies:
375375
/// 1) Apply (<https://kubernetes.io/docs/reference/using-api/api-concepts/#server-side-apply>)
376-
/// Starting from Kubernetes v1.18, you can enable the Server Side Apply feature so that the control plane tracks managed fields for all newly created objects.
376+
/// Starting from Kubernetes v1.18, you can enable the Server Side Apply feature so that the control plane tracks managed fields for all newly created objects.
377377
/// 2) Json (<https://tools.ietf.org/html/rfc6902>):
378-
/// This is supported on crate feature jsonpatch only
378+
/// This is supported on crate feature jsonpatch only
379379
/// 3) Merge (<https://tools.ietf.org/html/rfc7386>):
380-
/// For example, if you want to update a list you have to specify the complete list and update everything
380+
/// For example, if you want to update a list you have to specify the complete list and update everything
381381
/// 4) Strategic (not for CustomResource)
382-
/// With a strategic merge patch, a list is either replaced or merged depending on its patch strategy.
383-
/// The patch strategy is specified by the value of the patchStrategy key in a field tag in the Kubernetes source code.
384-
/// For example, the Containers field of PodSpec struct has a patchStrategy of merge.
382+
/// With a strategic merge patch, a list is either replaced or merged depending on its patch strategy.
383+
/// The patch strategy is specified by the value of the patchStrategy key in a field tag in the Kubernetes source code.
384+
/// For example, the Containers field of PodSpec struct has a patchStrategy of merge.
385385
async fn patch_status<T, S>(
386386
&self,
387387
resource: &T,

crates/stackable-operator/src/commons/listener.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ pub enum KubernetesTrafficPolicy {
110110
/// 1. It uses a cluster-level policy object (ListenerClass) to define how exactly the exposure works
111111
/// 2. It has a consistent API for reading back the exposed address(es) of the service
112112
/// 3. The Pod must mount a Volume referring to the Listener, which also allows
113-
/// ["sticky" scheduling](DOCS_BASE_URL_PLACEHOLDER/listener-operator/listener#_sticky_scheduling).
113+
/// ["sticky" scheduling](DOCS_BASE_URL_PLACEHOLDER/listener-operator/listener#_sticky_scheduling).
114114
///
115115
/// Learn more in the [Listener documentation](DOCS_BASE_URL_PLACEHOLDER/listener-operator/listener).
116116
#[derive(

crates/stackable-operator/src/commons/opa.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,15 @@
4343
//! assert_eq!(opa_config.document_url(&cluster, Some("allow"), OpaApiVersion::V1), "v1/data/test/allow".to_string());
4444
//! assert_eq!(opa_config.full_document_url(&cluster, "http://localhost:8081", None, OpaApiVersion::V1), "http://localhost:8081/v1/data/test".to_string());
4545
//! ```
46-
use std::sync::LazyLock;
47-
4846
use crate::client::{Client, GetApi};
4947
use k8s_openapi::{api::core::v1::ConfigMap, NamespaceResourceScope};
5048
use kube::{Resource, ResourceExt};
49+
use lazy_static::lazy_static;
5150
use regex::Regex;
5251
use schemars::{self, JsonSchema};
5352
use serde::{Deserialize, Serialize};
5453
use snafu::{OptionExt, ResultExt, Snafu};
5554

56-
static DOT_REGEX: LazyLock<Regex> =
57-
LazyLock::new(|| Regex::new("\\.").expect("failed to compile OPA dot regex"));
58-
59-
/// To remove leading slashes from OPA package name (if present)
60-
static LEADING_SLASH_REGEX: LazyLock<Regex> =
61-
LazyLock::new(|| Regex::new("(/*)(.*)").expect("failed to compile OPA leasing slash regex"));
62-
6355
type Result<T, E = Error> = std::result::Result<T, E>;
6456

6557
#[derive(Debug, Snafu)]
@@ -80,6 +72,11 @@ pub enum Error {
8072
},
8173
}
8274

75+
lazy_static! {
76+
static ref DOT_REGEX: Regex = Regex::new("\\.").unwrap();
77+
/// To remove leading slashes from OPA package name (if present)
78+
static ref LEADING_SLASH_REGEX: Regex = Regex::new("(/*)(.*)").unwrap();
79+
}
8380
/// Indicates the OPA API version. This is required to choose the correct
8481
/// path when constructing the OPA urls to query.
8582
pub enum OpaApiVersion {

crates/stackable-operator/src/cpu.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,12 @@ impl Display for CpuQuantity {
101101
impl FromStr for CpuQuantity {
102102
type Err = Error;
103103

104-
/// Only two formats can be parsed:
105-
///
104+
/// Only two formats can be parsed
106105
/// - {usize}m
107106
/// - {f32}
108-
///
109-
/// For the float, only milli-precision is supported. Using more precise
110-
/// values will trigger an error, and using any other unit than 'm' or None
111-
/// will also trigger an error.
107+
/// For the float, only milli-precision is supported.
108+
/// Using more precise values will trigger an error, and using any other
109+
/// unit than 'm' or None will also trigger an error.
112110
fn from_str(q: &str) -> Result<Self> {
113111
let start_of_unit = q.find(|c: char| c != '.' && !c.is_numeric());
114112
if let Some(start_of_unit) = start_of_unit {

crates/stackable-operator/src/kvp/key.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
1-
use std::{fmt::Display, ops::Deref, str::FromStr, sync::LazyLock};
1+
use std::{fmt::Display, ops::Deref, str::FromStr};
22

3+
use lazy_static::lazy_static;
34
use regex::Regex;
45
use snafu::{ensure, ResultExt, Snafu};
56

67
const KEY_PREFIX_MAX_LEN: usize = 253;
78
const KEY_NAME_MAX_LEN: usize = 63;
89

9-
// Lazily initialized regular expressions
10-
static KEY_PREFIX_REGEX: LazyLock<Regex> = LazyLock::new(|| {
11-
Regex::new(r"^[a-zA-Z](\.?[a-zA-Z0-9-])*\.[a-zA-Z]{2,}\.?$")
12-
.expect("failed to compile key prefix regex")
13-
});
14-
15-
static KEY_NAME_REGEX: LazyLock<Regex> = LazyLock::new(|| {
16-
Regex::new(r"^[a-z0-9A-Z]([a-z0-9A-Z-_.]*[a-z0-9A-Z]+)?$")
17-
.expect("failed to compile key name regex")
18-
});
10+
lazy_static! {
11+
static ref KEY_PREFIX_REGEX: Regex =
12+
Regex::new(r"^[a-zA-Z](\.?[a-zA-Z0-9-])*\.[a-zA-Z]{2,}\.?$").unwrap();
13+
static ref KEY_NAME_REGEX: Regex =
14+
Regex::new(r"^[a-z0-9A-Z]([a-z0-9A-Z-_.]*[a-z0-9A-Z]+)?$").unwrap();
15+
}
1916

2017
/// The error type for key parsing/validation operations.
2118
///

crates/stackable-operator/src/kvp/label/value.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
use std::{fmt::Display, ops::Deref, str::FromStr, sync::LazyLock};
1+
use std::{fmt::Display, ops::Deref, str::FromStr};
22

3+
use lazy_static::lazy_static;
34
use regex::Regex;
45
use snafu::{ensure, Snafu};
56

67
use crate::kvp::Value;
78

89
const LABEL_VALUE_MAX_LEN: usize = 63;
910

10-
// Lazily initialized regular expressions
11-
static LABEL_VALUE_REGEX: LazyLock<Regex> = LazyLock::new(|| {
12-
Regex::new(r"^[a-z0-9A-Z]([a-z0-9A-Z-_.]*[a-z0-9A-Z]+)?$")
13-
.expect("failed to compile value regex")
14-
});
11+
lazy_static! {
12+
static ref LABEL_VALUE_REGEX: Regex =
13+
Regex::new(r"^[a-z0-9A-Z]([a-z0-9A-Z-_.]*[a-z0-9A-Z]+)?$").unwrap();
14+
}
1515

1616
/// The error type for label value parse/validation operations.
1717
#[derive(Debug, PartialEq, Snafu)]

crates/stackable-operator/src/memory.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Utilities for converting Kubernetes quantities to Java heap settings.
22
//! Since Java heap sizes are a subset of Kubernetes quantities, the conversion
3-
//! might lose precision or fail completely. In addition:
4-
//!
3+
//! might lose precision or fail completely.
4+
//! In addition:
55
//! - decimal quantities are not supported ("2G" is invalid)
66
//! - units are case sensitive ("2gi" is invalid)
77
//! - exponential notation is not supported.
@@ -121,15 +121,12 @@ impl Display for BinaryMultiple {
121121
}
122122

123123
/// Convert a (memory) [`Quantity`] to Java heap settings.
124-
///
125124
/// Quantities are usually passed on to container resources while Java heap
126-
/// sizes need to be scaled accordingly. This implements a very simple heuristic
127-
/// to ensure that:
128-
///
125+
/// sizes need to be scaled accordingly.
126+
/// This implements a very simple heuristic to ensure that:
129127
/// - the quantity unit has been mapped to a java supported heap unit. Java only
130128
/// supports up to Gibibytes while K8S quantities can be expressed in Exbibytes.
131129
/// - the heap size has a non-zero value.
132-
///
133130
/// Fails if it can't enforce the above restrictions.
134131
#[deprecated(
135132
since = "0.33.0",
@@ -151,17 +148,15 @@ pub fn to_java_heap(q: &Quantity, factor: f32) -> Result<String> {
151148
}
152149

153150
/// Convert a (memory) [`Quantity`] to a raw Java heap value of the desired `target_unit`.
154-
///
155151
/// Quantities are usually passed on to container resources while Java heap
156-
/// sizes need to be scaled accordingly. The raw heap value is converted to the
157-
/// specified `target_unit` (this conversion is done even if specified a unit
158-
/// greater that Gibibytes. It is not recommended to scale to anything bigger
159-
/// than Gibibytes. This implements a very simple heuristic to ensure that:
160-
///
152+
/// sizes need to be scaled accordingly.
153+
/// The raw heap value is converted to the specified `target_unit` (this conversion
154+
/// is done even if specified a unit greater that Gibibytes. It is not recommended to scale
155+
/// to anything bigger than Gibibytes.
156+
/// This implements a very simple heuristic to ensure that:
161157
/// - the quantity unit has been mapped to a java supported heap unit. Java only
162158
/// supports up to Gibibytes while K8S quantities can be expressed in Exbibytes.
163159
/// - the heap size has a non-zero value.
164-
///
165160
/// Fails if it can't enforce the above restrictions.
166161
#[deprecated(
167162
since = "0.33.0",

crates/stackable-operator/src/status/condition/mod.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -290,20 +290,16 @@ impl ClusterConditionSet {
290290
self.conditions[index] = Some(condition);
291291
}
292292

293-
/// Merges two [`ClusterConditionSet`]s.
294-
///
295-
/// The condition_combiner implements the strategy used to merge two
296-
/// conditions of the same `type_`.
293+
/// Merges two [`ClusterConditionSet`]s. The condition_combiner implements the strategy used to
294+
/// merge two conditions of the same `type_`.
297295
///
298296
/// # Arguments
299297
///
300298
/// * `other` - The [`ClusterConditionSet`] to be merged
301-
/// * `condition_combiner` - This is either be `update_message` or
302-
/// `update_timestamps`. The `update_message` is used to concatenate
303-
/// messages of the same [`ClusterConditionStatus`] and the same
304-
/// [`ClusterConditionType`]. The `update_timestamps` is required to merge
305-
/// the old cluster status with the new one and update transition
306-
/// timestamps correctly.
299+
/// * `condition_combiner` - This is either be `update_message` or `update_timestamps`. The
300+
/// `update_message` is used to concatenate messages of the same [`ClusterConditionStatus`] and
301+
/// the same [`ClusterConditionType`]. The `update_timestamps` is required to merge the old
302+
/// cluster status with the new one and update transition timestamps correctly.
307303
fn merge(
308304
self,
309305
other: ClusterConditionSet,
@@ -365,7 +361,7 @@ fn update_timestamps(
365361
/// A condition combiner strategy with the following properties:
366362
/// 1. It preserves the condition with the highest status.
367363
/// 2. It joins the previous messages to the current one if both conditions
368-
/// have the same status.
364+
/// have the same status.
369365
fn update_message(
370366
old_condition: ClusterCondition,
371367
new_condition: ClusterCondition,

0 commit comments

Comments
 (0)