Skip to content

chore: Use Rust 2024 edition #994

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Apr 2, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
57 changes: 1 addition & 56 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ env:
CARGO_TERM_COLOR: always
CARGO_INCREMENTAL: '0'
CARGO_PROFILE_DEV_DEBUG: '0'
RUST_TOOLCHAIN_VERSION: "1.84.1"
RUST_TOOLCHAIN_VERSION: "1.85.0"
RUSTFLAGS: "-D warnings"
RUSTDOCFLAGS: "-D warnings"
RUST_LOG: "info"
Expand Down Expand Up @@ -64,59 +64,6 @@ jobs:
with:
command: check ${{ matrix.checks }}

run_rustfmt:
name: Run Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_TOOLCHAIN_VERSION }}
components: rustfmt
- uses: Swatinem/rust-cache@f0deed1e0edfc6a9be95417288c0e1099b1eeec3 # v2.7.7
with:
key: fmt
- run: cargo fmt --all -- --check

run_clippy:
name: Run Clippy
runs-on: ubuntu-latest
steps:
- name: Install host dependencies
run: |
sudo apt-get update
sudo apt-get install protobuf-compiler krb5-user libkrb5-dev libclang-dev liblzma-dev libssl-dev pkg-config
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false
submodules: recursive
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_TOOLCHAIN_VERSION }}
components: clippy
- uses: Swatinem/rust-cache@f0deed1e0edfc6a9be95417288c0e1099b1eeec3 # v2.7.7
with:
key: clippy
- name: Run clippy action to produce annotations
# NOTE (@Techassi): This action might get a new release sonn, because it
# currently uses Node 16, which is deprecated in the next few months by
# GitHub. See https://github.com/giraffate/clippy-action/pull/87
uses: giraffate/clippy-action@13b9d32482f25d29ead141b79e7e04e7900281e0 # v1.0.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: env.GITHUB_TOKEN != null && github.event.pull_request.draft == false
with:
clippy_flags: --all-targets -- -D warnings
reporter: 'github-pr-review'
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Run clippy manually without annotations
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: env.GITHUB_TOKEN == null
run: cargo clippy --color never -q --all-targets -- -D warnings

run_rustdoc:
name: Run RustDoc
runs-on: ubuntu-latest
Expand All @@ -136,8 +83,6 @@ jobs:
run_tests:
name: Run Cargo Tests
needs:
- run_clippy
- run_rustfmt
- run_rustdoc
runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:
- crates/**

env:
RUST_TOOLCHAIN_VERSION: "1.84.1"
RUST_TOOLCHAIN_VERSION: "1.85.0"

permissions: {}

Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[workspace]
members = ["crates/*"]
resolver = "2"
resolver = "3"

[workspace.package]
authors = ["Stackable GmbH <info@stackable.de>"]
license = "Apache-2.0"
edition = "2021"
edition = "2024"
repository = "https://github.com/stackabletech/operator-rs"

[workspace.dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/k8s-version/src/group.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{fmt, ops::Deref, str::FromStr, sync::LazyLock};

use regex::Regex;
use snafu::{ensure, Snafu};
use snafu::{Snafu, ensure};

const MAX_GROUP_LENGTH: usize = 253;

Expand Down
4 changes: 3 additions & 1 deletion crates/k8s-version/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ static VERSION_REGEX: LazyLock<Regex> = LazyLock::new(|| {
/// unparsed input.
#[derive(Debug, PartialEq, Snafu)]
pub enum ParseVersionError {
#[snafu(display("invalid version format. Input is empty, contains non-ASCII characters or contains more than 63 characters"))]
#[snafu(display(
"invalid version format. Input is empty, contains non-ASCII characters or contains more than 63 characters"
))]
InvalidFormat,

#[snafu(display("failed to parse major version"))]
Expand Down
4 changes: 2 additions & 2 deletions crates/stackable-certs/src/ca/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use stackable_operator::{client::Client, commons::secret::SecretReference, time:
use tracing::{debug, instrument};
use x509_cert::{
builder::{Builder, CertificateBuilder, Profile},
der::{pem::LineEnding, referenced::OwnedToRef, DecodePem},
der::{DecodePem, pem::LineEnding, referenced::OwnedToRef},
ext::pkix::{AuthorityKeyIdentifier, ExtendedKeyUsage},
name::Name,
serial_number::SerialNumber,
Expand All @@ -19,8 +19,8 @@ use x509_cert::{
};

use crate::{
keys::{ecdsa, rsa, CertificateKeypair},
CertificatePair,
keys::{CertificateKeypair, ecdsa, rsa},
};

mod consts;
Expand Down
2 changes: 1 addition & 1 deletion crates/stackable-certs/src/keys/ecdsa.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Abstraction layer around the [`ecdsa`] crate. This module provides types
//! which abstract away the generation of ECDSA keys used for signing of CAs
//! and other certificates.
use p256::{pkcs8::DecodePrivateKey, NistP256};
use p256::{NistP256, pkcs8::DecodePrivateKey};
use rand_core::{CryptoRngCore, OsRng};
use snafu::{ResultExt, Snafu};
use tracing::instrument;
Expand Down
2 changes: 1 addition & 1 deletion crates/stackable-certs/src/keys/rsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! which abstract away the generation of RSA keys used for signing of CAs
//! and other certificates.
use rand_core::{CryptoRngCore, OsRng};
use rsa::{pkcs8::DecodePrivateKey, RsaPrivateKey};
use rsa::{RsaPrivateKey, pkcs8::DecodePrivateKey};
use signature::Keypair;
use snafu::{ResultExt, Snafu};
use tracing::instrument;
Expand Down
2 changes: 1 addition & 1 deletion crates/stackable-certs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use std::ops::Deref;

use snafu::Snafu;
use x509_cert::{spki::EncodePublicKey, Certificate};
use x509_cert::{Certificate, spki::EncodePublicKey};
#[cfg(feature = "rustls")]
use {
p256::pkcs8::EncodePrivateKey,
Expand Down
10 changes: 5 additions & 5 deletions crates/stackable-operator-derive/src/fragment.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use darling::{ast::Data, FromDeriveInput, FromField, FromMeta, FromVariant};
use darling::{FromDeriveInput, FromField, FromMeta, FromVariant, ast::Data};
use proc_macro2::{Ident, TokenStream, TokenTree};
use quote::{format_ident, quote, ToTokens};
use quote::{ToTokens, format_ident, quote};
use syn::{
parse_quote, Attribute, DeriveInput, Generics, Meta, MetaList, Path, Type, Visibility,
WherePredicate,
Attribute, DeriveInput, Generics, Meta, MetaList, Path, Type, Visibility, WherePredicate,
parse_quote,
};

#[derive(FromMeta)]
Expand Down Expand Up @@ -125,7 +125,7 @@ pub fn derive(input: DeriveInput) -> TokenStream {
Data::Enum(_) => {
return quote! {
compile_error!("`#[derive(Fragment)]` does not currently support enums");
}
};
}
Data::Struct(fields) => fields.fields,
};
Expand Down
15 changes: 6 additions & 9 deletions crates/stackable-operator-derive/src/merge.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use darling::{
ast::{Data, Fields},
FromDeriveInput, FromField, FromMeta, FromVariant,
ast::{Data, Fields},
};
use proc_macro2::{Ident, Span, TokenStream};
use quote::{format_ident, quote};
use syn::{parse_quote, DeriveInput, Generics, Index, Path, WherePredicate};
use syn::{DeriveInput, Generics, Index, Path, WherePredicate, parse_quote};

#[derive(FromMeta)]
struct PathOverrides {
Expand Down Expand Up @@ -67,13 +67,10 @@ pub fn derive(input: DeriveInput) -> TokenStream {

let (ty, variants) = match data {
// Structs are almost single-variant enums, so we can reuse most of the same matching code for both cases
Data::Struct(fields) => (
InputType::Struct,
vec![MergeVariant {
ident: Ident::new("__placeholder", Span::call_site()),
fields,
}],
),
Data::Struct(fields) => (InputType::Struct, vec![MergeVariant {
ident: Ident::new("__placeholder", Span::call_site()),
fields,
}]),
Data::Enum(variants) => (InputType::Enum, variants),
};
let merge_variants = variants
Expand Down
111 changes: 52 additions & 59 deletions crates/stackable-operator/src/builder/pdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ mod tests {
api::policy::v1::{PodDisruptionBudget, PodDisruptionBudgetSpec},
apimachinery::pkg::{apis::meta::v1::LabelSelector, util::intstr::IntOrString},
};
use kube::{core::ObjectMeta, CustomResource};
use kube::{CustomResource, core::ObjectMeta};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

Expand All @@ -229,28 +229,22 @@ mod tests {
.with_min_available(42)
.build();

assert_eq!(
pdb,
PodDisruptionBudget {
metadata: ObjectMeta {
name: Some("trino".to_string()),
namespace: Some("default".to_string()),
..Default::default()
},
spec: Some(PodDisruptionBudgetSpec {
min_available: Some(IntOrString::Int(42)),
selector: Some(LabelSelector {
match_expressions: None,
match_labels: Some(BTreeMap::from([(
"foo".to_string(),
"bar".to_string()
)])),
}),
..Default::default()
assert_eq!(pdb, PodDisruptionBudget {
metadata: ObjectMeta {
name: Some("trino".to_string()),
namespace: Some("default".to_string()),
..Default::default()
},
spec: Some(PodDisruptionBudgetSpec {
min_available: Some(IntOrString::Int(42)),
selector: Some(LabelSelector {
match_expressions: None,
match_labels: Some(BTreeMap::from([("foo".to_string(), "bar".to_string())])),
}),
..Default::default()
}
)
}),
..Default::default()
})
}

#[test]
Expand Down Expand Up @@ -289,55 +283,54 @@ mod tests {
.with_max_unavailable(2)
.build();

assert_eq!(
pdb,
PodDisruptionBudget {
metadata: ObjectMeta {
name: Some("simple-trino-worker".to_string()),
namespace: Some("default".to_string()),
labels: Some(BTreeMap::from([
assert_eq!(pdb, PodDisruptionBudget {
metadata: ObjectMeta {
name: Some("simple-trino-worker".to_string()),
namespace: Some("default".to_string()),
labels: Some(BTreeMap::from([
("app.kubernetes.io/name".to_string(), "trino".to_string()),
(
"app.kubernetes.io/instance".to_string(),
"simple-trino".to_string()
),
(
"app.kubernetes.io/managed-by".to_string(),
"trino.stackable.tech_trino-operator-trino-controller".to_string()
),
(
"app.kubernetes.io/component".to_string(),
"worker".to_string()
)
])),
owner_references: Some(vec![
OwnerReferenceBuilder::new()
.initialize_from_resource(&trino)
.block_owner_deletion_opt(None)
.controller_opt(Some(true))
.build()
.unwrap()
]),
..Default::default()
},
spec: Some(PodDisruptionBudgetSpec {
max_unavailable: Some(IntOrString::Int(2)),
selector: Some(LabelSelector {
match_expressions: None,
match_labels: Some(BTreeMap::from([
("app.kubernetes.io/name".to_string(), "trino".to_string()),
(
"app.kubernetes.io/instance".to_string(),
"simple-trino".to_string()
),
(
"app.kubernetes.io/managed-by".to_string(),
"trino.stackable.tech_trino-operator-trino-controller".to_string()
),
(
"app.kubernetes.io/component".to_string(),
"worker".to_string()
)
])),
owner_references: Some(vec![OwnerReferenceBuilder::new()
.initialize_from_resource(&trino)
.block_owner_deletion_opt(None)
.controller_opt(Some(true))
.build()
.unwrap()]),
..Default::default()
},
spec: Some(PodDisruptionBudgetSpec {
max_unavailable: Some(IntOrString::Int(2)),
selector: Some(LabelSelector {
match_expressions: None,
match_labels: Some(BTreeMap::from([
("app.kubernetes.io/name".to_string(), "trino".to_string()),
(
"app.kubernetes.io/instance".to_string(),
"simple-trino".to_string()
),
(
"app.kubernetes.io/component".to_string(),
"worker".to_string()
)
])),
}),
..Default::default()
}),
..Default::default()
}
)
}),
..Default::default()
})
}
}
Loading