Skip to content
Open
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/stackable-operator/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ impl Client {
pub trait GetApi: Resource + Sized {
/// The namespace type for `Self`'s scope.
///
/// This will be [`str`] for namespaced resource, and [`()`] for cluster-scoped resources.
/// This will be [`str`] for namespaced resource, and `()` for cluster-scoped resources.
type Namespace: ?Sized;
/// Get a [`kube::Api`] for `Self`'s native scope..
fn get_api(client: kube::Client, ns: &Self::Namespace) -> kube::Api<Self>
Expand Down
56 changes: 56 additions & 0 deletions crates/stackable-operator/src/crd/authentication/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,59 @@ pub mod versioned {
oidc: Option<oidc::v1alpha1::ClientAuthenticationOptions<O>>,
}
}

#[cfg(test)]
impl stackable_versioned::test_utils::RoundtripTestData for v1alpha1::AuthenticationClassSpec {
fn roundtrip_test_data() -> Vec<Self> {
crate::utils::yaml_from_str_singleton_map(indoc::indoc! {"
- provider:
static:
userCredentialsSecret:
name: simple-users-credentials
- provider:
ldap:
hostname: my.ldap.server
port: 389
searchBase: ou=users,dc=example,dc=org
searchFilter: foo
bindCredentials:
secretClass: openldap-bind-credentials
ldapFieldNames:
email: email
givenName: givenName
group: group
surname: surname
uid: uid
tls:
verification:
server:
caCert:
secretClass: s3-cert
- provider:
oidc:
hostname: my.keycloak.server
port: 8080
rootPath: /realms/master
scopes:
- email
- openid
- profile
principalClaim: preferred_username
providerHint: Keycloak
tls:
verification:
server:
caCert:
secretClass: s3-cert
- provider:
tls: {}
- provider:
tls:
clientCertSecretClass: client-auth-tls
- provider:
kerberos:
kerberosSecretClass: kerberos-auth
"})
.expect("Failed to parse AuthenticationClassSpec YAML")
}
}
19 changes: 19 additions & 0 deletions crates/stackable-operator/src/crd/listener/class/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,22 @@ pub mod versioned {
pub service_overrides: Service,
}
}

#[cfg(test)]
impl stackable_versioned::test_utils::RoundtripTestData for v1alpha1::ListenerClassSpec {
fn roundtrip_test_data() -> Vec<Self> {
crate::utils::yaml_from_str_singleton_map(indoc::indoc! {"
- serviceType: ClusterIP
- serviceType: NodePort
- serviceType: LoadBalancer
- serviceType: ClusterIP
loadBalancerAllocateNodePorts: false
loadBalancerClass: foo
serviceAnnotations:
foo: bar
serviceExternalTrafficPolicy: Local
preferredAddressType: HostnameConservative
"})
.expect("Failed to parse ListenerClassSpec YAML")
}
}
51 changes: 51 additions & 0 deletions crates/stackable-operator/src/crd/listener/listeners/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,54 @@ pub mod versioned {
Cluster,
}
}

#[cfg(test)]
impl stackable_versioned::test_utils::RoundtripTestData for v1alpha1::ListenerSpec {
fn roundtrip_test_data() -> Vec<Self> {
crate::utils::yaml_from_str_singleton_map(indoc::indoc! {"
- {}
- className: cluster-internal
extraPodLabelSelectorLabels: {}
ports: []
publishNotReadyAddresses: true
- className: external-unstable
extraPodLabelSelectorLabels:
foo: bar
ports:
- name: http
port: 8080
protocol: TCP
publishNotReadyAddresses: true
"})
.expect("Failed to parse ListenerSpec YAML")
}
}

#[cfg(test)]
impl stackable_versioned::test_utils::RoundtripTestData for v1alpha1::PodListenersSpec {
fn roundtrip_test_data() -> Vec<Self> {
crate::utils::yaml_from_str_singleton_map(indoc::indoc! {"
- listeners: {}
- listeners:
foo:
scope: Node
- listeners:
foo:
scope: Cluster
ingressAddresses:
- address: 1.2.3.4
addressType: IP
ports: {}
- listeners:
foo:
scope: Cluster
ingressAddresses:
- address: foo.bar
addressType: Hostname
ports:
http: 8080
https: 8443
"})
.expect("Failed to parse PodListenersSpec YAML")
}
}
31 changes: 31 additions & 0 deletions crates/stackable-operator/src/crd/s3/bucket/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,34 @@ pub mod versioned {
pub connection: conn_v1alpha1::ConnectionSpec,
}
}

#[cfg(test)]
impl stackable_versioned::test_utils::RoundtripTestData for v1alpha1::BucketSpec {
fn roundtrip_test_data() -> Vec<Self> {
crate::utils::yaml_from_str_singleton_map(indoc::indoc! {"
- bucketName: my-example-bucket
connection:
reference: my-connection-resource
- bucketName: foo
connection:
inline:
host: s3.example.com
- bucketName: foo
connection:
inline:
host: s3.example.com
port: 1234
accessStyle: VirtualHosted
credentials:
secretClass: s3-credentials
region:
name: eu-west-1
tls:
verification:
server:
caCert:
secretClass: s3-cert
"})
.expect("Failed to parse BucketSpec YAML")
}
}
30 changes: 30 additions & 0 deletions crates/stackable-operator/src/crd/s3/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,36 @@ pub mod versioned {
}
}

#[cfg(test)]
impl stackable_versioned::test_utils::RoundtripTestData for v1alpha1::ConnectionSpec {
fn roundtrip_test_data() -> Vec<Self> {
crate::utils::yaml_from_str_singleton_map(indoc::indoc! {"
- host: s3.example.com
- host: s3.example.com
port: 1234
accessStyle: VirtualHosted
credentials:
secretClass: s3-credentials
region:
name: eu-west-1
tls: null
- host: s3.example.com
region:
name: us-east-1
tls:
verification:
none: {}
- host: s3.example.com
tls:
verification:
server:
caCert:
secretClass: s3-cert
"})
.expect("Failed to parse ConnectionSpec YAML")
}
}

#[cfg(test)]
mod tests {
use std::collections::BTreeMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ mod r#enum;
mod r#struct;

/// Contains common container data shared between structs and enums.
#[derive(Debug)]
pub struct CommonContainerData {
/// Original attributes placed on the container, like `#[derive()]` or `#[cfg()]`.
pub original_attributes: Vec<Attribute>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{borrow::Cow, cmp::Ordering};
use indoc::formatdoc;
use itertools::Itertools as _;
use proc_macro2::TokenStream;
use quote::quote;
use quote::{format_ident, quote};
use syn::parse_quote;

use crate::{
Expand Down Expand Up @@ -530,6 +530,71 @@ impl Struct {
})
}

pub(super) fn generate_conversion_roundtrip_test(
&self,
versions: &[VersionDefinition],
mod_gen_ctx: ModuleGenerationContext<'_>,
spec_gen_ctx: &SpecGenerationContext<'_>,
) -> TokenStream {
let versioned_path = &*mod_gen_ctx.crates.versioned;
let struct_ident = &self.common.idents.original;
let kind_ident = &spec_gen_ctx.kubernetes_idents.kind;

let api_versions = spec_gen_ctx
.version_strings
.iter()
.map(|version| {
format!(
"{group}/{version}",
group = &spec_gen_ctx.kubernetes_arguments.group
)
})
.collect::<Vec<_>>();

let earliest_version_module_ident = &versions
.first()
.expect("there must be at least one version present")
.idents
.module;
let latest_version_module_ident = &versions
.last()
.expect("there must be at least one version present")
.idents
.module;
let earliest_api_version = api_versions
.first()
.expect("there must be at least one version present");
let latest_api_version = api_versions
.last()
.expect("there must be at least one version present");
let test_function_down_up = format_ident!("{struct_ident}_roundtrip_down_up");
let test_function_up_down = format_ident!("{struct_ident}_roundtrip_up_down");

quote! {
#[cfg(test)]
#[test]
fn #test_function_down_up() {
#versioned_path::test_utils::test_roundtrip::<#latest_version_module_ident::#struct_ident>(
stringify!(#kind_ident),
#latest_api_version,
#earliest_api_version,
#kind_ident::try_convert,
);
}

#[cfg(test)]
#[test]
fn #test_function_up_down() {
#versioned_path::test_utils::test_roundtrip::<#earliest_version_module_ident::#struct_ident>(
stringify!(#kind_ident),
#earliest_api_version,
#latest_api_version,
#kind_ident::try_convert,
);
}
}
}

pub(super) fn generate_from_json_object_fn(
&self,
mod_gen_ctx: ModuleGenerationContext<'_>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ impl Container {
}

/// A versioned struct.
#[derive(Debug)]
pub struct Struct {
/// List of fields defined in the original struct. How, and if, an item
/// should generate code, is decided by the currently generated version.
Expand All @@ -101,6 +102,7 @@ pub struct Struct {
pub generics: Generics,
}

#[derive(Debug)]
pub struct KubernetesData {
pub kubernetes_arguments: StructCrdArguments,
pub kubernetes_idents: KubernetesIdents,
Expand Down Expand Up @@ -164,11 +166,14 @@ impl Struct {
self.generate_entry_impl_block(versions, mod_gen_ctx, &spec_gen_ctx);
let version_enum = self.generate_version_enum(mod_gen_ctx, &spec_gen_ctx);
let status_struct = self.generate_status_struct(mod_gen_ctx, &spec_gen_ctx);
let conversion_roundtrip_test =
self.generate_conversion_roundtrip_test(versions, mod_gen_ctx, &spec_gen_ctx);

container_tokens
.extend_outer(entry_enum)
.extend_outer(entry_enum_impl)
.extend_outer(version_enum)
.extend_outer(conversion_roundtrip_test)
.extend_outer(status_struct);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use crate::{
utils::{ItemIdentExt, ItemIdents},
};

#[derive(Debug)]
pub struct VersionedField {
pub original_attributes: Vec<Attribute>,
pub changes: Option<BTreeMap<Version, ItemStatus>>,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading