Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pr_pre-commit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

env:
CARGO_TERM_COLOR: always
RUST_TOOLCHAIN_VERSION: "1.82.0"
RUST_TOOLCHAIN_VERSION: "nightly-2025-01-15"
HADOLINT_VERSION: "v1.17.6"

jobs:
Expand Down
9 changes: 7 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ repos:
- repo: https://github.com/doublify/pre-commit-rust
rev: eeee35a89e69d5772bdee97db1a6a898467b686e # 1.0
hooks:
- id: fmt
args: ["--all", "--", "--check"]
- id: clippy
args: ["--all-targets", "--", "-D", "warnings"]
- repo: https://github.com/adrienverge/yamllint
Expand Down Expand Up @@ -53,3 +51,10 @@ repos:
entry: .scripts/verify_crate_versions.sh
stages: [pre-commit, pre-merge-commit, manual]
pass_filenames: false

- id: rustfmt
name: rustfmt
language: system
entry: cargo +nightly-2025-01-15 fmt --all -- --check
stages: [pre-commit]
pass_filenames: false
12 changes: 5 additions & 7 deletions crates/k8s-version/src/api_version.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use std::{cmp::Ordering, fmt::Display, str::FromStr};

use snafu::{ResultExt, Snafu};

#[cfg(feature = "darling")]
use darling::FromMeta;
use snafu::{ResultExt, Snafu};

use crate::{Group, ParseGroupError, ParseVersionError, Version};

Expand Down Expand Up @@ -102,13 +101,12 @@ impl ApiVersion {

#[cfg(test)]
mod test {
use super::*;
use crate::Level;

use rstest::rstest;

#[cfg(feature = "darling")]
use quote::quote;
use rstest::rstest;

use super::*;
use crate::Level;

#[cfg(feature = "darling")]
fn parse_meta(tokens: proc_macro2::TokenStream) -> ::std::result::Result<syn::Meta, String> {
Expand Down
10 changes: 4 additions & 6 deletions crates/k8s-version/src/level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ use std::{
sync::LazyLock,
};

use regex::Regex;
use snafu::{OptionExt, ResultExt, Snafu};

#[cfg(feature = "darling")]
use darling::FromMeta;
use regex::Regex;
use snafu::{OptionExt, ResultExt, Snafu};

static LEVEL_REGEX: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(r"^(?P<identifier>[a-z]+)(?P<version>\d+)$").expect("failed to compile level regex")
Expand Down Expand Up @@ -158,14 +157,13 @@ impl FromMeta for Level {

#[cfg(test)]
mod test {
#[cfg(feature = "darling")]
use quote::quote;
use rstest::rstest;
use rstest_reuse::*;

use super::*;

#[cfg(feature = "darling")]
use quote::quote;

#[cfg(feature = "darling")]
fn parse_meta(tokens: proc_macro2::TokenStream) -> ::std::result::Result<syn::Meta, String> {
let attribute: syn::Attribute = syn::parse_quote!(#[#tokens]);
Expand Down
10 changes: 4 additions & 6 deletions crates/k8s-version/src/version.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use std::{cmp::Ordering, fmt::Display, num::ParseIntError, str::FromStr, sync::LazyLock};

use regex::Regex;
use snafu::{OptionExt, ResultExt, Snafu};

#[cfg(feature = "darling")]
use darling::FromMeta;
use regex::Regex;
use snafu::{OptionExt, ResultExt, Snafu};

use crate::{Level, ParseLevelError};

Expand Down Expand Up @@ -117,14 +116,13 @@ impl Version {

#[cfg(test)]
mod test {
#[cfg(feature = "darling")]
use quote::quote;
use rstest::rstest;
use rstest_reuse::{apply, template};

use super::*;

#[cfg(feature = "darling")]
use quote::quote;

#[cfg(feature = "darling")]
fn parse_meta(tokens: proc_macro2::TokenStream) -> ::std::result::Result<syn::Meta, String> {
let attribute: syn::Attribute = syn::parse_quote!(#[#tokens]);
Expand Down
5 changes: 2 additions & 3 deletions crates/stackable-certs/src/keys/ecdsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,11 @@ impl SigningKey {
}

impl CertificateKeypair for SigningKey {
type SigningKey = p256::ecdsa::SigningKey;
type Error = Error;
type Signature = ecdsa::der::Signature<NistP256>;
type SigningKey = p256::ecdsa::SigningKey;
type VerifyingKey = p256::ecdsa::VerifyingKey;

type Error = Error;

fn signing_key(&self) -> &Self::SigningKey {
&self.0
}
Expand Down
4 changes: 2 additions & 2 deletions crates/stackable-certs/src/keys/rsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ impl SigningKey {
}

impl CertificateKeypair for SigningKey {
type SigningKey = rsa::pkcs1v15::SigningKey<sha2::Sha256>;
type Error = Error;
type Signature = rsa::pkcs1v15::Signature;
type SigningKey = rsa::pkcs1v15::SigningKey<sha2::Sha256>;
type VerifyingKey = rsa::pkcs1v15::VerifyingKey<sha2::Sha256>;
type Error = Error;

fn signing_key(&self) -> &Self::SigningKey {
&self.0
Expand Down
5 changes: 2 additions & 3 deletions crates/stackable-certs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#[cfg(feature = "rustls")]
use std::ops::Deref;

use snafu::Snafu;
use x509_cert::{spki::EncodePublicKey, Certificate};
#[cfg(feature = "rustls")]
use {
p256::pkcs8::EncodePrivateKey,
Expand All @@ -29,9 +31,6 @@ use {
x509_cert::der::Encode,
};

use snafu::Snafu;
use x509_cert::{spki::EncodePublicKey, Certificate};

use crate::keys::CertificateKeypair;

pub mod ca;
Expand Down
7 changes: 4 additions & 3 deletions crates/stackable-operator/src/builder/configmap.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::BTreeMap;

use k8s_openapi::{api::core::v1::ConfigMap, apimachinery::pkg::apis::meta::v1::ObjectMeta};
use snafu::{OptionExt, Snafu};
use std::collections::BTreeMap;

type Result<T, E = Error> = std::result::Result<T, E>;

Expand Down Expand Up @@ -64,10 +65,10 @@ impl ConfigMapBuilder {

#[cfg(test)]
mod tests {
use crate::builder::{configmap::ConfigMapBuilder, meta::ObjectMetaBuilder};

use std::collections::BTreeMap;

use crate::builder::{configmap::ConfigMapBuilder, meta::ObjectMetaBuilder};

#[test]
fn configmap_builder() {
let mut data = BTreeMap::new();
Expand Down
3 changes: 2 additions & 1 deletion crates/stackable-operator/src/builder/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,10 @@ impl OwnerReferenceBuilder {

#[cfg(test)]
mod tests {
use k8s_openapi::api::core::v1::Pod;

use super::*;
use crate::builder::meta::ObjectMetaBuilder;
use k8s_openapi::api::core::v1::Pod;

#[test]
fn objectmeta_builder() {
Expand Down
3 changes: 1 addition & 2 deletions crates/stackable-operator/src/builder/pdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,9 @@ mod tests {
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use super::*;
use crate::builder::meta::{ObjectMetaBuilder, OwnerReferenceBuilder};

use super::PodDisruptionBudgetBuilder;

#[test]
pub fn normal_build() {
#[allow(deprecated)]
Expand Down
5 changes: 2 additions & 3 deletions crates/stackable-operator/src/builder/pod/container.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use std::fmt;

#[cfg(doc)]
use {k8s_openapi::api::core::v1::PodSpec, std::collections::BTreeMap};

use indexmap::IndexMap;
use k8s_openapi::api::core::v1::{
ConfigMapKeySelector, Container, ContainerPort, EnvVar, EnvVarSource, Lifecycle,
Expand All @@ -11,6 +8,8 @@ use k8s_openapi::api::core::v1::{
};
use snafu::{ResultExt as _, Snafu};
use tracing::instrument;
#[cfg(doc)]
use {k8s_openapi::api::core::v1::PodSpec, std::collections::BTreeMap};

use crate::{
commons::product_image_selection::ResolvedProductImage,
Expand Down
12 changes: 6 additions & 6 deletions crates/stackable-operator/src/builder/pod/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ use k8s_openapi::{
use snafu::{OptionExt, ResultExt, Snafu};
use tracing::{instrument, warn};

use crate::kvp::Labels;
use crate::{
builder::meta::ObjectMetaBuilder,
builder::{
meta::ObjectMetaBuilder,
pod::volume::{ListenerOperatorVolumeSourceBuilder, ListenerReference, VolumeBuilder},
},
commons::{
affinity::StackableAffinity,
product_image_selection::ResolvedProductImage,
Expand All @@ -23,11 +25,10 @@ use crate::{
LIMIT_REQUEST_RATIO_CPU, LIMIT_REQUEST_RATIO_MEMORY,
},
},
kvp::Labels,
time::Duration,
};

use self::volume::{ListenerOperatorVolumeSourceBuilder, ListenerReference, VolumeBuilder};

pub mod container;
pub mod resources;
pub mod security;
Expand Down Expand Up @@ -633,6 +634,7 @@ mod tests {
};
use rstest::*;

use super::*;
use crate::builder::{
meta::ObjectMetaBuilder,
pod::{
Expand All @@ -641,8 +643,6 @@ mod tests {
},
};

use super::*;

// A simple [`Container`] with a name and image.
#[fixture]
fn dummy_container() -> Container {
Expand Down
7 changes: 6 additions & 1 deletion crates/stackable-operator/src/builder/pod/security.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ impl SecurityContextBuilder {
sc.level = Some(level.into());
self
}

pub fn se_linux_role(&mut self, role: impl Into<String>) -> &mut Self {
let sc = self
.security_context
Expand Down Expand Up @@ -201,6 +202,7 @@ impl PodSecurityContextBuilder {
));
self
}

pub fn se_linux_role(&mut self, role: &str) -> &mut Self {
self.pod_security_context.se_linux_options =
Some(self.pod_security_context.se_linux_options.clone().map_or(
Expand All @@ -215,6 +217,7 @@ impl PodSecurityContextBuilder {
));
self
}

pub fn se_linux_type(&mut self, type_: &str) -> &mut Self {
self.pod_security_context.se_linux_options =
Some(self.pod_security_context.se_linux_options.clone().map_or(
Expand All @@ -229,6 +232,7 @@ impl PodSecurityContextBuilder {
));
self
}

pub fn se_linux_user(&mut self, user: &str) -> &mut Self {
self.pod_security_context.se_linux_options =
Some(self.pod_security_context.se_linux_options.clone().map_or(
Expand Down Expand Up @@ -335,9 +339,10 @@ impl PodSecurityContextBuilder {

#[cfg(test)]
mod tests {
use super::*;
use k8s_openapi::api::core::v1::{PodSecurityContext, SELinuxOptions, SeccompProfile, Sysctl};

use super::*;

#[test]
fn security_context_builder() {
let mut builder = PodSecurityContextBuilder::new();
Expand Down
7 changes: 4 additions & 3 deletions crates/stackable-operator/src/builder/pod/volume.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use k8s_openapi::{
},
apimachinery::pkg::api::resource::Quantity,
};

use snafu::{ResultExt, Snafu};
use tracing::warn;

Expand Down Expand Up @@ -568,10 +567,12 @@ impl ListenerOperatorVolumeSourceBuilder {

#[cfg(test)]
mod tests {
use super::*;
use k8s_openapi::apimachinery::pkg::api::resource::Quantity;
use std::collections::BTreeMap;

use k8s_openapi::apimachinery::pkg::api::resource::Quantity;

use super::*;

#[test]
fn builder() {
let mut volume_builder = VolumeBuilder::new("name");
Expand Down
7 changes: 4 additions & 3 deletions crates/stackable-operator/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,14 @@ fn resolve_path<'a>(

#[cfg(test)]
mod tests {
use super::*;
use std::{env, fs::File};

use clap::Parser;
use rstest::*;
use std::env;
use std::fs::File;
use tempfile::tempdir;

use super::*;

const USER_PROVIDED_PATH: &str = "user_provided_path_properties.yaml";
const DEPLOY_FILE_PATH: &str = "deploy_config_spec_properties.yaml";
const DEFAULT_FILE_PATH: &str = "default_file_path_properties.yaml";
Expand Down
Loading