You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by ca...@apache.org on 2026/02/03 18:52:43 UTC
(druid) branch master updated: bugfix: Fix bug that could lead to illegal k8s label ending in non-alphanumeric (#18981)
This is an automated email from the ASF dual-hosted git repository.
capistrant pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/druid.git
The following commit(s) were added to refs/heads/master by this push:
new 45e4bb219ea bugfix: Fix bug that could lead to illegal k8s label ending in non-alphanumeric (#18981)
45e4bb219ea is described below
commit 45e4bb219ea6447557f82384b3b1a092643b8887
Author: Lucas Capistrant <ca...@users.noreply.github.com>
AuthorDate: Tue Feb 3 12:52:37 2026 -0600
bugfix: Fix bug that could lead to illegal k8s label ending in non-alphanumeric (#18981)
---
.../overlord/common/KubernetesOverlordUtils.java | 4 ++-
.../common/KubernetesOverlordUtilsTest.java | 32 ++++++++++++++++++++++
2 files changed, 35 insertions(+), 1 deletion(-)
diff --git a/extensions-core/kubernetes-overlord-extensions/src/main/java/org/apache/druid/k8s/overlord/common/KubernetesOverlordUtils.java b/extensions-core/kubernetes-overlord-extensions/src/main/java/org/apache/druid/k8s/overlord/common/KubernetesOverlordUtils.java
index dc7b8f99136..bd5791c3437 100644
--- a/extensions-core/kubernetes-overlord-extensions/src/main/java/org/apache/druid/k8s/overlord/common/KubernetesOverlordUtils.java
+++ b/extensions-core/kubernetes-overlord-extensions/src/main/java/org/apache/druid/k8s/overlord/common/KubernetesOverlordUtils.java
@@ -36,7 +36,9 @@ public class KubernetesOverlordUtils
public static String convertStringToK8sLabel(String rawString)
{
String trimmedString = rawString == null ? "" : RegExUtils.replaceAll(rawString, K8S_LABEL_PATTERN, "");
- return StringUtils.left(StringUtils.strip(trimmedString, "_.-"), 63);
+ String truncated = StringUtils.left(trimmedString, 63);
+ // K8s labels must start and end with an alphanumeric character
+ return StringUtils.strip(truncated, "_.-");
}
diff --git a/extensions-core/kubernetes-overlord-extensions/src/test/java/org/apache/druid/k8s/overlord/common/KubernetesOverlordUtilsTest.java b/extensions-core/kubernetes-overlord-extensions/src/test/java/org/apache/druid/k8s/overlord/common/KubernetesOverlordUtilsTest.java
index 5254e0fbe69..39331c87707 100644
--- a/extensions-core/kubernetes-overlord-extensions/src/test/java/org/apache/druid/k8s/overlord/common/KubernetesOverlordUtilsTest.java
+++ b/extensions-core/kubernetes-overlord-extensions/src/test/java/org/apache/druid/k8s/overlord/common/KubernetesOverlordUtilsTest.java
@@ -75,4 +75,36 @@ public class KubernetesOverlordUtilsTest
String jobName2 = KubernetesOverlordUtils.convertTaskIdToJobName("coordinator-issued_compact_1234_telemetry_wikipedia_geteditfailuresinnorthamerica_agg_summ_117_pcgkebcl_2023-07-19T16:53:11.416Z");
Assert.assertNotEquals(jobName1, jobName2);
}
+
+ @Test
+ public void test_longLabelEndsWithAlphanumeric()
+ {
+ // Test case for bug where truncation at 63 chars could result in a label ending with a special character
+ // This string is 80 characters and would be truncated at position 63, landing on a hyphen
+ String longLabelHyphen = "very-long-datasource-name-with-many-illegal_label_endings-that-exceeds-the--------limit-12345678";
+ String longLabelPeriod = "very-long-datasource-name-with-many-illegal_label_endings-that-exceeds-the........limit-12345678";
+ String longLabelUnderscore = "very-long-datasource-name-with-many-illegal_label_endings-that-exceeds-the________limit-12345678";
+
+ for (String longLabel : new String[]{longLabelHyphen, longLabelPeriod, longLabelUnderscore}) {
+ String result = KubernetesOverlordUtils.convertStringToK8sLabel(longLabel);
+
+ // Result should not exceed 63 characters
+ Assert.assertTrue("Label should not exceed 63 characters", result.length() <= 63);
+
+ // Result should not be empty
+ Assert.assertFalse("Label should not be empty", result.isEmpty());
+
+ // Result should not end with a hyphen, underscore, or dot
+ Assert.assertFalse("Label should not end with hyphen", result.endsWith("-"));
+ Assert.assertFalse("Label should not end with underscore", result.endsWith("_"));
+ Assert.assertFalse("Label should not end with dot", result.endsWith("."));
+
+ // Result should end with an alphanumeric character
+ char lastChar = result.charAt(result.length() - 1);
+ Assert.assertTrue(
+ "Label should end with alphanumeric character, but ends with: " + lastChar,
+ Character.isLetterOrDigit(lastChar)
+ );
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org