Skip to content

chore: Consolidate error enums and use expect where possible - #1084

Open
adwk67 wants to merge 3 commits into
mainfrom
fix/consolidate-result--handling
Open

chore: Consolidate error enums and use expect where possible#1084
adwk67 wants to merge 3 commits into
mainfrom
fix/consolidate-result--handling

Conversation

@adwk67

@adwk67 adwk67 commented Sep 8, 2026

Copy link
Copy Markdown
Member

Description

Part of stackabletech/issues#883

--- PASS: kuttl (200.16s)
    --- PASS: kuttl/harness (0.00s)
        --- PASS: kuttl/harness/cluster-operation_zookeeper-latest-3.9.5_openshift-false (51.82s)
        --- PASS: kuttl/harness/smoke_zookeeper-3.9.5_use-server-tls-true_use-client-auth-tls-true_openshift-false (94.22s)
        --- PASS: kuttl/harness/delete-rolegroup_zookeeper-3.9.5_openshift-false (119.03s)
        --- PASS: kuttl/harness/znode_zookeeper-latest-3.9.5_openshift-false (26.49s)
        --- PASS: kuttl/harness/logging_zookeeper-3.9.5_openshift-false (105.93s)
PASS

Definition of Done Checklist

  • Not all of these items are applicable to all PRs, the author should update this template to only leave the boxes in that are relevant
  • Please make sure all these things are done and tick the boxes

Author

  • Changes are OpenShift compatible
  • CRD changes approved
  • CRD documentation for all fields, following the style guide.
  • Helm chart can be installed and deployed operator works
  • Integration tests passed (for non trivial changes)
  • Changes need to be "offline" compatible
  • Links to generated (nightly) docs added
  • Release note snippet added

Reviewer

  • Code contains useful comments
  • Code contains useful logging statements
  • (Integration-)Test cases added
  • Documentation added or updated. Follows the style guide.
  • Changelog updated
  • Cargo.toml only contains references to git tags (not specific commits or branches)

Acceptance

  • Feature Tracker has been updated
  • Proper release label has been added
  • Links to generated (nightly) docs added
  • Release note snippet added
  • Add type/deprecation label & add to the deprecation schedule
  • Add type/experimental label & add to the experimental features tracker

@adwk67
adwk67 marked this pull request as ready for review September 8, 2026 09:58
Comment thread rust/operator-binary/src/crd/security.rs Outdated
Comment thread rust/operator-binary/src/crd/security.rs Outdated
/// The resulting volume will contain TLS certificates with the FQDN reported in the applicable [ListenerStatus].
///
/// [ListenerStatus]: ::stackable_operator::crd::listener::v1alpha1::ListenerStatus
fn create_server_tls_volume(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one can panic now and should have a comment saying so?

/// Creates ephemeral volumes to mount the `SecretClass` with the pod scope into the Pods.
///
/// The resulting volume will contain TLS certificates with the FQDN of the Pod in relation to the StatefulSet's headless service.
fn create_quorum_tls_volume(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one can panic now and should have a comment saying so?

"The string `<cluster_name>-<role_name>` must not exceed the limit of Listener names."
);
// Both halves are RFC 1123 labels joined by a dash, which is a valid RFC 1123 subdomain.
let _ = ClusterName::IS_RFC_1123_SUBDOMAIN_NAME;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also used as a service name and as the first label of the FQDN, so it shouldbe a label with max 63 chars and no dots? This would affect the check above.

Suggested change
let _ = ClusterName::IS_RFC_1123_SUBDOMAIN_NAME;
let _ = ClusterName::IS_RFC_1035_LABEL_NAME;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just document that the returned ListenerName is an RFC 1035 label name and create a unit test:

diff --git a/rust/operator-binary/src/crd/mod.rs b/rust/operator-binary/src/crd/mod.rs
index d2df7a1..fc81e09 100644
--- a/rust/operator-binary/src/crd/mod.rs
+++ b/rust/operator-binary/src/crd/mod.rs
@@ -50,6 +50,8 @@ pub mod tls;
 ///
 /// Lives in the `crd` module (rather than the controller build tree) because it is shared by both
 /// controllers and by [`role_listener_fqdn`].
+///
+/// The returned ListenerName is a lowercase RFC 1035 label name (checked by a unit test).
 pub fn role_listener_name(cluster_name: &ClusterName, zk_role: &ZookeeperRole) -> ListenerName {
     const _: () = assert!(
         ClusterName::MAX_LENGTH + 1 /* dash */ + RoleName::MAX_LENGTH <= ListenerName::MAX_LENGTH,
@@ -340,7 +342,7 @@ pub mod versioned {
     }
 }

-#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
+#[derive(Clone, Debug, Eq, EnumIter, Hash, Ord, PartialEq, PartialOrd)]
 pub enum ZookeeperRole {
     Server,
 }
@@ -478,6 +480,7 @@ mod tests {
     use stackable_operator::{
         commons::networking::DomainName, versioned::test_utils::RoundtripTestData,
     };
+    use strum::IntoEnumIterator;

     use super::*;

@@ -774,4 +777,22 @@ mod tests {
             .expect("Failed to parse ZookeeperZnodeSpec YAML")
         }
     }
+
+    #[test]
+    fn role_listener_name_is_rfc_1035_label_name() {
+        // Every ClusterName is a valid RFC 1035 label name, so we use just some string with maximum
+        // length.
+        let _ = ClusterName::IS_RFC_1035_LABEL_NAME;
+        let cluster_name = ClusterName::from_str_unsafe(&"a".repeat(ClusterName::MAX_LENGTH));
+
+        for role in ZookeeperRole::iter() {
+            let role_listener_name = role_listener_name(&cluster_name, &role);
+            assert!(
+                stackable_operator::validation::is_lowercase_rfc_1035_label(
+                    role_listener_name.as_ref()
+                )
+                .is_ok()
+            );
+        }
+    }
 }

@maltesander maltesander left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just nits, Changelog is missing.

Co-authored-by: maltesander <contact@maltesander.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants