Skip to content

Commit 897b751

Browse files
committed
adjust variable names and add docs, fix changelog
1 parent abd7043 commit 897b751

File tree

2 files changed

+29
-21
lines changed

2 files changed

+29
-21
lines changed

crates/stackable-operator/CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ All notable changes to this project will be documented in this file.
88

99
- Extend `ObjectMetaBuilder` with `finalizers` ([#1094]).
1010

11+
### Fixed
12+
13+
- BREAKING: Don't allow uppercase characters in Kubernetes object names ([#1095]).
14+
1115
[#1094]: https://github.com/stackabletech/operator-rs/pull/1094
16+
[#1095]: https://github.com/stackabletech/operator-rs/pull/1095
1217

1318
## [0.97.0] - 2025-09-09
1419

@@ -25,12 +30,10 @@ All notable changes to this project will be documented in this file.
2530
### Fixed
2631

2732
- Don't default the `termination_grace_period` of the `ProbeBuilder` to 0, as this is an invalid value ([#1090]).
28-
- Don't allow uppercase characters in Kubernetes object names ([#1095]).
2933

3034
[#1085]: https://github.com/stackabletech/operator-rs/pull/1085
3135
[#1087]: https://github.com/stackabletech/operator-rs/pull/1087
3236
[#1090]: https://github.com/stackabletech/operator-rs/pull/1090
33-
[#1095]: https://github.com/stackabletech/operator-rs/pull/1095
3437

3538
## [0.96.0] - 2025-08-25
3639

crates/stackable-operator/src/validation.rs

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use regex::Regex;
1616
use snafu::Snafu;
1717

1818
/// Minimal length required by RFC 1123 is 63. Up to 255 allowed, unsupported by k8s.
19-
const RFC_1123_LABEL_MAX_LENGTH: usize = 63;
19+
pub const RFC_1123_LABEL_MAX_LENGTH: usize = 63;
2020
// This is a modified RFC 1123 format according to the Kubernetes specification, see https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-label-names
2121
pub const LOWERCASE_RFC_1123_LABEL_FMT: &str = "[a-z0-9]([-a-z0-9]*[a-z0-9])?";
2222
const LOWERCASE_RFC_1123_LABEL_ERROR_MSG: &str = "a lowercase RFC 1123 label must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character";
@@ -25,28 +25,29 @@ const LOWERCASE_RFC_1123_LABEL_ERROR_MSG: &str = "a lowercase RFC 1123 label mus
2525
const RFC_1123_LABEL_FMT: &str = "[a-zA-Z0-9]([-a-zA-Z0-9]*[a-zA-Z0-9])?";
2626

2727
/// This is a subdomain's max length in DNS (RFC 1123)
28-
const RFC_1123_SUBDOMAIN_MAX_LENGTH: usize = 253;
29-
const RFC_1123_SUBDOMAIN_FMT: &str = concatcp!(
28+
pub const RFC_1123_SUBDOMAIN_MAX_LENGTH: usize = 253;
29+
const LOWERCASE_RFC_1123_SUBDOMAIN_FMT: &str = concatcp!(
3030
LOWERCASE_RFC_1123_LABEL_FMT,
3131
"(\\.",
3232
LOWERCASE_RFC_1123_LABEL_FMT,
3333
")*"
3434
);
35-
const RFC_1123_SUBDOMAIN_ERROR_MSG: &str = "a RFC 1123 subdomain must consist of alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character";
35+
const LOWERCASE_RFC_1123_SUBDOMAIN_ERROR_MSG: &str = "a lowercase RFC 1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character";
3636

37-
const DOMAIN_MAX_LENGTH: usize = RFC_1123_SUBDOMAIN_MAX_LENGTH;
37+
pub const DOMAIN_MAX_LENGTH: usize = RFC_1123_SUBDOMAIN_MAX_LENGTH;
3838

3939
/// Same as [`RFC_1123_LABEL_FMT`], but allows a trailing dot
4040
const DOMAIN_FMT: &str = concatcp!(RFC_1123_LABEL_FMT, "(\\.", RFC_1123_LABEL_FMT, ")*\\.?");
4141
const DOMAIN_ERROR_MSG: &str = "a domain must consist of alphanumeric characters, '-' or '.', and must start with an alphanumeric character and end with an alphanumeric character or '.'";
4242

4343
// FIXME: According to https://www.rfc-editor.org/rfc/rfc1035#section-2.3.1 domain names must start with a letter
4444
// (and not a number).
45-
const RFC_1035_LABEL_FMT: &str = "[a-z]([-a-z0-9]*[a-z0-9])?";
46-
const RFC_1035_LABEL_ERROR_MSG: &str = "a DNS-1035 label must consist of lower case alphanumeric characters or '-', start with an alphabetic character, and end with an alphanumeric character";
45+
// This is a modified RFC 1035 format according to the Kubernetes specification, see https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#rfc-1035-label-names
46+
const LOWERCASE_RFC_1035_LABEL_FMT: &str = "[a-z]([-a-z0-9]*[a-z0-9])?";
47+
const LOWERCASE_RFC_1035_LABEL_ERROR_MSG: &str = "a DNS-1035 label must consist of lower case alphanumeric characters or '-', start with an alphabetic character, and end with an alphanumeric character";
4748

4849
// This is a label's max length in DNS (RFC 1035)
49-
const RFC_1035_LABEL_MAX_LENGTH: usize = 63;
50+
pub const RFC_1035_LABEL_MAX_LENGTH: usize = 63;
5051

5152
// Technically Kerberos allows more realm names
5253
// (https://web.mit.edu/kerberos/krb5-1.21/doc/admin/realm_config.html#realm-name),
@@ -69,13 +70,14 @@ static LOWERCASE_RFC_1123_LABEL_REGEX: LazyLock<Regex> = LazyLock::new(|| {
6970
.expect("failed to compile RFC 1123 label regex")
7071
});
7172

72-
static RFC_1123_SUBDOMAIN_REGEX: LazyLock<Regex> = LazyLock::new(|| {
73-
Regex::new(&format!("^{RFC_1123_SUBDOMAIN_FMT}$"))
73+
static LOWERCASE_RFC_1123_SUBDOMAIN_REGEX: LazyLock<Regex> = LazyLock::new(|| {
74+
Regex::new(&format!("^{LOWERCASE_RFC_1123_SUBDOMAIN_FMT}$"))
7475
.expect("failed to compile RFC 1123 subdomain regex")
7576
});
7677

77-
static RFC_1035_LABEL_REGEX: LazyLock<Regex> = LazyLock::new(|| {
78-
Regex::new(&format!("^{RFC_1035_LABEL_FMT}$")).expect("failed to compile RFC 1035 label regex")
78+
static LOWERCASE_RFC_1035_LABEL_REGEX: LazyLock<Regex> = LazyLock::new(|| {
79+
Regex::new(&format!("^{LOWERCASE_RFC_1035_LABEL_FMT}$"))
80+
.expect("failed to compile RFC 1035 label regex")
7981
});
8082

8183
pub(crate) static KERBEROS_REALM_NAME_REGEX: LazyLock<Regex> = LazyLock::new(|| {
@@ -214,7 +216,8 @@ pub fn is_domain(value: &str) -> Result {
214216
])
215217
}
216218

217-
/// Tests for a string that conforms to the definition of a label in DNS (RFC 1123).
219+
/// Tests for a string that conforms to the kubernetes-specific definition of a label in DNS (RFC 1123)
220+
/// used in Namespace names, see: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-label-names
218221
/// Maximum label length supported by k8s is 63 characters (minimum required).
219222
pub fn is_rfc_1123_label(value: &str) -> Result {
220223
validate_all([
@@ -228,27 +231,29 @@ pub fn is_rfc_1123_label(value: &str) -> Result {
228231
])
229232
}
230233

231-
/// Tests for a string that conforms to the definition of a subdomain in DNS (RFC 1123).
234+
/// Tests for a string that conforms to the kubernetes-specific definition of a subdomain in DNS (RFC 1123)
235+
/// used in ConfigMap names, see https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-subdomain-names
232236
pub fn is_rfc_1123_subdomain(value: &str) -> Result {
233237
validate_all([
234238
validate_str_length(value, RFC_1123_SUBDOMAIN_MAX_LENGTH),
235239
validate_str_regex(
236240
value,
237-
&RFC_1123_SUBDOMAIN_REGEX,
238-
RFC_1123_SUBDOMAIN_ERROR_MSG,
241+
&LOWERCASE_RFC_1123_SUBDOMAIN_REGEX,
242+
LOWERCASE_RFC_1123_SUBDOMAIN_ERROR_MSG,
239243
&["example.com"],
240244
),
241245
])
242246
}
243247

244-
/// Tests for a string that conforms to the definition of a label in DNS (RFC 1035).
248+
/// Tests for a string that conforms to the kubernetes-specific definition of a label in DNS (RFC 1035)
249+
/// used in Service names, see: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#rfc-1035-label-names
245250
pub fn is_rfc_1035_label(value: &str) -> Result {
246251
validate_all([
247252
validate_str_length(value, RFC_1035_LABEL_MAX_LENGTH),
248253
validate_str_regex(
249254
value,
250-
&RFC_1035_LABEL_REGEX,
251-
RFC_1035_LABEL_ERROR_MSG,
255+
&LOWERCASE_RFC_1035_LABEL_REGEX,
256+
LOWERCASE_RFC_1035_LABEL_ERROR_MSG,
252257
&["my-name", "abc-123"],
253258
),
254259
])

0 commit comments

Comments
 (0)