Skip to content

Commit 8fd4dc9

Browse files
committed
chore: First round of pedantic clippy lints
1 parent 380e4fb commit 8fd4dc9

53 files changed

Lines changed: 382 additions & 374 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

crates/stackable-operator/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ All notable changes to this project will be documented in this file.
1010
- Add support for specifying a `clientAuthenticationMethod` for OIDC ([#1178]).
1111
This was originally done in [#1158] and had been reverted in [#1170].
1212

13+
### Changed
14+
15+
- BREAKING: `OpaConfig::full_document_url` now takes `&OpaApiVersion` instead of `OpaApiVersion` ([#XXXX]).
16+
1317
### Removed
1418

1519
- BREAKING: Remove unused `add_prefix`, `try_add_prefix`, `set_name`, and `try_set_name` associated

crates/stackable-operator/src/builder/event.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,7 @@ impl EventBuilder {
116116
reporting_instance: self.reporting_instance.clone(),
117117
series: None,
118118
source,
119-
type_: self
120-
.event_type
121-
.as_ref()
122-
.map(|event_type| event_type.to_string()),
119+
type_: self.event_type.as_ref().map(ToString::to_string),
123120
}
124121
}
125122
}

crates/stackable-operator/src/builder/meta.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ impl ObjectMetaBuilder {
152152
/// for more flexibility if needed.
153153
pub fn with_recommended_labels<T: Resource>(
154154
&mut self,
155-
object_labels: ObjectLabels<T>,
155+
object_labels: &ObjectLabels<T>,
156156
) -> Result<&mut Self> {
157157
let recommended_labels =
158158
Labels::recommended(object_labels).context(RecommendedLabelsSnafu)?;
@@ -206,8 +206,8 @@ impl ObjectMetaBuilder {
206206
.ownerreference
207207
.as_ref()
208208
.map(|ownerreference| vec![ownerreference.clone()]),
209-
labels: self.labels.clone().map(|l| l.into()),
210-
annotations: self.annotations.clone().map(|a| a.into()),
209+
labels: self.labels.clone().map(Into::into),
210+
annotations: self.annotations.clone().map(Into::into),
211211
finalizers: self.finalizers.clone(),
212212
..ObjectMeta::default()
213213
}
@@ -350,7 +350,7 @@ mod tests {
350350
.namespace("bar")
351351
.ownerreference_from_resource(&pod, Some(true), Some(false))
352352
.unwrap()
353-
.with_recommended_labels(ObjectLabels {
353+
.with_recommended_labels(&ObjectLabels {
354354
owner: &pod,
355355
app_name: "test_app",
356356
app_version: "1.0",

crates/stackable-operator/src/builder/pdb.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ impl PodDisruptionBudgetBuilder<ObjectMeta, LabelSelector, PodDisruptionBudgetCo
190190
min_available: min_available.map(i32::from).map(IntOrString::Int),
191191
selector: Some(self.selector),
192192
// Because this feature is still in beta in k8s version 1.27, the builder currently does not offer this attribute.
193-
unhealthy_pod_eviction_policy: Default::default(),
193+
unhealthy_pod_eviction_policy: None,
194194
}),
195195
..Default::default()
196196
}
@@ -250,7 +250,7 @@ mod tests {
250250
}),
251251
..Default::default()
252252
}
253-
)
253+
);
254254
}
255255

256256
#[test]
@@ -340,6 +340,6 @@ mod tests {
340340
}),
341341
..Default::default()
342342
}
343-
)
343+
);
344344
}
345345
}

crates/stackable-operator/src/builder/pod/container.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl ContainerBuilder {
8383
self
8484
}
8585

86-
/// Adds the following container attributes from a [ResolvedProductImage]:
86+
/// Adds the following container attributes from a [`ResolvedProductImage`]:
8787
/// * image
8888
/// * image_pull_policy
8989
pub fn image_from_product_image(&mut self, product_image: &ResolvedProductImage) -> &mut Self {
@@ -118,7 +118,7 @@ impl ContainerBuilder {
118118
pub fn add_env_var_from_field_path(
119119
&mut self,
120120
name: impl Into<String>,
121-
field_path: FieldPathEnvVar,
121+
field_path: &FieldPathEnvVar,
122122
) -> &mut Self {
123123
self.add_env_var_from_source(
124124
name,
@@ -587,12 +587,12 @@ mod tests {
587587
assert_eq!(
588588
source.to_string(),
589589
"input is 64 bytes long but must be no more than 63"
590-
)
590+
);
591591
}
592592
// One characters shorter name is valid
593593
let max_len_container_name: String = long_container_name.chars().skip(1).collect();
594594
assert_eq!(max_len_container_name.len(), 63);
595-
assert!(ContainerBuilder::new(&max_len_container_name).is_ok())
595+
assert!(ContainerBuilder::new(&max_len_container_name).is_ok());
596596
}
597597

598598
#[test]
@@ -644,7 +644,7 @@ mod tests {
644644
.resources(resources.clone())
645645
.build();
646646

647-
assert_eq!(container.resources, Some(resources))
647+
assert_eq!(container.resources, Some(resources));
648648
}
649649

650650
/// Panics if given container builder constructor result is not [Err] with error message

crates/stackable-operator/src/builder/pod/probe.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,10 @@ impl ProbeBuilder<ProbeAction, Duration> {
194194

195195
// SAFETY: Period is checked above to be non-zero
196196
let success_threshold = success_threshold_duration.div_duration_f32(*self.period);
197-
Ok(self.with_success_threshold(success_threshold.ceil() as i32))
197+
// Note: We calculate an f32, which can overflow an i32, so we clamp it to bo in range
198+
#[expect(clippy::cast_possible_truncation)]
199+
#[expect(clippy::cast_precision_loss)]
200+
Ok(self.with_success_threshold(success_threshold.ceil().clamp(0.0, i32::MAX as f32) as i32))
198201
}
199202

200203
/// After a probe fails `failureThreshold` times in a row, Kubernetes considers that the
@@ -257,7 +260,10 @@ impl ProbeBuilder<ProbeAction, Duration> {
257260

258261
// SAFETY: Period is checked above to be non-zero
259262
let failure_threshold = failure_threshold_duration.div_duration_f32(*self.period);
260-
Ok(self.with_failure_threshold(failure_threshold.ceil() as i32))
263+
// Note: We calculate an f32, which can overflow an i32, so we clamp it to bo in range
264+
#[expect(clippy::cast_possible_truncation)]
265+
#[expect(clippy::cast_precision_loss)]
266+
Ok(self.with_failure_threshold(failure_threshold.ceil().clamp(0.0, i32::MAX as f32) as i32))
261267
}
262268

263269
/// Build the [`Probe`] using the specified contents.

crates/stackable-operator/src/builder/pod/resources.rs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@ impl<MR, ML> ResourceRequirementsBuilder<Quantity, (), MR, ML> {
9898
}
9999
}
100100

101-
impl<CR, CL, ML> ResourceRequirementsBuilder<CL, CR, (), ML> {
101+
impl<CR, CL, ML> ResourceRequirementsBuilder<CR, CL, (), ML> {
102102
pub fn with_memory_request(
103103
self,
104104
request: impl Into<String>,
105-
) -> ResourceRequirementsBuilder<CL, CR, Quantity, ML> {
105+
) -> ResourceRequirementsBuilder<CR, CL, Quantity, ML> {
106106
let Self {
107107
cpu_request,
108108
cpu_limit,
@@ -124,7 +124,7 @@ impl<CR, CL, ML> ResourceRequirementsBuilder<CL, CR, (), ML> {
124124
self,
125125
request: impl Into<String>,
126126
factor: f32,
127-
) -> memory::Result<ResourceRequirementsBuilder<CL, CR, Quantity, Quantity>> {
127+
) -> memory::Result<ResourceRequirementsBuilder<CR, CL, Quantity, Quantity>> {
128128
let request = MemoryQuantity::from_str(&request.into())?;
129129
let limit = request * factor;
130130

@@ -168,7 +168,7 @@ impl<CR, CL> ResourceRequirementsBuilder<CR, CL, Quantity, ()> {
168168
}
169169
}
170170

171-
impl<CL, CR, ML, MR> ResourceRequirementsBuilder<CL, CR, ML, MR> {
171+
impl<CR, CL, MR, ML> ResourceRequirementsBuilder<CR, CL, MR, ML> {
172172
pub fn with_resource(
173173
mut self,
174174
rr_type: ResourceRequirementsType,
@@ -185,21 +185,18 @@ impl<CL, CR, ML, MR> ResourceRequirementsBuilder<CL, CR, ML, MR> {
185185

186186
let resource = resource.to_string();
187187

188-
match self.other.get_mut(&resource) {
189-
Some(types) => {
190-
if types.contains_key(&rr_type) {
191-
warn!(
192-
"resource {} for '{}' already set, not overwriting",
193-
rr_type, resource
194-
);
195-
}
196-
197-
types.insert(rr_type, Quantity(quantity.into()));
198-
}
199-
None => {
200-
let types = BTreeMap::from([(rr_type, Quantity(quantity.into()))]);
201-
self.other.insert(resource, types);
188+
if let Some(types) = self.other.get_mut(&resource) {
189+
if types.contains_key(&rr_type) {
190+
warn!(
191+
"resource {} for '{}' already set, not overwriting",
192+
rr_type, resource
193+
);
202194
}
195+
196+
types.insert(rr_type, Quantity(quantity.into()));
197+
} else {
198+
let types = BTreeMap::from([(rr_type, Quantity(quantity.into()))]);
199+
self.other.insert(resource, types);
203200
}
204201

205202
self
@@ -286,6 +283,6 @@ mod tests {
286283
.with_resource(ResourceRequirementsType::Requests, "nvidia.com/gpu", "1")
287284
.build();
288285

289-
assert_eq!(rr, resources)
286+
assert_eq!(rr, resources);
290287
}
291288
}

crates/stackable-operator/src/builder/pod/volume.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl VolumeBuilder {
8484
quantity: Option<Quantity>,
8585
) -> &mut Self {
8686
self.volume_source = VolumeSource::EmptyDir(EmptyDirVolumeSource {
87-
medium: medium.map(|m| m.into()),
87+
medium: medium.map(Into::into),
8888
size_limit: quantity,
8989
});
9090
self
@@ -102,7 +102,7 @@ impl VolumeBuilder {
102102
) -> &mut Self {
103103
self.volume_source = VolumeSource::HostPath(HostPathVolumeSource {
104104
path: path.into(),
105-
type_: type_.map(|t| t.into()),
105+
type_: type_.map(Into::into),
106106
});
107107
self
108108
}
@@ -362,12 +362,12 @@ impl SecretOperatorVolumeSourceBuilder {
362362

363363
if let Some(password) = &self.tls_pkcs12_password {
364364
// The `tls_pkcs12_password` is only used for PKCS12 stores.
365-
if Some(SecretFormat::TlsPkcs12) != self.format {
366-
warn!(format.actual = ?self.format, format.expected = ?Some(SecretFormat::TlsPkcs12), "A TLS PKCS12 password was set but ignored because another format was requested")
367-
} else {
365+
if Some(SecretFormat::TlsPkcs12) == self.format {
368366
annotations.insert(
369367
Annotation::tls_pkcs12_password(password).context(ParseAnnotationSnafu)?,
370368
);
369+
} else {
370+
warn!(format.actual = ?self.format, format.expected = ?Some(SecretFormat::TlsPkcs12), "A TLS PKCS12 password was set but ignored because another format was requested");
371371
}
372372
}
373373

@@ -500,18 +500,6 @@ impl ListenerOperatorVolumeSourceBuilder {
500500
}
501501
}
502502

503-
fn build_spec(&self) -> PersistentVolumeClaimSpec {
504-
PersistentVolumeClaimSpec {
505-
storage_class_name: Some("listeners.stackable.tech".to_string()),
506-
resources: Some(VolumeResourceRequirements {
507-
requests: Some([("storage".to_string(), Quantity("1".to_string()))].into()),
508-
..Default::default()
509-
}),
510-
access_modes: Some(vec!["ReadWriteMany".to_string()]),
511-
..PersistentVolumeClaimSpec::default()
512-
}
513-
}
514-
515503
#[deprecated(note = "renamed to `build_ephemeral`", since = "0.61.1")]
516504
pub fn build(&self) -> Result<EphemeralVolumeSource, ListenerOperatorVolumeSourceBuilderError> {
517505
self.build_ephemeral()
@@ -534,7 +522,7 @@ impl ListenerOperatorVolumeSourceBuilder {
534522
.with_labels(self.labels.clone())
535523
.build(),
536524
),
537-
spec: self.build_spec(),
525+
spec: Self::spec(),
538526
}),
539527
})
540528
}
@@ -555,10 +543,22 @@ impl ListenerOperatorVolumeSourceBuilder {
555543
.with_annotation(listener_reference_annotation)
556544
.with_labels(self.labels.clone())
557545
.build(),
558-
spec: Some(self.build_spec()),
546+
spec: Some(Self::spec()),
559547
..Default::default()
560548
})
561549
}
550+
551+
fn spec() -> PersistentVolumeClaimSpec {
552+
PersistentVolumeClaimSpec {
553+
storage_class_name: Some("listeners.stackable.tech".to_string()),
554+
resources: Some(VolumeResourceRequirements {
555+
requests: Some([("storage".to_string(), Quantity("1".to_string()))].into()),
556+
..Default::default()
557+
}),
558+
access_modes: Some(vec!["ReadWriteMany".to_string()]),
559+
..PersistentVolumeClaimSpec::default()
560+
}
561+
}
562562
}
563563

564564
#[cfg(test)]

crates/stackable-operator/src/cli/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,6 @@ mod tests {
126126
RunArguments::command()
127127
.print_long_help()
128128
.expect("help message should be printed to stdout");
129-
RunArguments::command().debug_assert()
129+
RunArguments::command().debug_assert();
130130
}
131131
}

crates/stackable-operator/src/cli/product_config.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl ProductConfigPath {
5959
let search_paths = if let Some(path) = user_provided_path {
6060
vec![path]
6161
} else {
62-
default_paths.iter().map(|path| path.as_ref()).collect()
62+
default_paths.iter().map(AsRef::as_ref).collect()
6363
};
6464
for path in &search_paths {
6565
if path.exists() {
@@ -148,7 +148,7 @@ mod tests {
148148
}
149149

150150
#[test]
151-
#[should_panic]
151+
#[should_panic = "RequiredFileMissing { search_path: [\"user_provided_path_properties.yaml\"] }"]
152152
fn resolve_path_user_path_not_existing() {
153153
ProductConfigPath::resolve_path(Some(USER_PROVIDED_PATH.as_ref()), &[DEPLOY_FILE_PATH])
154154
.unwrap();
@@ -165,7 +165,7 @@ mod tests {
165165
PathBuf::from(DEPLOY_FILE_PATH),
166166
PathBuf::from(DEFAULT_FILE_PATH)
167167
]
168-
)
168+
);
169169
} else {
170170
panic!("must return RequiredFileMissing when file was not found")
171171
}

0 commit comments

Comments
 (0)