Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
7 changes: 7 additions & 0 deletions crates/stackable-operator/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

### Added

- [v2]: Make `ResourceNames::ensure_max_length` public ([#1260]).
- [v2]: Add `MAX_ANNOTATION_NAME_LENGTH` constant with a value of `63` ([#1260]).

[#1260]: https://github.com/stackabletech/operator-rs/pull/1260

## [0.115.0] - 2026-08-04

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ use strum::{EnumDiscriminants, IntoStaticStr};
/// Duplicates the private constant [`crate::kvp::LABEL_VALUE_MAX_LEN`]
pub const MAX_LABEL_VALUE_LENGTH: usize = 63;

/// Maximum length of annotation names
pub const MAX_ANNOTATION_NAME_LENGTH: usize = 63;

@siegfriedweber siegfriedweber Aug 5, 2026

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 constant belongs in kvp::key and should be named MAX_KEY_NAME_LENGTH.

Rather than exposing the value publicly, it might be cleaner to offer a sanitize function that takes a key prefix and name and returns a valid kvp::key::Key.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I removed the constant and added the requested function. However, I didn't call it sanitize, as to me that gives off security vibes, but happy to discuss the name :)


#[derive(Debug, EnumDiscriminants, Snafu)]
#[snafu(visibility(pub))]
#[strum_discriminants(derive(IntoStaticStr))]
Expand Down
6 changes: 5 additions & 1 deletion crates/stackable-operator/src/v2/role_group_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ impl ResourceNames {
/// `max_length < 1 /* character */ + 1 /* dash */ + hash_length`.
///
/// Kubernetes object names cannot contain non-ASCII characters.
fn ensure_max_length(resource_name: String, max_length: usize, hash_length: usize) -> String {
pub fn ensure_max_length(
resource_name: String,
max_length: usize,
hash_length: usize,
) -> String {

@siegfriedweber siegfriedweber Aug 5, 2026

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 function was written for resource names, where the assertions always hold. If it's now used to shorten arbitrary strings (which could also come from the user) then you can expect the operator to crash.

That said, I do see the usefulness. I'd suggest making it safe for arbitrary strings (which isn't trivial) and moving it to a string utility module.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Moved it into crates/stackable-operator/src/utils/length_enforcement.rs.

which isn't trivial

However, I'm pretty sure I missed something, will test non-asci strings now

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I pushed a commit that adds UTF-8 support: f0a76b3
It work's, but also feels a bit awkward to use

assert!(resource_name.is_ascii());
assert!(max_length >= 1 /* character */ + 1 /* dash */ + hash_length);

Expand Down