Skip to content

Commit d0ac5ae

Browse files
authored
fix(stackable-operator): Re-export versioned error types (#1025)
* fix(stackable-operator): Re-export versioned error types * chore(stackable-operator): Adjust doc comments * chore(stackable-operator): Add pub keyword * chore(stackable-operator): Use re-exported macro * chore(stackable-operator): Add changelog entry
1 parent 51dc280 commit d0ac5ae

File tree

11 files changed

+220
-197
lines changed

11 files changed

+220
-197
lines changed

crates/stackable-operator/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ All notable changes to this project will be documented in this file.
1212
- The `static` authentication provider must now be imported using `r#static`.
1313
- Import are now more granular in general.
1414

15+
### Fixed
16+
17+
- Re-export versioned CRD-specific error types ([#1025]).
18+
1519
[#968]: https://github.com/stackabletech/operator-rs/pull/968
20+
[#1025]: https://github.com/stackabletech/operator-rs/pull/1025
1621

1722
## [0.92.0] - 2025-04-14
1823

crates/stackable-operator/src/crd/authentication/core/mod.rs

+28-19
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
use kube::CustomResource;
22
use schemars::JsonSchema;
33
use serde::{Deserialize, Serialize};
4-
use stackable_versioned::versioned;
4+
5+
use crate::versioned::versioned;
56

67
mod v1alpha1_impl;
78

89
#[versioned(version(name = "v1alpha1"))]
910
pub mod versioned {
10-
// This makes v1alpha1 versions of all authentication providers available to the
11-
// AuthenticationClassProvider enum below.
12-
mod v1alpha1 {
11+
pub mod v1alpha1 {
12+
// Re-export the v1alpha1-specific error type from the private impl module.
13+
pub use v1alpha1_impl::Error;
14+
15+
// This makes v1alpha1 versions of all authentication providers available to the
16+
// AuthenticationClassProvider enum below.
1317
use crate::crd::authentication::{kerberos, ldap, oidc, r#static, tls};
1418
}
1519
/// The Stackable Platform uses the AuthenticationClass as a central mechanism to handle user
@@ -79,18 +83,20 @@ pub mod versioned {
7983
Oidc(oidc::v1alpha1::AuthenticationProvider),
8084

8185
/// The [TLS provider](DOCS_BASE_URL_PLACEHOLDER/concepts/authentication#_tls).
82-
/// The TLS AuthenticationClass is used when users should authenticate themselves with a TLS certificate.
86+
/// The TLS AuthenticationClass is used when users should authenticate themselves with a
87+
/// TLS certificate.
8388
Tls(tls::v1alpha1::AuthenticationProvider),
8489

8590
/// The [Kerberos provider](DOCS_BASE_URL_PLACEHOLDER/concepts/authentication#_kerberos).
86-
/// The Kerberos AuthenticationClass is used when users should authenticate themselves via Kerberos.
91+
/// The Kerberos AuthenticationClass is used when users should authenticate themselves via
92+
/// Kerberos.
8793
Kerberos(kerberos::v1alpha1::AuthenticationProvider),
8894
}
8995

90-
/// Common [`v1alpha1::ClientAuthenticationDetails`] which is specified at the client/ product
91-
/// cluster level. It provides a name (key) to resolve a particular [`AuthenticationClass`].
92-
/// Additionally, it provides authentication provider specific configuration (OIDC and LDAP for
93-
/// example).
96+
/// Common client authentication details which is specified at the client/ product cluster level.
97+
///
98+
/// It provides a name (key) to resolve a particular [`AuthenticationClass`]. Additionally, it
99+
/// provides authentication provider specific configuration (OIDC and LDAP for example).
94100
///
95101
/// If the product needs additional (product specific) authentication options, it is recommended
96102
/// to wrap this struct and use `#[serde(flatten)]` on the field.
@@ -123,19 +129,22 @@ pub mod versioned {
123129
pub struct ClientAuthenticationDetails<O = ()> {
124130
/// Name of the [AuthenticationClass](https://docs.stackable.tech/home/nightly/concepts/authentication) used to
125131
/// authenticate users.
126-
//
127-
// To get the concrete [`AuthenticationClass`], we must resolve it. This resolution can be achieved by using
128-
// [`ClientAuthenticationDetails::resolve_class`].
132+
///
133+
/// To get the concrete [`AuthenticationClass`], we must resolve it. This resolution can be
134+
/// achieved by using [`ClientAuthenticationDetails::resolve_class`].
129135
#[serde(rename = "authenticationClass")]
130136
authentication_class_ref: String,
131137

132-
/// This field contains OIDC-specific configuration. It is only required in case OIDC is used.
138+
/// This field contains OIDC-specific configuration. It is only required in case OIDC is
139+
/// used.
140+
///
141+
/// Use [`ClientAuthenticationDetails::oidc_or_error`] to get the value or report an error
142+
/// to the user.
133143
//
134-
// Use [`ClientAuthenticationDetails::oidc_or_error`] to get the value or report an error to the user.
135-
// TODO: Ideally we want this to be an enum once other `ClientAuthenticationOptions` are added, so
136-
// that user can not configure multiple options at the same time (yes we are aware that this makes a
137-
// changing the type of an AuthenticationClass harder).
138-
// This is a non-breaking change though :)
144+
// TODO: Ideally we want this to be an enum once other `ClientAuthenticationOptions` are
145+
// added, so that user can not configure multiple options at the same time (yes we are aware
146+
// that this makes a changing the type of an AuthenticationClass harder). This is a
147+
// non-breaking change though :)
139148
oidc: Option<oidc::v1alpha1::ClientAuthenticationOptions<O>>,
140149
}
141150
}

crates/stackable-operator/src/crd/authentication/ldap/mod.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
use schemars::JsonSchema;
22
use serde::{Deserialize, Serialize};
3-
use stackable_versioned::versioned;
43

5-
use crate::commons::{
6-
networking::HostName, secret_class::SecretClassVolume, tls_verification::TlsClientDetails,
4+
use crate::{
5+
commons::{
6+
networking::HostName, secret_class::SecretClassVolume, tls_verification::TlsClientDetails,
7+
},
8+
versioned::versioned,
79
};
810

911
mod v1alpha1_impl;
1012

1113
#[versioned(version(name = "v1alpha1"))]
1214
pub mod versioned {
15+
pub mod v1alpha1 {
16+
// Re-export the v1alpha1-specific error type from the private impl module.
17+
pub use v1alpha1_impl::Error;
18+
}
19+
1320
#[derive(
1421
Clone, Debug, Deserialize, Eq, Hash, JsonSchema, Ord, PartialEq, PartialOrd, Serialize,
1522
)]

crates/stackable-operator/src/crd/authentication/ldap/v1alpha1_impl.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use k8s_openapi::api::core::v1::{Volume, VolumeMount};
22
use snafu::{ResultExt as _, Snafu};
3-
use url::{ParseError, Url};
3+
use url::Url;
44

55
use crate::{
66
builder::{
@@ -22,7 +22,7 @@ pub enum Error {
2222
BindCredentials { source: SecretClassVolumeError },
2323

2424
#[snafu(display("failed to parse LDAP endpoint url"))]
25-
ParseLdapEndpointUrl { source: ParseError },
25+
ParseLdapEndpointUrl { source: url::ParseError },
2626

2727
#[snafu(display("failed to add LDAP TLS client details volumes and volume mounts"))]
2828
AddLdapTlsClientDetailsVolumes { source: TlsClientDetailsError },

crates/stackable-operator/src/crd/authentication/oidc/mod.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
use schemars::JsonSchema;
22
use serde::{Deserialize, Serialize};
3-
use stackable_versioned::versioned;
43
#[cfg(doc)]
54
use url::Url;
65

7-
use crate::commons::{networking::HostName, tls_verification::TlsClientDetails};
6+
use crate::{
7+
commons::{networking::HostName, tls_verification::TlsClientDetails},
8+
versioned::versioned,
9+
};
810

911
mod v1alpha1_impl;
1012

@@ -17,6 +19,11 @@ const DEFAULT_WELLKNOWN_OIDC_CONFIG_PATH: &str = "/.well-known/openid-configurat
1719

1820
#[versioned(version(name = "v1alpha1"))]
1921
pub mod versioned {
22+
pub mod v1alpha1 {
23+
// Re-export the v1alpha1-specific error type from the private impl module.
24+
pub use v1alpha1_impl::Error;
25+
}
26+
2027
/// This struct contains configuration values to configure an OpenID Connect
2128
/// (OIDC) authentication class. Required fields are the identity provider
2229
/// (IdP) `hostname` and the TLS configuration. The `port` is selected

crates/stackable-operator/src/crd/authentication/oidc/v1alpha1_impl.rs

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use crate::{
1818

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

21-
// TODO (@Techassi): Move this into mod.rs
2221
#[derive(Debug, PartialEq, Snafu)]
2322
pub enum Error {
2423
#[snafu(display("failed to parse OIDC endpoint url"))]

crates/stackable-operator/src/crd/s3/bucket/mod.rs

+5-18
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,17 @@
11
use kube::CustomResource;
22
use schemars::JsonSchema;
33
use serde::{Deserialize, Serialize};
4-
use snafu::Snafu;
5-
use stackable_versioned::versioned;
64

7-
use crate::crd::s3::{ConnectionError, connection::v1alpha1 as conn_v1alpha1};
5+
use crate::{crd::s3::connection::v1alpha1 as conn_v1alpha1, versioned::versioned};
86

97
mod v1alpha1_impl;
108

11-
// NOTE (@Techassi): Where should this error be placed? Technically errors can
12-
// change between version, because version-specific impl blocks might need
13-
// different variants or might use a completely different error type.
14-
#[derive(Debug, Snafu)]
15-
pub enum BucketError {
16-
#[snafu(display("failed to retrieve S3 connection '{s3_connection}'"))]
17-
RetrieveS3Connection {
18-
source: crate::client::Error,
19-
s3_connection: String,
20-
},
21-
22-
#[snafu(display("failed to resolve S3 connection"))]
23-
ResolveConnection { source: ConnectionError },
24-
}
25-
269
#[versioned(version(name = "v1alpha1"))]
2710
pub mod versioned {
11+
pub mod v1alpha1 {
12+
pub use v1alpha1_impl::BucketError;
13+
}
14+
2815
/// S3 bucket specification containing the bucket name and an inlined or referenced connection specification.
2916
/// Learn more on the [S3 concept documentation](DOCS_BASE_URL_PLACEHOLDER/concepts/s3).
3017
#[versioned(k8s(

crates/stackable-operator/src/crd/s3/bucket/v1alpha1_impl.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
11
//! v1alpha1 specific implementations for S3 buckets.
22
3-
use snafu::ResultExt as _;
3+
use snafu::{ResultExt as _, Snafu};
44

55
use crate::{
66
client::Client,
7-
crd::s3::bucket::{
8-
BucketError, ResolveConnectionSnafu, RetrieveS3ConnectionSnafu,
9-
v1alpha1::{InlineBucketOrReference, ResolvedBucket, S3Bucket},
7+
crd::s3::{
8+
bucket::v1alpha1::{InlineBucketOrReference, ResolvedBucket, S3Bucket},
9+
connection::v1alpha1::ConnectionError,
1010
},
1111
};
1212

13+
#[derive(Debug, Snafu)]
14+
pub enum BucketError {
15+
#[snafu(display("failed to retrieve S3 connection '{s3_connection}'"))]
16+
RetrieveS3Connection {
17+
source: crate::client::Error,
18+
s3_connection: String,
19+
},
20+
21+
#[snafu(display("failed to resolve S3 connection"))]
22+
ResolveConnection { source: ConnectionError },
23+
}
24+
1325
impl InlineBucketOrReference {
1426
pub async fn resolve(
1527
self,

0 commit comments

Comments
 (0)