Skip to content

Commit

Permalink
Removed usage of statefulset.kubernetes.io/pod-name label on servic…
Browse files Browse the repository at this point in the history
…es and pods (strimzi#11087)

Signed-off-by: Paolo Patierno <ppatierno@live.com>
  • Loading branch information
ppatierno authored Jan 29, 2025
1 parent 8f81517 commit b6120c9
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 39 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
* The storage overrides for configuring per-broker storage class are not supported anymore.
If you are using the storage overrides, you should instead use multiple KafkaNodePool resources with a different storage class each.
For more details about migrating from storage overrides, please follow the [documentation](https://strimzi.io/docs/operators/0.45.0/full/deploying.html#con-config-storage-zookeeper-str).
* Removed the `statefulset.kubernetes.io/pod-name` label from pods and external listeners Kubernetes Services.
* If you have any custom setup leveraging such label, please use the `strimzi.io/pod-name` one instead.

## 0.45.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ public List<Service> generatePerPodServices() {
pool.ownerReference,
pool.templatePerBrokerService,
ports,
pool.labels.strimziSelectorLabels().withStatefulSetPod(node.podName()),
pool.labels.strimziSelectorLabels().withStrimziPodName(node.podName()),
ListenersUtils.serviceType(listener),
ListenersUtils.brokerLabels(listener, node.nodeId()),
ListenersUtils.brokerAnnotations(listener, node.nodeId()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public static Pod createStatefulPod(
Pod pod = new PodBuilder()
.withNewMetadata()
.withName(name)
.withLabels(labels.withStrimziPodName(name).withStatefulSetPod(name).withStrimziPodSetController(strimziPodSetName).withAdditionalLabels(Util.mergeLabelsOrAnnotations(defaultPodLabels, TemplateUtils.labels(template))).toMap())
.withLabels(labels.withStrimziPodName(name).withStrimziPodSetController(strimziPodSetName).withAdditionalLabels(Util.mergeLabelsOrAnnotations(defaultPodLabels, TemplateUtils.labels(template))).toMap())
.withNamespace(namespace)
.withAnnotations(Util.mergeLabelsOrAnnotations(podAnnotations, TemplateUtils.annotations(template)))
.endMetadata()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -787,11 +787,11 @@ public void testExternalRoutes() {
for (Service service : services) {
if (service.getMetadata().getName().contains("foo-brokers-")) {
assertThat(service.getMetadata().getName(), startsWith("foo-brokers-"));
assertThat(service.getSpec().getSelector().get(Labels.KUBERNETES_STATEFULSET_POD_LABEL), oneOf("foo-brokers-5", "foo-brokers-6", "foo-brokers-7"));
assertThat(service.getSpec().getSelector().get(Labels.STRIMZI_POD_NAME_LABEL), oneOf("foo-brokers-5", "foo-brokers-6", "foo-brokers-7"));
TestUtils.checkOwnerReference(service, POOL_BROKERS);
} else {
assertThat(service.getMetadata().getName(), startsWith("foo-mixed-"));
assertThat(service.getSpec().getSelector().get(Labels.KUBERNETES_STATEFULSET_POD_LABEL), oneOf("foo-mixed-3", "foo-mixed-4"));
assertThat(service.getSpec().getSelector().get(Labels.STRIMZI_POD_NAME_LABEL), oneOf("foo-mixed-3", "foo-mixed-4"));
TestUtils.checkOwnerReference(service, POOL_MIXED);
}

Expand Down Expand Up @@ -1022,11 +1022,11 @@ public void testExternalLoadBalancers() {
for (Service service : services) {
if (service.getMetadata().getName().contains("foo-brokers-")) {
assertThat(service.getMetadata().getName(), startsWith("foo-brokers-"));
assertThat(service.getSpec().getSelector().get(Labels.KUBERNETES_STATEFULSET_POD_LABEL), oneOf("foo-brokers-5", "foo-brokers-6", "foo-brokers-7"));
assertThat(service.getSpec().getSelector().get(Labels.STRIMZI_POD_NAME_LABEL), oneOf("foo-brokers-5", "foo-brokers-6", "foo-brokers-7"));
TestUtils.checkOwnerReference(service, POOL_BROKERS);
} else {
assertThat(service.getMetadata().getName(), startsWith("foo-mixed-"));
assertThat(service.getSpec().getSelector().get(Labels.KUBERNETES_STATEFULSET_POD_LABEL), oneOf("foo-mixed-3", "foo-mixed-4"));
assertThat(service.getSpec().getSelector().get(Labels.STRIMZI_POD_NAME_LABEL), oneOf("foo-mixed-3", "foo-mixed-4"));
TestUtils.checkOwnerReference(service, POOL_MIXED);
}

Expand Down Expand Up @@ -1438,11 +1438,11 @@ public void testExternalNodePorts() {
for (Service service : services) {
if (service.getMetadata().getName().contains("foo-brokers-")) {
assertThat(service.getMetadata().getName(), startsWith("foo-brokers-"));
assertThat(service.getSpec().getSelector().get(Labels.KUBERNETES_STATEFULSET_POD_LABEL), oneOf("foo-brokers-5", "foo-brokers-6", "foo-brokers-7"));
assertThat(service.getSpec().getSelector().get(Labels.STRIMZI_POD_NAME_LABEL), oneOf("foo-brokers-5", "foo-brokers-6", "foo-brokers-7"));
TestUtils.checkOwnerReference(service, POOL_BROKERS);
} else {
assertThat(service.getMetadata().getName(), startsWith("foo-mixed-"));
assertThat(service.getSpec().getSelector().get(Labels.KUBERNETES_STATEFULSET_POD_LABEL), oneOf("foo-mixed-3", "foo-mixed-4"));
assertThat(service.getSpec().getSelector().get(Labels.STRIMZI_POD_NAME_LABEL), oneOf("foo-mixed-3", "foo-mixed-4"));
TestUtils.checkOwnerReference(service, POOL_MIXED);
}

Expand Down Expand Up @@ -1907,11 +1907,11 @@ public void testExternalIngress() {
for (Service service : services) {
if (service.getMetadata().getName().contains("foo-brokers-")) {
assertThat(service.getMetadata().getName(), startsWith("foo-brokers-"));
assertThat(service.getSpec().getSelector().get(Labels.KUBERNETES_STATEFULSET_POD_LABEL), oneOf("foo-brokers-5", "foo-brokers-6", "foo-brokers-7"));
assertThat(service.getSpec().getSelector().get(Labels.STRIMZI_POD_NAME_LABEL), oneOf("foo-brokers-5", "foo-brokers-6", "foo-brokers-7"));
TestUtils.checkOwnerReference(service, POOL_BROKERS);
} else {
assertThat(service.getMetadata().getName(), startsWith("foo-mixed-"));
assertThat(service.getSpec().getSelector().get(Labels.KUBERNETES_STATEFULSET_POD_LABEL), oneOf("foo-mixed-3", "foo-mixed-4"));
assertThat(service.getSpec().getSelector().get(Labels.STRIMZI_POD_NAME_LABEL), oneOf("foo-mixed-3", "foo-mixed-4"));
TestUtils.checkOwnerReference(service, POOL_MIXED);
}

Expand Down Expand Up @@ -2163,7 +2163,7 @@ public void testClusterIP() {

assertThat(service.getMetadata().getName(), oneOf("foo-mixed-clusterip-3", "foo-mixed-clusterip-4", "foo-brokers-clusterip-5", "foo-brokers-clusterip-6", "foo-brokers-clusterip-7"));
assertThat(service.getSpec().getType(), is("ClusterIP"));
assertThat(service.getSpec().getSelector().get(Labels.KUBERNETES_STATEFULSET_POD_LABEL), oneOf("foo-mixed-3", "foo-mixed-4", "foo-brokers-5", "foo-brokers-6", "foo-brokers-7"));
assertThat(service.getSpec().getSelector().get(Labels.STRIMZI_POD_NAME_LABEL), oneOf("foo-mixed-3", "foo-mixed-4", "foo-brokers-5", "foo-brokers-6", "foo-brokers-7"));
assertThat(service.getSpec().getPorts().size(), is(1));
assertThat(service.getSpec().getPorts().get(0).getName(), is("tcp-clusterip"));
assertThat(service.getSpec().getPorts().get(0).getPort(), is(9094));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3332,7 +3332,7 @@ public void testPodSet() {
assertThat(pods.size(), is(3));

for (Pod pod : pods) {
assertThat(pod.getMetadata().getLabels().entrySet().containsAll(KC.labels.withStrimziPodName(pod.getMetadata().getName()).withStatefulSetPod(pod.getMetadata().getName()).withStrimziPodSetController(CLUSTER + "-controllers").toMap().entrySet()), is(true));
assertThat(pod.getMetadata().getLabels().entrySet().containsAll(KC.labels.withStrimziPodName(pod.getMetadata().getName()).withStrimziPodSetController(CLUSTER + "-controllers").toMap().entrySet()), is(true));
assertThat(pod.getMetadata().getAnnotations().size(), is(2));
assertThat(pod.getMetadata().getAnnotations().get(PodRevision.STRIMZI_REVISION_ANNOTATION), is(notNullValue()));
assertThat(pod.getMetadata().getAnnotations().get("test-anno"), is("test-value"));
Expand Down Expand Up @@ -3398,7 +3398,7 @@ public void testPodSet() {
assertThat(pods.size(), is(2));

for (Pod pod : pods) {
assertThat(pod.getMetadata().getLabels().entrySet().containsAll(KC.labels.withStrimziPodName(pod.getMetadata().getName()).withStatefulSetPod(pod.getMetadata().getName()).withStrimziPodSetController(CLUSTER + "-mixed").toMap().entrySet()), is(true));
assertThat(pod.getMetadata().getLabels().entrySet().containsAll(KC.labels.withStrimziPodName(pod.getMetadata().getName()).withStrimziPodSetController(CLUSTER + "-mixed").toMap().entrySet()), is(true));
assertThat(pod.getMetadata().getAnnotations().size(), is(2));
assertThat(pod.getMetadata().getAnnotations().get(PodRevision.STRIMZI_REVISION_ANNOTATION), is(notNullValue()));
assertThat(pod.getMetadata().getAnnotations().get("test-anno"), is("test-value"));
Expand Down Expand Up @@ -3464,7 +3464,7 @@ public void testPodSet() {
assertThat(pods.size(), is(3));

for (Pod pod : pods) {
assertThat(pod.getMetadata().getLabels().entrySet().containsAll(KC.labels.withStrimziPodName(pod.getMetadata().getName()).withStatefulSetPod(pod.getMetadata().getName()).withStrimziPodSetController(CLUSTER + "-brokers").toMap().entrySet()), is(true));
assertThat(pod.getMetadata().getLabels().entrySet().containsAll(KC.labels.withStrimziPodName(pod.getMetadata().getName()).withStrimziPodSetController(CLUSTER + "-brokers").toMap().entrySet()), is(true));
assertThat(pod.getMetadata().getAnnotations().size(), is(2));
assertThat(pod.getMetadata().getAnnotations().get(PodRevision.STRIMZI_REVISION_ANNOTATION), is(notNullValue()));
assertThat(pod.getMetadata().getAnnotations().get("test-anno"), is("test-value"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ public void testPodSet() {
// We need to loop through the pods to make sure they have the right values
List<Pod> pods = PodSetUtils.podSetToPods(ps);
for (Pod pod : pods) {
assertThat(pod.getMetadata().getLabels().entrySet().containsAll(kc.labels.withStrimziPodName(pod.getMetadata().getName()).withStatefulSetPod(pod.getMetadata().getName()).withStrimziPodSetController(kc.getComponentName()).toMap().entrySet()), is(true));
assertThat(pod.getMetadata().getLabels().entrySet().containsAll(kc.labels.withStrimziPodName(pod.getMetadata().getName()).withStrimziPodSetController(kc.getComponentName()).toMap().entrySet()), is(true));
assertThat(pod.getMetadata().getAnnotations().size(), is(2));
assertThat(pod.getMetadata().getAnnotations().get(PodRevision.STRIMZI_REVISION_ANNOTATION), is(notNullValue()));
assertThat(pod.getMetadata().getAnnotations().get("anno3"), is("anno-value3"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ public void testPodSet() {
// We need to loop through the pods to make sure they have the right values
List<Pod> pods = PodSetUtils.podSetToPods(ps);
for (Pod pod : pods) {
assertThat(pod.getMetadata().getLabels().entrySet().containsAll(kmm2.labels.withStrimziPodName(pod.getMetadata().getName()).withStatefulSetPod(pod.getMetadata().getName()).withStrimziPodSetController(kmm2.getComponentName()).toMap().entrySet()), is(true));
assertThat(pod.getMetadata().getLabels().entrySet().containsAll(kmm2.labels.withStrimziPodName(pod.getMetadata().getName()).withStrimziPodSetController(kmm2.getComponentName()).toMap().entrySet()), is(true));
assertThat(pod.getMetadata().getAnnotations().size(), is(2));
assertThat(pod.getMetadata().getAnnotations().get(PodRevision.STRIMZI_REVISION_ANNOTATION), is(notNullValue()));
assertThat(pod.getMetadata().getAnnotations().get("anno3"), is("anno-value3"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,9 +450,8 @@ public void testCreateStatefulPodWithNullValues() {
assertThat(pod.getMetadata().getLabels(), is(LABELS
.withStrimziPodSetController(NAME)
.withStrimziPodName(NAME + "-0")
.withAdditionalLabels(Map.of("statefulset.kubernetes.io/pod-name", "my-workload-0"))
.toMap()));
assertThat(pod.getMetadata().getAnnotations(), is(Map.of(PodRevision.STRIMZI_REVISION_ANNOTATION, "6a6a679b")));
assertThat(pod.getMetadata().getAnnotations(), is(Map.of(PodRevision.STRIMZI_REVISION_ANNOTATION, "eaf3698c")));

assertThat(pod.getSpec().getRestartPolicy(), is("Always"));
assertThat(pod.getSpec().getHostname(), is(NAME + "-0"));
Expand Down Expand Up @@ -501,9 +500,9 @@ public void testCreateStatefulPodWithNullValuesAndNullTemplate() {
assertThat(pod.getMetadata().getLabels(), is(LABELS
.withStrimziPodSetController(NAME)
.withStrimziPodName(NAME + "-0")
.withAdditionalLabels(Map.of("statefulset.kubernetes.io/pod-name", "my-workload-0", "default-label", "default-value"))
.withAdditionalLabels(Map.of("default-label", "default-value"))
.toMap()));
assertThat(pod.getMetadata().getAnnotations(), is(Map.of("extra", "annotations", PodRevision.STRIMZI_REVISION_ANNOTATION, "da09ff49")));
assertThat(pod.getMetadata().getAnnotations(), is(Map.of("extra", "annotations", PodRevision.STRIMZI_REVISION_ANNOTATION, "65a2d237")));

assertThat(pod.getSpec().getRestartPolicy(), is("Always"));
assertThat(pod.getSpec().getHostname(), is(NAME + "-0"));
Expand Down Expand Up @@ -553,9 +552,9 @@ public void testCreateStatefulPodWithEmptyTemplate() {
assertThat(pod.getMetadata().getLabels(), is(LABELS
.withStrimziPodSetController(NAME)
.withStrimziPodName(NAME + "-0")
.withAdditionalLabels(Map.of("statefulset.kubernetes.io/pod-name", "my-workload-0", "default-label", "default-value"))
.withAdditionalLabels(Map.of("default-label", "default-value"))
.toMap()));
assertThat(pod.getMetadata().getAnnotations(), is(Map.of("extra", "annotations", PodRevision.STRIMZI_REVISION_ANNOTATION, "da09ff49")));
assertThat(pod.getMetadata().getAnnotations(), is(Map.of("extra", "annotations", PodRevision.STRIMZI_REVISION_ANNOTATION, "65a2d237")));

assertThat(pod.getSpec().getRestartPolicy(), is("Always"));
assertThat(pod.getSpec().getHostname(), is(NAME + "-0"));
Expand Down Expand Up @@ -622,9 +621,9 @@ public void testCreateStatefulPodWithTemplate() {
assertThat(pod.getMetadata().getLabels(), is(LABELS
.withStrimziPodSetController(NAME)
.withStrimziPodName(NAME + "-0")
.withAdditionalLabels(Map.of("statefulset.kubernetes.io/pod-name", "my-workload-0", "default-label", "default-value", "label-3", "value-3", "label-4", "value-4"))
.withAdditionalLabels(Map.of("default-label", "default-value", "label-3", "value-3", "label-4", "value-4"))
.toMap()));
assertThat(pod.getMetadata().getAnnotations(), is(Map.of("extra", "annotations", "anno-1", "value-1", "anno-2", "value-2", PodRevision.STRIMZI_REVISION_ANNOTATION, "d3ffc657")));
assertThat(pod.getMetadata().getAnnotations(), is(Map.of("extra", "annotations", "anno-1", "value-1", "anno-2", "value-2", PodRevision.STRIMZI_REVISION_ANNOTATION, "6458a317")));

assertThat(pod.getSpec().getRestartPolicy(), is("Always"));
assertThat(pod.getSpec().getHostname(), is(NAME + "-0"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,6 @@ public class Labels extends ResourceLabels {
*/
public static final String KUBERNETES_MANAGED_BY_LABEL = KUBERNETES_DOMAIN + "managed-by";

/**
* Used to identify individual pods
*/
public static final String KUBERNETES_STATEFULSET_POD_LABEL = "statefulset.kubernetes.io/pod-name";

/**
* Used to exclude parent CR's labels from being assigned to provisioned subresources
*/
Expand Down Expand Up @@ -351,16 +346,6 @@ public Labels withStrimziDiscovery() {
return with(STRIMZI_DISCOVERY_LABEL, "true");
}

/**
* The same labels as this instance, but with the given {@code name} for the {@code statefulset.kubernetes.io/pod-name} key.
*
* @param name The pod name to add
* @return A new instance with the given pod name added.
*/
public Labels withStatefulSetPod(String name) {
return with(KUBERNETES_STATEFULSET_POD_LABEL, name);
}

/**
* Sets the Strimzi controller label to strimzipodset
*
Expand Down

0 comments on commit b6120c9

Please sign in to comment.