From c8fc9f2a4f6a79d0ae9ed227e74b4a288684b013 Mon Sep 17 00:00:00 2001 From: AvivGuiser Date: Sat, 7 Jun 2025 11:55:17 +0300 Subject: [PATCH 01/11] add option to use targetPortName in create service port function Signed-off-by: AvivGuiser --- .../operator/cluster/model/CruiseControl.java | 2 +- .../cluster/model/KafkaBridgeCluster.java | 2 +- .../operator/cluster/model/KafkaCluster.java | 14 ++++++++------ .../cluster/model/KafkaConnectCluster.java | 4 ++-- .../operator/cluster/model/ServiceUtils.java | 15 ++++++--------- .../operator/cluster/model/ServiceUtilsTest.java | 6 +++--- 6 files changed, 21 insertions(+), 22 deletions(-) diff --git a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/CruiseControl.java b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/CruiseControl.java index 8b965894d9c..5b234b3230d 100644 --- a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/CruiseControl.java +++ b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/CruiseControl.java @@ -303,7 +303,7 @@ public Service generateService() { labels, ownerReference, templateService, - List.of(ServiceUtils.createServicePort(REST_API_PORT_NAME, REST_API_PORT, REST_API_PORT, "TCP")) + List.of(ServiceUtils.createServicePort(REST_API_PORT_NAME, REST_API_PORT, REST_API_PORT,REST_API_PORT_NAME, "TCP")) ); } diff --git a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/KafkaBridgeCluster.java b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/KafkaBridgeCluster.java index 0ddb0ce3854..9f053687907 100644 --- a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/KafkaBridgeCluster.java +++ b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/KafkaBridgeCluster.java @@ -234,7 +234,7 @@ public Service generateService() { labels, ownerReference, templateService, - List.of(ServiceUtils.createServicePort(REST_API_PORT_NAME, port, port, "TCP")), + List.of(ServiceUtils.createServicePort(REST_API_PORT_NAME, port, port, REST_API_PORT_NAME, "TCP")), labels.strimziSelectorLabels(), ModelUtils.getCustomLabelsOrAnnotations(CO_ENV_VAR_CUSTOM_SERVICE_LABELS), Util.mergeLabelsOrAnnotations(getDiscoveryAnnotation(port), ModelUtils.getCustomLabelsOrAnnotations(CO_ENV_VAR_CUSTOM_SERVICE_ANNOTATIONS)) diff --git a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/KafkaCluster.java b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/KafkaCluster.java index d981a888298..16de4c04ee0 100644 --- a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/KafkaCluster.java +++ b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/KafkaCluster.java @@ -650,10 +650,10 @@ private List getServicePorts() { List internalListeners = ListenersUtils.internalListeners(listeners); List ports = new ArrayList<>(internalListeners.size() + 1); - ports.add(ServiceUtils.createServicePort(REPLICATION_PORT_NAME, REPLICATION_PORT, REPLICATION_PORT, "TCP")); + ports.add(ServiceUtils.createServicePort(REPLICATION_PORT_NAME, REPLICATION_PORT, REPLICATION_PORT,REPLICATION_PORT_NAME, "TCP")); for (GenericKafkaListener listener : internalListeners) { - ports.add(ServiceUtils.createServicePort(ListenersUtils.backwardsCompatiblePortName(listener), listener.getPort(), listener.getPort(), "TCP")); + ports.add(ServiceUtils.createServicePort(ListenersUtils.backwardsCompatiblePortName(listener), listener.getPort(), listener.getPort(),ListenersUtils.backwardsCompatiblePortName(listener), "TCP")); } return ports; @@ -669,12 +669,12 @@ private List getHeadlessServicePorts() { List internalListeners = ListenersUtils.internalListeners(listeners); List ports = new ArrayList<>(internalListeners.size() + 3); - ports.add(ServiceUtils.createServicePort(CONTROLPLANE_PORT_NAME, CONTROLPLANE_PORT, CONTROLPLANE_PORT, "TCP")); - ports.add(ServiceUtils.createServicePort(REPLICATION_PORT_NAME, REPLICATION_PORT, REPLICATION_PORT, "TCP")); - ports.add(ServiceUtils.createServicePort(KAFKA_AGENT_PORT_NAME, KAFKA_AGENT_PORT, KAFKA_AGENT_PORT, "TCP")); + ports.add(ServiceUtils.createServicePort(CONTROLPLANE_PORT_NAME, CONTROLPLANE_PORT, CONTROLPLANE_PORT, CONTROLPLANE_PORT_NAME,"TCP")); + ports.add(ServiceUtils.createServicePort(REPLICATION_PORT_NAME, REPLICATION_PORT, REPLICATION_PORT, REPLICATION_PORT_NAME,"TCP")); + ports.add(ServiceUtils.createServicePort(KAFKA_AGENT_PORT_NAME, KAFKA_AGENT_PORT, KAFKA_AGENT_PORT, KAFKA_AGENT_PORT_NAME,"TCP")); for (GenericKafkaListener listener : internalListeners) { - ports.add(ServiceUtils.createServicePort(ListenersUtils.backwardsCompatiblePortName(listener), listener.getPort(), listener.getPort(), "TCP")); + ports.add(ServiceUtils.createServicePort(ListenersUtils.backwardsCompatiblePortName(listener), listener.getPort(), listener.getPort(),ListenersUtils.backwardsCompatiblePortName(listener), "TCP")); } ports.addAll(jmx.servicePorts()); @@ -748,6 +748,7 @@ public List generateExternalBootstrapServices() { ServiceUtils.createServicePort(ListenersUtils.backwardsCompatiblePortName(listener), listener.getPort(), listener.getPort(), + ListenersUtils.backwardsCompatiblePortName(listener), ListenersUtils.bootstrapNodePort(listener), "TCP") ); @@ -839,6 +840,7 @@ public List generatePerPodServices() { ListenersUtils.backwardsCompatiblePortName(listener), listener.getPort(), listener.getPort(), + ListenersUtils.backwardsCompatiblePortName(listener), ListenersUtils.brokerNodePort(listener, node.nodeId()), "TCP") ); diff --git a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/KafkaConnectCluster.java b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/KafkaConnectCluster.java index 8b82270f6b2..9eef7730546 100644 --- a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/KafkaConnectCluster.java +++ b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/KafkaConnectCluster.java @@ -342,7 +342,7 @@ public String getServiceName() { */ public Service generateService() { List ports = new ArrayList<>(1); - ports.add(ServiceUtils.createServicePort(REST_API_PORT_NAME, REST_API_PORT, REST_API_PORT, "TCP")); + ports.add(ServiceUtils.createServicePort(REST_API_PORT_NAME, REST_API_PORT, REST_API_PORT, REST_API_PORT_NAME,"TCP")); ports.addAll(jmx.servicePorts()); @@ -362,7 +362,7 @@ public Service generateService() { * @return The generated Service */ public Service generateHeadlessService() { - List ports = List.of(ServiceUtils.createServicePort(REST_API_PORT_NAME, REST_API_PORT, REST_API_PORT, "TCP")); + List ports = List.of(ServiceUtils.createServicePort(REST_API_PORT_NAME, REST_API_PORT, REST_API_PORT, REST_API_PORT_NAME,"TCP")); return ServiceUtils.createHeadlessService( componentName, diff --git a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/ServiceUtils.java b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/ServiceUtils.java index ac2592f2a47..f8048418552 100644 --- a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/ServiceUtils.java +++ b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/ServiceUtils.java @@ -4,11 +4,7 @@ */ package io.strimzi.operator.cluster.model; -import io.fabric8.kubernetes.api.model.OwnerReference; -import io.fabric8.kubernetes.api.model.Service; -import io.fabric8.kubernetes.api.model.ServiceBuilder; -import io.fabric8.kubernetes.api.model.ServicePort; -import io.fabric8.kubernetes.api.model.ServicePortBuilder; +import io.fabric8.kubernetes.api.model.*; import io.strimzi.api.kafka.model.common.template.HasMetadataTemplate; import io.strimzi.api.kafka.model.common.template.InternalServiceTemplate; import io.strimzi.api.kafka.model.common.template.IpFamily; @@ -18,6 +14,7 @@ import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.stream.Collectors; /** @@ -224,8 +221,8 @@ private static List ipFamilies(InternalServiceTemplate template) { * * @return Created port */ - public static ServicePort createServicePort(String name, int port, int targetPort, String protocol) { - return createServicePort(name, port, targetPort, null, protocol); + public static ServicePort createServicePort(String name, int port, int targetPort, String targetPortName, String protocol) { + return createServicePort(name, port, targetPort, targetPortName, protocol); } /** @@ -239,12 +236,12 @@ public static ServicePort createServicePort(String name, int port, int targetPor * * @return Created port */ - public static ServicePort createServicePort(String name, int port, int targetPort, Integer nodePort, String protocol) { + public static ServicePort createServicePort(String name, int port, int targetPort, String targetPortName, Integer nodePort, String protocol) { return new ServicePortBuilder() .withName(name) .withProtocol(protocol) .withPort(port) - .withNewTargetPort(targetPort) + .withNewTargetPort(Objects.requireNonNullElse(targetPortName, targetPort)) .withNodePort(nodePort) .build(); } diff --git a/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/ServiceUtilsTest.java b/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/ServiceUtilsTest.java index f43cc1d8cd2..38cd6c5a4f0 100644 --- a/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/ServiceUtilsTest.java +++ b/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/ServiceUtilsTest.java @@ -42,7 +42,7 @@ public class ServiceUtilsTest { .withStrimziComponentType("my-component-type") .withAdditionalLabels(Map.of("label-1", "value-1", "label-2", "value-2")); private static final String PORT_NAME = "my-port"; - private static final ServicePort PORT = ServiceUtils.createServicePort(PORT_NAME, 1234, 5678, "HTTP"); + private static final ServicePort PORT = ServiceUtils.createServicePort(PORT_NAME, 1234, 5678, PORT_NAME,"HTTP"); private static final InternalServiceTemplate TEMPLATE = new InternalServiceTemplateBuilder() .withNewMetadata() .withLabels(Map.of("label-3", "value-3", "label-4", "value-4")) @@ -54,7 +54,7 @@ public class ServiceUtilsTest { @ParallelTest public void testCreateServicePort() { - ServicePort port = ServiceUtils.createServicePort(PORT_NAME, 1234, 5678, "HTTP"); + ServicePort port = ServiceUtils.createServicePort(PORT_NAME, 1234, 5678,PORT_NAME, "HTTP"); assertThat(port.getName(), is(PORT_NAME)); assertThat(port.getPort(), is(1234)); @@ -65,7 +65,7 @@ public void testCreateServicePort() { @ParallelTest public void testCreateServiceWithNodePort() { - ServicePort port = ServiceUtils.createServicePort(PORT_NAME, 1234, 5678, 30000, "HTTP"); + ServicePort port = ServiceUtils.createServicePort(PORT_NAME, 1234, 5678, PORT_NAME,30000, "HTTP"); assertThat(port.getName(), is(PORT_NAME)); assertThat(port.getPort(), is(1234)); From 09ed33ce61110f12c5aae2a857f9a9c8ae897ec9 Mon Sep 17 00:00:00 2001 From: AvivGuiser Date: Sat, 7 Jun 2025 14:02:05 +0300 Subject: [PATCH 02/11] fix checkstyle Signed-off-by: AvivGuiser --- .../operator/cluster/model/CruiseControl.java | 2 +- .../strimzi/operator/cluster/model/KafkaCluster.java | 12 ++++++------ .../operator/cluster/model/KafkaConnectCluster.java | 4 ++-- .../strimzi/operator/cluster/model/ServiceUtils.java | 6 +++++- .../strimzi/operator/cluster/model/jmx/JmxModel.java | 2 +- .../operator/cluster/model/ServiceUtilsTest.java | 6 +++--- 6 files changed, 18 insertions(+), 14 deletions(-) diff --git a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/CruiseControl.java b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/CruiseControl.java index 5b234b3230d..58e8b3d0f58 100644 --- a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/CruiseControl.java +++ b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/CruiseControl.java @@ -303,7 +303,7 @@ public Service generateService() { labels, ownerReference, templateService, - List.of(ServiceUtils.createServicePort(REST_API_PORT_NAME, REST_API_PORT, REST_API_PORT,REST_API_PORT_NAME, "TCP")) + List.of(ServiceUtils.createServicePort(REST_API_PORT_NAME, REST_API_PORT, REST_API_PORT, REST_API_PORT_NAME, "TCP")) ); } diff --git a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/KafkaCluster.java b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/KafkaCluster.java index 16de4c04ee0..187a4b6be4e 100644 --- a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/KafkaCluster.java +++ b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/KafkaCluster.java @@ -650,10 +650,10 @@ private List getServicePorts() { List internalListeners = ListenersUtils.internalListeners(listeners); List ports = new ArrayList<>(internalListeners.size() + 1); - ports.add(ServiceUtils.createServicePort(REPLICATION_PORT_NAME, REPLICATION_PORT, REPLICATION_PORT,REPLICATION_PORT_NAME, "TCP")); + ports.add(ServiceUtils.createServicePort(REPLICATION_PORT_NAME, REPLICATION_PORT, REPLICATION_PORT, REPLICATION_PORT_NAME, "TCP")); for (GenericKafkaListener listener : internalListeners) { - ports.add(ServiceUtils.createServicePort(ListenersUtils.backwardsCompatiblePortName(listener), listener.getPort(), listener.getPort(),ListenersUtils.backwardsCompatiblePortName(listener), "TCP")); + ports.add(ServiceUtils.createServicePort(ListenersUtils.backwardsCompatiblePortName(listener), listener.getPort(), listener.getPort(), ListenersUtils.backwardsCompatiblePortName(listener), "TCP")); } return ports; @@ -669,12 +669,12 @@ private List getHeadlessServicePorts() { List internalListeners = ListenersUtils.internalListeners(listeners); List ports = new ArrayList<>(internalListeners.size() + 3); - ports.add(ServiceUtils.createServicePort(CONTROLPLANE_PORT_NAME, CONTROLPLANE_PORT, CONTROLPLANE_PORT, CONTROLPLANE_PORT_NAME,"TCP")); - ports.add(ServiceUtils.createServicePort(REPLICATION_PORT_NAME, REPLICATION_PORT, REPLICATION_PORT, REPLICATION_PORT_NAME,"TCP")); - ports.add(ServiceUtils.createServicePort(KAFKA_AGENT_PORT_NAME, KAFKA_AGENT_PORT, KAFKA_AGENT_PORT, KAFKA_AGENT_PORT_NAME,"TCP")); + ports.add(ServiceUtils.createServicePort(CONTROLPLANE_PORT_NAME, CONTROLPLANE_PORT, CONTROLPLANE_PORT, CONTROLPLANE_PORT_NAME, "TCP")); + ports.add(ServiceUtils.createServicePort(REPLICATION_PORT_NAME, REPLICATION_PORT, REPLICATION_PORT, REPLICATION_PORT_NAME, "TCP")); + ports.add(ServiceUtils.createServicePort(KAFKA_AGENT_PORT_NAME, KAFKA_AGENT_PORT, KAFKA_AGENT_PORT, KAFKA_AGENT_PORT_NAME, "TCP")); for (GenericKafkaListener listener : internalListeners) { - ports.add(ServiceUtils.createServicePort(ListenersUtils.backwardsCompatiblePortName(listener), listener.getPort(), listener.getPort(),ListenersUtils.backwardsCompatiblePortName(listener), "TCP")); + ports.add(ServiceUtils.createServicePort(ListenersUtils.backwardsCompatiblePortName(listener), listener.getPort(), listener.getPort(), ListenersUtils.backwardsCompatiblePortName(listener), "TCP")); } ports.addAll(jmx.servicePorts()); diff --git a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/KafkaConnectCluster.java b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/KafkaConnectCluster.java index 9eef7730546..28ea46a0aa0 100644 --- a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/KafkaConnectCluster.java +++ b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/KafkaConnectCluster.java @@ -342,7 +342,7 @@ public String getServiceName() { */ public Service generateService() { List ports = new ArrayList<>(1); - ports.add(ServiceUtils.createServicePort(REST_API_PORT_NAME, REST_API_PORT, REST_API_PORT, REST_API_PORT_NAME,"TCP")); + ports.add(ServiceUtils.createServicePort(REST_API_PORT_NAME, REST_API_PORT, REST_API_PORT, REST_API_PORT_NAME, "TCP")); ports.addAll(jmx.servicePorts()); @@ -362,7 +362,7 @@ public Service generateService() { * @return The generated Service */ public Service generateHeadlessService() { - List ports = List.of(ServiceUtils.createServicePort(REST_API_PORT_NAME, REST_API_PORT, REST_API_PORT, REST_API_PORT_NAME,"TCP")); + List ports = List.of(ServiceUtils.createServicePort(REST_API_PORT_NAME, REST_API_PORT, REST_API_PORT, REST_API_PORT_NAME, "TCP")); return ServiceUtils.createHeadlessService( componentName, diff --git a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/ServiceUtils.java b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/ServiceUtils.java index f8048418552..9201416a744 100644 --- a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/ServiceUtils.java +++ b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/ServiceUtils.java @@ -4,7 +4,9 @@ */ package io.strimzi.operator.cluster.model; -import io.fabric8.kubernetes.api.model.*; +import io.fabric8.kubernetes.api.model.OwnerReference; +import io.fabric8.kubernetes.api.model.Service; +import io.fabric8.kubernetes.api.model.ServicePort; import io.strimzi.api.kafka.model.common.template.HasMetadataTemplate; import io.strimzi.api.kafka.model.common.template.InternalServiceTemplate; import io.strimzi.api.kafka.model.common.template.IpFamily; @@ -217,6 +219,7 @@ private static List ipFamilies(InternalServiceTemplate template) { * @param name Name of the port * @param port The port on the service which can be accessed by clients * @param targetPort The port on the container / Pod where the connections will be routed + * @param targetPortName the name of the target port on the container / Pod where the connections will be routed * @param protocol Protocol used by this port * * @return Created port @@ -231,6 +234,7 @@ public static ServicePort createServicePort(String name, int port, int targetPor * @param name Name of the port * @param port The port on the service which can be accessed by clients * @param targetPort The port on the container / Pod where the connections will be routed + * @param targetPortName the name of the target port on the container / Pod where the connections will be routed * @param nodePort The desired node port number * @param protocol Protocol used by this port * diff --git a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/jmx/JmxModel.java b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/jmx/JmxModel.java index 24e77f05e80..41c7a1093c3 100644 --- a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/jmx/JmxModel.java +++ b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/jmx/JmxModel.java @@ -115,7 +115,7 @@ public String secretName() { */ public List servicePorts() { if (isEnabled) { - return List.of(ServiceUtils.createServicePort(JMX_PORT_NAME, JMX_PORT, JMX_PORT, "TCP")); + return List.of(ServiceUtils.createServicePort(JMX_PORT_NAME, JMX_PORT, JMX_PORT, JMX_PORT_NAME, "TCP")); } else { return List.of(); } diff --git a/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/ServiceUtilsTest.java b/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/ServiceUtilsTest.java index 38cd6c5a4f0..e90bb6394e9 100644 --- a/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/ServiceUtilsTest.java +++ b/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/ServiceUtilsTest.java @@ -42,7 +42,7 @@ public class ServiceUtilsTest { .withStrimziComponentType("my-component-type") .withAdditionalLabels(Map.of("label-1", "value-1", "label-2", "value-2")); private static final String PORT_NAME = "my-port"; - private static final ServicePort PORT = ServiceUtils.createServicePort(PORT_NAME, 1234, 5678, PORT_NAME,"HTTP"); + private static final ServicePort PORT = ServiceUtils.createServicePort(PORT_NAME, 1234, 5678, PORT_NAME, "HTTP"); private static final InternalServiceTemplate TEMPLATE = new InternalServiceTemplateBuilder() .withNewMetadata() .withLabels(Map.of("label-3", "value-3", "label-4", "value-4")) @@ -54,7 +54,7 @@ public class ServiceUtilsTest { @ParallelTest public void testCreateServicePort() { - ServicePort port = ServiceUtils.createServicePort(PORT_NAME, 1234, 5678,PORT_NAME, "HTTP"); + ServicePort port = ServiceUtils.createServicePort(PORT_NAME, 1234, 5678, PORT_NAME, "HTTP"); assertThat(port.getName(), is(PORT_NAME)); assertThat(port.getPort(), is(1234)); @@ -65,7 +65,7 @@ public void testCreateServicePort() { @ParallelTest public void testCreateServiceWithNodePort() { - ServicePort port = ServiceUtils.createServicePort(PORT_NAME, 1234, 5678, PORT_NAME,30000, "HTTP"); + ServicePort port = ServiceUtils.createServicePort(PORT_NAME, 1234, 5678, PORT_NAME, 30000, "HTTP"); assertThat(port.getName(), is(PORT_NAME)); assertThat(port.getPort(), is(1234)); From da8c21b05aebc4a00343a898fd33b3925d899999 Mon Sep 17 00:00:00 2001 From: AvivGuiser Date: Sat, 7 Jun 2025 14:15:52 +0300 Subject: [PATCH 03/11] fix missing imports Signed-off-by: AvivGuiser --- .../java/io/strimzi/operator/cluster/model/ServiceUtils.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/ServiceUtils.java b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/ServiceUtils.java index 9201416a744..adc93814e8f 100644 --- a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/ServiceUtils.java +++ b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/ServiceUtils.java @@ -6,7 +6,9 @@ import io.fabric8.kubernetes.api.model.OwnerReference; import io.fabric8.kubernetes.api.model.Service; +import io.fabric8.kubernetes.api.model.ServiceBuilder; import io.fabric8.kubernetes.api.model.ServicePort; +import io.fabric8.kubernetes.api.model.ServicePortBuilder; import io.strimzi.api.kafka.model.common.template.HasMetadataTemplate; import io.strimzi.api.kafka.model.common.template.InternalServiceTemplate; import io.strimzi.api.kafka.model.common.template.IpFamily; From d51ebd214810b7631d65f098c30766aaaa7f2752 Mon Sep 17 00:00:00 2001 From: AvivGuiser Date: Sat, 7 Jun 2025 14:34:47 +0300 Subject: [PATCH 04/11] fix infinite-recursion Signed-off-by: AvivGuiser --- .../java/io/strimzi/operator/cluster/model/ServiceUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/ServiceUtils.java b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/ServiceUtils.java index adc93814e8f..2384c4a7405 100644 --- a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/ServiceUtils.java +++ b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/ServiceUtils.java @@ -227,7 +227,7 @@ private static List ipFamilies(InternalServiceTemplate template) { * @return Created port */ public static ServicePort createServicePort(String name, int port, int targetPort, String targetPortName, String protocol) { - return createServicePort(name, port, targetPort, targetPortName, protocol); + return createServicePort(name, port, targetPort, targetPortName,null, protocol); } /** From 6f1893f72af7f93245230e2a0f1471bf8d333742 Mon Sep 17 00:00:00 2001 From: AvivGuiser Date: Sat, 7 Jun 2025 14:44:08 +0300 Subject: [PATCH 05/11] fix checkstyle Signed-off-by: AvivGuiser --- .../java/io/strimzi/operator/cluster/model/ServiceUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/ServiceUtils.java b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/ServiceUtils.java index 2384c4a7405..9ab506280cb 100644 --- a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/ServiceUtils.java +++ b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/ServiceUtils.java @@ -227,7 +227,7 @@ private static List ipFamilies(InternalServiceTemplate template) { * @return Created port */ public static ServicePort createServicePort(String name, int port, int targetPort, String targetPortName, String protocol) { - return createServicePort(name, port, targetPort, targetPortName,null, protocol); + return createServicePort(name, port, targetPort, targetPortName, null, protocol); } /** From 2ef2df8cb725969659b29d42dd31f4aa8e59fc18 Mon Sep 17 00:00:00 2001 From: AvivGuiser Date: Sat, 7 Jun 2025 16:24:18 +0300 Subject: [PATCH 06/11] fix tests Signed-off-by: AvivGuiser --- .../model/KafkaClusterListenersTest.java | 40 +++++++++---------- .../cluster/model/ServiceUtilsTest.java | 4 +- .../cluster/model/jmx/JmxModelTest.java | 8 ++-- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/KafkaClusterListenersTest.java b/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/KafkaClusterListenersTest.java index 290286a77ab..0053d84b584 100644 --- a/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/KafkaClusterListenersTest.java +++ b/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/KafkaClusterListenersTest.java @@ -775,7 +775,7 @@ public void testExternalRoutes() { assertThat(bootstrapServices.get(0).getSpec().getPorts().size(), is(1)); assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getName(), is(ListenersUtils.BACKWARDS_COMPATIBLE_EXTERNAL_PORT_NAME)); assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getPort(), is(9094)); - assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getTargetPort().getIntVal(), is(9094)); + assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getTargetPort().getStrVal(), is("tcp-external")); assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getNodePort(), is(nullValue())); assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getProtocol(), is("TCP")); TestUtils.checkOwnerReference(bootstrapServices.get(0), KAFKA); @@ -799,7 +799,7 @@ public void testExternalRoutes() { assertThat(service.getSpec().getPorts().size(), is(1)); assertThat(service.getSpec().getPorts().get(0).getName(), is(ListenersUtils.BACKWARDS_COMPATIBLE_EXTERNAL_PORT_NAME)); assertThat(service.getSpec().getPorts().get(0).getPort(), is(9094)); - assertThat(service.getSpec().getPorts().get(0).getTargetPort().getIntVal(), is(9094)); + assertThat(service.getSpec().getPorts().get(0).getTargetPort().getStrVal(), is("tcp-external")); assertThat(service.getSpec().getPorts().get(0).getNodePort(), is(nullValue())); assertThat(service.getSpec().getPorts().get(0).getProtocol(), is("TCP")); } @@ -1006,7 +1006,7 @@ public void testExternalLoadBalancers() { assertThat(bootstrapServices.get(0).getSpec().getPorts().size(), is(1)); assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getName(), is(ListenersUtils.BACKWARDS_COMPATIBLE_EXTERNAL_PORT_NAME)); assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getPort(), is(9094)); - assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getTargetPort().getIntVal(), is(9094)); + assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getTargetPort().getStrVal(), is("tcp-external")); assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getNodePort(), is(nullValue())); assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getProtocol(), is("TCP")); assertThat(bootstrapServices.get(0).getSpec().getLoadBalancerIP(), is(nullValue())); @@ -1035,7 +1035,7 @@ public void testExternalLoadBalancers() { assertThat(service.getSpec().getPorts().size(), is(1)); assertThat(service.getSpec().getPorts().get(0).getName(), is(ListenersUtils.BACKWARDS_COMPATIBLE_EXTERNAL_PORT_NAME)); assertThat(service.getSpec().getPorts().get(0).getPort(), is(9094)); - assertThat(service.getSpec().getPorts().get(0).getTargetPort().getIntVal(), is(9094)); + assertThat(service.getSpec().getPorts().get(0).getTargetPort().getStrVal(), is("tcp-external")); assertThat(service.getSpec().getPorts().get(0).getNodePort(), is(nullValue())); assertThat(service.getSpec().getPorts().get(0).getProtocol(), is("TCP")); assertThat(service.getSpec().getLoadBalancerIP(), is(nullValue())); @@ -1162,14 +1162,14 @@ public void testExternalLoadBalancerAllocateNodePorts() { assertThat(externalServices, hasSize(1)); assertThat(externalServices.get(0).getSpec().getAllocateLoadBalancerNodePorts(), is(false)); assertThat(externalServices.get(0).getSpec().getPorts(), hasSize(1)); - assertThat(externalServices.get(0).getSpec().getPorts().get(0).getTargetPort().getIntVal(), is(9094)); + assertThat(externalServices.get(0).getSpec().getPorts().get(0).getTargetPort().getStrVal(), is("tcp-lb1")); List perPodServices = kc.generatePerPodServices(); assertThat(perPodServices, hasSize(5)); for (Service service : perPodServices) { assertThat(service.getSpec().getAllocateLoadBalancerNodePorts(), is(false)); assertThat(service.getSpec().getPorts(), hasSize(1)); - assertThat(service.getSpec().getPorts().get(0).getTargetPort().getIntVal(), is(9094)); + assertThat(service.getSpec().getPorts().get(0).getTargetPort().getStrVal(), is("tcp-external")); } } @@ -1426,7 +1426,7 @@ public void testExternalNodePorts() { assertThat(bootstrapServices.get(0).getSpec().getPorts().size(), is(1)); assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getName(), is(ListenersUtils.BACKWARDS_COMPATIBLE_EXTERNAL_PORT_NAME)); assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getPort(), is(9094)); - assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getTargetPort().getIntVal(), is(9094)); + assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getTargetPort().getStrVal(), is("tcp-external")); assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getNodePort(), is(nullValue())); assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getProtocol(), is("TCP")); TestUtils.checkOwnerReference(bootstrapServices.get(0), KAFKA); @@ -1450,7 +1450,7 @@ public void testExternalNodePorts() { assertThat(service.getSpec().getPorts().size(), is(1)); assertThat(service.getSpec().getPorts().get(0).getName(), is(ListenersUtils.BACKWARDS_COMPATIBLE_EXTERNAL_PORT_NAME)); assertThat(service.getSpec().getPorts().get(0).getPort(), is(9094)); - assertThat(service.getSpec().getPorts().get(0).getTargetPort().getIntVal(), is(9094)); + assertThat(service.getSpec().getPorts().get(0).getTargetPort().getStrVal(), is("tcp-external")); assertThat(service.getSpec().getPorts().get(0).getNodePort(), is(nullValue())); assertThat(service.getSpec().getPorts().get(0).getProtocol(), is("TCP")); } @@ -1612,7 +1612,7 @@ public void testExternalNodePortOverrides() { assertThat(ext.getSpec().getPorts().size(), is(1)); assertThat(ext.getSpec().getPorts().get(0).getName(), is(ListenersUtils.BACKWARDS_COMPATIBLE_EXTERNAL_PORT_NAME)); assertThat(ext.getSpec().getPorts().get(0).getPort(), is(9094)); - assertThat(ext.getSpec().getPorts().get(0).getTargetPort().getIntVal(), is(9094)); + assertThat(ext.getSpec().getPorts().get(0).getTargetPort().getStrVal(), is("tcp-external")); assertThat(ext.getSpec().getPorts().get(0).getNodePort(), is(32001)); assertThat(ext.getSpec().getPorts().get(0).getProtocol(), is("TCP")); @@ -1627,21 +1627,21 @@ public void testExternalNodePortOverrides() { assertThat(service.getSpec().getPorts().size(), is(1)); assertThat(service.getSpec().getPorts().get(0).getName(), is(ListenersUtils.BACKWARDS_COMPATIBLE_EXTERNAL_PORT_NAME)); assertThat(service.getSpec().getPorts().get(0).getPort(), is(9094)); - assertThat(service.getSpec().getPorts().get(0).getTargetPort().getIntVal(), is(9094)); + assertThat(service.getSpec().getPorts().get(0).getTargetPort().getStrVal(), is("tcp-external")); assertThat(service.getSpec().getPorts().get(0).getNodePort(), is(32106)); assertThat(service.getSpec().getPorts().get(0).getProtocol(), is("TCP")); } else if (service.getMetadata().getName().startsWith("foo-mixed-3")) { assertThat(service.getSpec().getPorts().size(), is(1)); assertThat(service.getSpec().getPorts().get(0).getName(), is(ListenersUtils.BACKWARDS_COMPATIBLE_EXTERNAL_PORT_NAME)); assertThat(service.getSpec().getPorts().get(0).getPort(), is(9094)); - assertThat(service.getSpec().getPorts().get(0).getTargetPort().getIntVal(), is(9094)); + assertThat(service.getSpec().getPorts().get(0).getTargetPort().getStrVal(), is("tcp-external")); assertThat(service.getSpec().getPorts().get(0).getNodePort(), is(32103)); assertThat(service.getSpec().getPorts().get(0).getProtocol(), is("TCP")); } else { assertThat(service.getSpec().getPorts().size(), is(1)); assertThat(service.getSpec().getPorts().get(0).getName(), is(ListenersUtils.BACKWARDS_COMPATIBLE_EXTERNAL_PORT_NAME)); assertThat(service.getSpec().getPorts().get(0).getPort(), is(9094)); - assertThat(service.getSpec().getPorts().get(0).getTargetPort().getIntVal(), is(9094)); + assertThat(service.getSpec().getPorts().get(0).getTargetPort().getStrVal(), is("tcp-external")); assertThat(service.getSpec().getPorts().get(0).getNodePort(), is(nullValue())); assertThat(service.getSpec().getPorts().get(0).getProtocol(), is("TCP")); } @@ -1744,7 +1744,7 @@ public void testNodePortWithLoadbalancer() { assertThat(kc.generateExternalBootstrapServices().get(0).getSpec().getPorts().size(), is(1)); assertThat(kc.generateExternalBootstrapServices().get(0).getSpec().getPorts().get(0).getName(), is(ListenersUtils.BACKWARDS_COMPATIBLE_EXTERNAL_PORT_NAME)); assertThat(kc.generateExternalBootstrapServices().get(0).getSpec().getPorts().get(0).getPort(), is(9094)); - assertThat(kc.generateExternalBootstrapServices().get(0).getSpec().getPorts().get(0).getTargetPort().getIntVal(), is(9094)); + assertThat(kc.generateExternalBootstrapServices().get(0).getSpec().getPorts().get(0).getTargetPort().getStrVal(), is("tcp-external")); assertThat(kc.generateExternalBootstrapServices().get(0).getSpec().getPorts().get(0).getNodePort(), is(32189)); assertThat(kc.generateExternalBootstrapServices().get(0).getSpec().getPorts().get(0).getProtocol(), is("TCP")); @@ -1757,21 +1757,21 @@ public void testNodePortWithLoadbalancer() { assertThat(service.getSpec().getPorts().size(), is(1)); assertThat(service.getSpec().getPorts().get(0).getName(), is(ListenersUtils.BACKWARDS_COMPATIBLE_EXTERNAL_PORT_NAME)); assertThat(service.getSpec().getPorts().get(0).getPort(), is(9094)); - assertThat(service.getSpec().getPorts().get(0).getTargetPort().getIntVal(), is(9094)); + assertThat(service.getSpec().getPorts().get(0).getTargetPort().getStrVal(), is("tcp-external")); assertThat(service.getSpec().getPorts().get(0).getNodePort(), is(32006)); assertThat(service.getSpec().getPorts().get(0).getProtocol(), is("TCP")); } else if (service.getMetadata().getName().startsWith("foo-mixed-3")) { assertThat(service.getSpec().getPorts().size(), is(1)); assertThat(service.getSpec().getPorts().get(0).getName(), is(ListenersUtils.BACKWARDS_COMPATIBLE_EXTERNAL_PORT_NAME)); assertThat(service.getSpec().getPorts().get(0).getPort(), is(9094)); - assertThat(service.getSpec().getPorts().get(0).getTargetPort().getIntVal(), is(9094)); + assertThat(service.getSpec().getPorts().get(0).getTargetPort().getStrVal(), is("tcp-external")); assertThat(service.getSpec().getPorts().get(0).getNodePort(), is(32003)); assertThat(service.getSpec().getPorts().get(0).getProtocol(), is("TCP")); } else { assertThat(service.getSpec().getPorts().size(), is(1)); assertThat(service.getSpec().getPorts().get(0).getName(), is(ListenersUtils.BACKWARDS_COMPATIBLE_EXTERNAL_PORT_NAME)); assertThat(service.getSpec().getPorts().get(0).getPort(), is(9094)); - assertThat(service.getSpec().getPorts().get(0).getTargetPort().getIntVal(), is(9094)); + assertThat(service.getSpec().getPorts().get(0).getTargetPort().getStrVal(), is("tcp-external")); assertThat(service.getSpec().getPorts().get(0).getNodePort(), is(nullValue())); assertThat(service.getSpec().getPorts().get(0).getProtocol(), is("TCP")); } @@ -1895,7 +1895,7 @@ public void testExternalIngress() { assertThat(bootstrapServices.get(0).getSpec().getPorts().size(), is(1)); assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getName(), is(ListenersUtils.BACKWARDS_COMPATIBLE_EXTERNAL_PORT_NAME)); assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getPort(), is(9094)); - assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getTargetPort().getIntVal(), is(9094)); + assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getTargetPort().getStrVal(), is("tcp-external")); assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getNodePort(), is(nullValue())); assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getProtocol(), is("TCP")); TestUtils.checkOwnerReference(bootstrapServices.get(0), KAFKA); @@ -1919,7 +1919,7 @@ public void testExternalIngress() { assertThat(service.getSpec().getPorts().size(), is(1)); assertThat(service.getSpec().getPorts().get(0).getName(), is(ListenersUtils.BACKWARDS_COMPATIBLE_EXTERNAL_PORT_NAME)); assertThat(service.getSpec().getPorts().get(0).getPort(), is(9094)); - assertThat(service.getSpec().getPorts().get(0).getTargetPort().getIntVal(), is(9094)); + assertThat(service.getSpec().getPorts().get(0).getTargetPort().getStrVal(), is("tcp-external")); assertThat(service.getSpec().getPorts().get(0).getNodePort(), is(nullValue())); assertThat(service.getSpec().getPorts().get(0).getProtocol(), is("TCP")); } @@ -2130,7 +2130,7 @@ public void testClusterIP() { assertThat(bootstrapServices.get(0).getSpec().getPorts().size(), is(1)); assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getName(), is("tcp-clusterip")); assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getPort(), is(9094)); - assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getTargetPort().getIntVal(), is(9094)); + assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getTargetPort().getStrVal(), is("tcp-clusterip")); assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getNodePort(), is(nullValue())); assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getProtocol(), is("TCP")); TestUtils.checkOwnerReference(bootstrapServices.get(0), KAFKA); @@ -2167,7 +2167,7 @@ public void testClusterIP() { 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)); - assertThat(service.getSpec().getPorts().get(0).getTargetPort().getIntVal(), is(9094)); + assertThat(service.getSpec().getPorts().get(0).getTargetPort().getStrVal(), is("tcp-clusterip")); assertThat(service.getSpec().getPorts().get(0).getNodePort(), is(nullValue())); assertThat(service.getSpec().getPorts().get(0).getProtocol(), is("TCP")); } diff --git a/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/ServiceUtilsTest.java b/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/ServiceUtilsTest.java index e90bb6394e9..ecabb622ab9 100644 --- a/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/ServiceUtilsTest.java +++ b/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/ServiceUtilsTest.java @@ -58,7 +58,7 @@ public void testCreateServicePort() { assertThat(port.getName(), is(PORT_NAME)); assertThat(port.getPort(), is(1234)); - assertThat(port.getTargetPort().getIntVal(), is(5678)); + assertThat(port.getTargetPort().getStrVal(), is(PORT_NAME)); assertThat(port.getNodePort(), is(nullValue())); assertThat(port.getProtocol(), is("HTTP")); } @@ -69,7 +69,7 @@ public void testCreateServiceWithNodePort() { assertThat(port.getName(), is(PORT_NAME)); assertThat(port.getPort(), is(1234)); - assertThat(port.getTargetPort().getIntVal(), is(5678)); + assertThat(port.getTargetPort().getStrVal(), is(PORT_NAME)); assertThat(port.getNodePort(), is(30000)); assertThat(port.getProtocol(), is("HTTP")); } diff --git a/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/jmx/JmxModelTest.java b/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/jmx/JmxModelTest.java index 95463afaff2..85fcccf00ac 100644 --- a/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/jmx/JmxModelTest.java +++ b/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/jmx/JmxModelTest.java @@ -73,7 +73,7 @@ public void testEnabledJmx() { assertThat(jmx.servicePorts().size(), is(1)); assertThat(jmx.servicePorts().get(0).getName(), is("jmx")); assertThat(jmx.servicePorts().get(0).getPort(), is(9999)); - assertThat(jmx.servicePorts().get(0).getTargetPort().getIntVal(), is(9999)); + assertThat(jmx.servicePorts().get(0).getTargetPort().getStrVal(), is("jmx")); assertThat(jmx.servicePorts().get(0).getProtocol(), is("TCP")); assertThat(jmx.containerPorts().size(), is(1)); @@ -86,7 +86,7 @@ public void testEnabledJmx() { assertThat(jmx.networkPolicyIngresRules().size(), is(1)); assertThat(jmx.networkPolicyIngresRules().get(0).getPorts().size(), is(1)); - assertThat(jmx.networkPolicyIngresRules().get(0).getPorts().get(0).getPort().getIntVal(), is(9999)); + assertThat(jmx.networkPolicyIngresRules().get(0).getPorts().get(0).getPort().getStrVal(), is("jmx")); assertThat(jmx.networkPolicyIngresRules().get(0).getFrom(), is(List.of())); assertThat(jmx.jmxSecret(null), is(nullValue())); @@ -108,7 +108,7 @@ public void testEnabledJmxWithAuthentication() { assertThat(jmx.servicePorts().size(), is(1)); assertThat(jmx.servicePorts().get(0).getName(), is("jmx")); assertThat(jmx.servicePorts().get(0).getPort(), is(9999)); - assertThat(jmx.servicePorts().get(0).getTargetPort().getIntVal(), is(9999)); + assertThat(jmx.servicePorts().get(0).getTargetPort().getStrVal(), is("jmx")); assertThat(jmx.servicePorts().get(0).getProtocol(), is("TCP")); assertThat(jmx.containerPorts().size(), is(1)); @@ -127,7 +127,7 @@ public void testEnabledJmxWithAuthentication() { assertThat(jmx.networkPolicyIngresRules().size(), is(1)); assertThat(jmx.networkPolicyIngresRules().get(0).getPorts().size(), is(1)); - assertThat(jmx.networkPolicyIngresRules().get(0).getPorts().get(0).getPort().getIntVal(), is(9999)); + assertThat(jmx.networkPolicyIngresRules().get(0).getPorts().get(0).getPort().getStrVal(), is("jmx")); assertThat(jmx.networkPolicyIngresRules().get(0).getFrom(), is(List.of())); Secret newSecret = jmx.jmxSecret(null); From 81bcd630f44abe991f9912af49988bdbe433d8df Mon Sep 17 00:00:00 2001 From: AvivGuiser Date: Sat, 7 Jun 2025 18:02:45 +0300 Subject: [PATCH 07/11] fix tests Signed-off-by: AvivGuiser --- .../java/io/strimzi/operator/cluster/model/jmx/JmxModel.java | 2 +- .../operator/cluster/model/KafkaClusterListenersTest.java | 2 +- .../io/strimzi/operator/cluster/model/jmx/JmxModelTest.java | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/jmx/JmxModel.java b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/jmx/JmxModel.java index 41c7a1093c3..f399fe4b56b 100644 --- a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/jmx/JmxModel.java +++ b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/jmx/JmxModel.java @@ -115,7 +115,7 @@ public String secretName() { */ public List servicePorts() { if (isEnabled) { - return List.of(ServiceUtils.createServicePort(JMX_PORT_NAME, JMX_PORT, JMX_PORT, JMX_PORT_NAME, "TCP")); + return List.of(ServiceUtils.createServicePort(JMX_PORT_NAME, JMX_PORT, JMX_PORT, JMX_PORT_NAME, "TCP")); } else { return List.of(); } diff --git a/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/KafkaClusterListenersTest.java b/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/KafkaClusterListenersTest.java index 0053d84b584..c280f9f752c 100644 --- a/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/KafkaClusterListenersTest.java +++ b/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/KafkaClusterListenersTest.java @@ -1169,7 +1169,7 @@ public void testExternalLoadBalancerAllocateNodePorts() { for (Service service : perPodServices) { assertThat(service.getSpec().getAllocateLoadBalancerNodePorts(), is(false)); assertThat(service.getSpec().getPorts(), hasSize(1)); - assertThat(service.getSpec().getPorts().get(0).getTargetPort().getStrVal(), is("tcp-external")); + assertThat(service.getSpec().getPorts().get(0).getTargetPort().getStrVal(), is("tcp-lb1")); } } diff --git a/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/jmx/JmxModelTest.java b/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/jmx/JmxModelTest.java index 85fcccf00ac..dc4843304d7 100644 --- a/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/jmx/JmxModelTest.java +++ b/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/jmx/JmxModelTest.java @@ -86,7 +86,7 @@ public void testEnabledJmx() { assertThat(jmx.networkPolicyIngresRules().size(), is(1)); assertThat(jmx.networkPolicyIngresRules().get(0).getPorts().size(), is(1)); - assertThat(jmx.networkPolicyIngresRules().get(0).getPorts().get(0).getPort().getStrVal(), is("jmx")); + assertThat(jmx.networkPolicyIngresRules().get(0).getPorts().get(0).getPort().getIntVal(), is(9999)); assertThat(jmx.networkPolicyIngresRules().get(0).getFrom(), is(List.of())); assertThat(jmx.jmxSecret(null), is(nullValue())); @@ -127,7 +127,7 @@ public void testEnabledJmxWithAuthentication() { assertThat(jmx.networkPolicyIngresRules().size(), is(1)); assertThat(jmx.networkPolicyIngresRules().get(0).getPorts().size(), is(1)); - assertThat(jmx.networkPolicyIngresRules().get(0).getPorts().get(0).getPort().getStrVal(), is("jmx")); + assertThat(jmx.networkPolicyIngresRules().get(0).getPorts().get(0).getPort().getIntVal(), is(9999)); assertThat(jmx.networkPolicyIngresRules().get(0).getFrom(), is(List.of())); Secret newSecret = jmx.jmxSecret(null); From bbf76840c0cc7714ae9559e637455fb76f688b31 Mon Sep 17 00:00:00 2001 From: AvivGuiser Date: Fri, 20 Jun 2025 20:25:26 +0300 Subject: [PATCH 08/11] add test to test creation of not named target port Signed-off-by: AvivGuiser --- .../operator/cluster/model/ServiceUtilsTest.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/ServiceUtilsTest.java b/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/ServiceUtilsTest.java index ecabb622ab9..0e5800c7fec 100644 --- a/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/ServiceUtilsTest.java +++ b/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/ServiceUtilsTest.java @@ -53,7 +53,7 @@ public class ServiceUtilsTest { .build(); @ParallelTest - public void testCreateServicePort() { + public void testCreateServicePortName() { ServicePort port = ServiceUtils.createServicePort(PORT_NAME, 1234, 5678, PORT_NAME, "HTTP"); assertThat(port.getName(), is(PORT_NAME)); @@ -63,6 +63,17 @@ public void testCreateServicePort() { assertThat(port.getProtocol(), is("HTTP")); } + @ParallelTest + public void testCreateServicePortNumber() { + ServicePort port = ServiceUtils.createServicePort(PORT_NAME, 1234, 5678, null, "HTTP"); + + assertThat(port.getName(), is(PORT_NAME)); + assertThat(port.getPort(), is(1234)); + assertThat(port.getTargetPort().getIntVal(), is(5678)); + assertThat(port.getNodePort(), is(nullValue())); + assertThat(port.getProtocol(), is("HTTP")); + } + @ParallelTest public void testCreateServiceWithNodePort() { ServicePort port = ServiceUtils.createServicePort(PORT_NAME, 1234, 5678, PORT_NAME, 30000, "HTTP"); From 4d4b13da42e29746672681a7c9eaed8a9da942b9 Mon Sep 17 00:00:00 2001 From: AvivGuiser Date: Thu, 26 Jun 2025 23:23:58 +0300 Subject: [PATCH 09/11] address CR comments, remove the usage of int target port in serviceUtils Signed-off-by: AvivGuiser --- .../strimzi/operator/cluster/model/ServiceUtils.java | 2 +- .../operator/cluster/model/ServiceUtilsTest.java | 11 ----------- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/ServiceUtils.java b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/ServiceUtils.java index 9ab506280cb..2eb83d02b6c 100644 --- a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/ServiceUtils.java +++ b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/ServiceUtils.java @@ -247,7 +247,7 @@ public static ServicePort createServicePort(String name, int port, int targetPor .withName(name) .withProtocol(protocol) .withPort(port) - .withNewTargetPort(Objects.requireNonNullElse(targetPortName, targetPort)) + .withNewTargetPort(targetPortName) .withNodePort(nodePort) .build(); } diff --git a/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/ServiceUtilsTest.java b/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/ServiceUtilsTest.java index 0e5800c7fec..49bc539dba2 100644 --- a/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/ServiceUtilsTest.java +++ b/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/ServiceUtilsTest.java @@ -63,17 +63,6 @@ public void testCreateServicePortName() { assertThat(port.getProtocol(), is("HTTP")); } - @ParallelTest - public void testCreateServicePortNumber() { - ServicePort port = ServiceUtils.createServicePort(PORT_NAME, 1234, 5678, null, "HTTP"); - - assertThat(port.getName(), is(PORT_NAME)); - assertThat(port.getPort(), is(1234)); - assertThat(port.getTargetPort().getIntVal(), is(5678)); - assertThat(port.getNodePort(), is(nullValue())); - assertThat(port.getProtocol(), is("HTTP")); - } - @ParallelTest public void testCreateServiceWithNodePort() { ServicePort port = ServiceUtils.createServicePort(PORT_NAME, 1234, 5678, PORT_NAME, 30000, "HTTP"); From 3162a5f9ce98656d8eaccdb8b4395541d654a67f Mon Sep 17 00:00:00 2001 From: AvivGuiser Date: Thu, 26 Jun 2025 23:32:10 +0300 Subject: [PATCH 10/11] address CR comments, remove the usage of int target port in serviceUtils Signed-off-by: AvivGuiser --- .../io/strimzi/operator/cluster/model/ServiceUtils.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/ServiceUtils.java b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/ServiceUtils.java index 2eb83d02b6c..69c7ee980e6 100644 --- a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/ServiceUtils.java +++ b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/ServiceUtils.java @@ -18,7 +18,6 @@ import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.stream.Collectors; /** @@ -227,7 +226,7 @@ private static List ipFamilies(InternalServiceTemplate template) { * @return Created port */ public static ServicePort createServicePort(String name, int port, int targetPort, String targetPortName, String protocol) { - return createServicePort(name, port, targetPort, targetPortName, null, protocol); + return createServicePort(name, port, targetPortName, null, protocol); } /** @@ -235,14 +234,13 @@ public static ServicePort createServicePort(String name, int port, int targetPor * * @param name Name of the port * @param port The port on the service which can be accessed by clients - * @param targetPort The port on the container / Pod where the connections will be routed * @param targetPortName the name of the target port on the container / Pod where the connections will be routed * @param nodePort The desired node port number * @param protocol Protocol used by this port * * @return Created port */ - public static ServicePort createServicePort(String name, int port, int targetPort, String targetPortName, Integer nodePort, String protocol) { + public static ServicePort createServicePort(String name, int port, String targetPortName, Integer nodePort, String protocol) { return new ServicePortBuilder() .withName(name) .withProtocol(protocol) From 4c3b6e149e40b209eea684da10ccb85b227e26a9 Mon Sep 17 00:00:00 2001 From: AvivGuiser Date: Thu, 26 Jun 2025 23:51:42 +0300 Subject: [PATCH 11/11] address CR comments, remove the usage of int target port in serviceUtils Signed-off-by: AvivGuiser --- .../operator/cluster/model/CruiseControl.java | 2 +- .../operator/cluster/model/KafkaBridgeCluster.java | 2 +- .../operator/cluster/model/KafkaCluster.java | 14 ++++++-------- .../cluster/model/KafkaConnectCluster.java | 4 ++-- .../operator/cluster/model/ServiceUtils.java | 3 +-- .../operator/cluster/model/jmx/JmxModel.java | 2 +- .../operator/cluster/model/ServiceUtilsTest.java | 6 +++--- 7 files changed, 15 insertions(+), 18 deletions(-) diff --git a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/CruiseControl.java b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/CruiseControl.java index 58e8b3d0f58..21d2179bdde 100644 --- a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/CruiseControl.java +++ b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/CruiseControl.java @@ -303,7 +303,7 @@ public Service generateService() { labels, ownerReference, templateService, - List.of(ServiceUtils.createServicePort(REST_API_PORT_NAME, REST_API_PORT, REST_API_PORT, REST_API_PORT_NAME, "TCP")) + List.of(ServiceUtils.createServicePort(REST_API_PORT_NAME, REST_API_PORT, REST_API_PORT_NAME, "TCP")) ); } diff --git a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/KafkaBridgeCluster.java b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/KafkaBridgeCluster.java index 9f053687907..4417b51f3ee 100644 --- a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/KafkaBridgeCluster.java +++ b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/KafkaBridgeCluster.java @@ -234,7 +234,7 @@ public Service generateService() { labels, ownerReference, templateService, - List.of(ServiceUtils.createServicePort(REST_API_PORT_NAME, port, port, REST_API_PORT_NAME, "TCP")), + List.of(ServiceUtils.createServicePort(REST_API_PORT_NAME, port, REST_API_PORT_NAME, "TCP")), labels.strimziSelectorLabels(), ModelUtils.getCustomLabelsOrAnnotations(CO_ENV_VAR_CUSTOM_SERVICE_LABELS), Util.mergeLabelsOrAnnotations(getDiscoveryAnnotation(port), ModelUtils.getCustomLabelsOrAnnotations(CO_ENV_VAR_CUSTOM_SERVICE_ANNOTATIONS)) diff --git a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/KafkaCluster.java b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/KafkaCluster.java index 187a4b6be4e..032060453be 100644 --- a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/KafkaCluster.java +++ b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/KafkaCluster.java @@ -650,10 +650,10 @@ private List getServicePorts() { List internalListeners = ListenersUtils.internalListeners(listeners); List ports = new ArrayList<>(internalListeners.size() + 1); - ports.add(ServiceUtils.createServicePort(REPLICATION_PORT_NAME, REPLICATION_PORT, REPLICATION_PORT, REPLICATION_PORT_NAME, "TCP")); + ports.add(ServiceUtils.createServicePort(REPLICATION_PORT_NAME, REPLICATION_PORT, REPLICATION_PORT_NAME, "TCP")); for (GenericKafkaListener listener : internalListeners) { - ports.add(ServiceUtils.createServicePort(ListenersUtils.backwardsCompatiblePortName(listener), listener.getPort(), listener.getPort(), ListenersUtils.backwardsCompatiblePortName(listener), "TCP")); + ports.add(ServiceUtils.createServicePort(ListenersUtils.backwardsCompatiblePortName(listener), listener.getPort(), ListenersUtils.backwardsCompatiblePortName(listener), "TCP")); } return ports; @@ -669,12 +669,12 @@ private List getHeadlessServicePorts() { List internalListeners = ListenersUtils.internalListeners(listeners); List ports = new ArrayList<>(internalListeners.size() + 3); - ports.add(ServiceUtils.createServicePort(CONTROLPLANE_PORT_NAME, CONTROLPLANE_PORT, CONTROLPLANE_PORT, CONTROLPLANE_PORT_NAME, "TCP")); - ports.add(ServiceUtils.createServicePort(REPLICATION_PORT_NAME, REPLICATION_PORT, REPLICATION_PORT, REPLICATION_PORT_NAME, "TCP")); - ports.add(ServiceUtils.createServicePort(KAFKA_AGENT_PORT_NAME, KAFKA_AGENT_PORT, KAFKA_AGENT_PORT, KAFKA_AGENT_PORT_NAME, "TCP")); + ports.add(ServiceUtils.createServicePort(CONTROLPLANE_PORT_NAME, CONTROLPLANE_PORT, CONTROLPLANE_PORT_NAME, "TCP")); + ports.add(ServiceUtils.createServicePort(REPLICATION_PORT_NAME, REPLICATION_PORT, REPLICATION_PORT_NAME, "TCP")); + ports.add(ServiceUtils.createServicePort(KAFKA_AGENT_PORT_NAME, KAFKA_AGENT_PORT, KAFKA_AGENT_PORT_NAME, "TCP")); for (GenericKafkaListener listener : internalListeners) { - ports.add(ServiceUtils.createServicePort(ListenersUtils.backwardsCompatiblePortName(listener), listener.getPort(), listener.getPort(), ListenersUtils.backwardsCompatiblePortName(listener), "TCP")); + ports.add(ServiceUtils.createServicePort(ListenersUtils.backwardsCompatiblePortName(listener), listener.getPort(), ListenersUtils.backwardsCompatiblePortName(listener), "TCP")); } ports.addAll(jmx.servicePorts()); @@ -746,7 +746,6 @@ public List generateExternalBootstrapServices() { List ports = Collections.singletonList( ServiceUtils.createServicePort(ListenersUtils.backwardsCompatiblePortName(listener), - listener.getPort(), listener.getPort(), ListenersUtils.backwardsCompatiblePortName(listener), ListenersUtils.bootstrapNodePort(listener), @@ -839,7 +838,6 @@ public List generatePerPodServices() { ServiceUtils.createServicePort( ListenersUtils.backwardsCompatiblePortName(listener), listener.getPort(), - listener.getPort(), ListenersUtils.backwardsCompatiblePortName(listener), ListenersUtils.brokerNodePort(listener, node.nodeId()), "TCP") diff --git a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/KafkaConnectCluster.java b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/KafkaConnectCluster.java index 28ea46a0aa0..336cc7482c3 100644 --- a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/KafkaConnectCluster.java +++ b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/KafkaConnectCluster.java @@ -342,7 +342,7 @@ public String getServiceName() { */ public Service generateService() { List ports = new ArrayList<>(1); - ports.add(ServiceUtils.createServicePort(REST_API_PORT_NAME, REST_API_PORT, REST_API_PORT, REST_API_PORT_NAME, "TCP")); + ports.add(ServiceUtils.createServicePort(REST_API_PORT_NAME, REST_API_PORT, REST_API_PORT_NAME, "TCP")); ports.addAll(jmx.servicePorts()); @@ -362,7 +362,7 @@ public Service generateService() { * @return The generated Service */ public Service generateHeadlessService() { - List ports = List.of(ServiceUtils.createServicePort(REST_API_PORT_NAME, REST_API_PORT, REST_API_PORT, REST_API_PORT_NAME, "TCP")); + List ports = List.of(ServiceUtils.createServicePort(REST_API_PORT_NAME, REST_API_PORT, REST_API_PORT_NAME, "TCP")); return ServiceUtils.createHeadlessService( componentName, diff --git a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/ServiceUtils.java b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/ServiceUtils.java index 69c7ee980e6..7de967da93b 100644 --- a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/ServiceUtils.java +++ b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/ServiceUtils.java @@ -219,13 +219,12 @@ private static List ipFamilies(InternalServiceTemplate template) { * * @param name Name of the port * @param port The port on the service which can be accessed by clients - * @param targetPort The port on the container / Pod where the connections will be routed * @param targetPortName the name of the target port on the container / Pod where the connections will be routed * @param protocol Protocol used by this port * * @return Created port */ - public static ServicePort createServicePort(String name, int port, int targetPort, String targetPortName, String protocol) { + public static ServicePort createServicePort(String name, int port, String targetPortName, String protocol) { return createServicePort(name, port, targetPortName, null, protocol); } diff --git a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/jmx/JmxModel.java b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/jmx/JmxModel.java index f399fe4b56b..cb0e25570a3 100644 --- a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/jmx/JmxModel.java +++ b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/jmx/JmxModel.java @@ -115,7 +115,7 @@ public String secretName() { */ public List servicePorts() { if (isEnabled) { - return List.of(ServiceUtils.createServicePort(JMX_PORT_NAME, JMX_PORT, JMX_PORT, JMX_PORT_NAME, "TCP")); + return List.of(ServiceUtils.createServicePort(JMX_PORT_NAME, JMX_PORT, JMX_PORT_NAME, "TCP")); } else { return List.of(); } diff --git a/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/ServiceUtilsTest.java b/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/ServiceUtilsTest.java index 49bc539dba2..924a957a0cb 100644 --- a/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/ServiceUtilsTest.java +++ b/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/ServiceUtilsTest.java @@ -42,7 +42,7 @@ public class ServiceUtilsTest { .withStrimziComponentType("my-component-type") .withAdditionalLabels(Map.of("label-1", "value-1", "label-2", "value-2")); private static final String PORT_NAME = "my-port"; - private static final ServicePort PORT = ServiceUtils.createServicePort(PORT_NAME, 1234, 5678, PORT_NAME, "HTTP"); + private static final ServicePort PORT = ServiceUtils.createServicePort(PORT_NAME, 1234, PORT_NAME, "HTTP"); private static final InternalServiceTemplate TEMPLATE = new InternalServiceTemplateBuilder() .withNewMetadata() .withLabels(Map.of("label-3", "value-3", "label-4", "value-4")) @@ -54,7 +54,7 @@ public class ServiceUtilsTest { @ParallelTest public void testCreateServicePortName() { - ServicePort port = ServiceUtils.createServicePort(PORT_NAME, 1234, 5678, PORT_NAME, "HTTP"); + ServicePort port = ServiceUtils.createServicePort(PORT_NAME, 1234, PORT_NAME, "HTTP"); assertThat(port.getName(), is(PORT_NAME)); assertThat(port.getPort(), is(1234)); @@ -65,7 +65,7 @@ public void testCreateServicePortName() { @ParallelTest public void testCreateServiceWithNodePort() { - ServicePort port = ServiceUtils.createServicePort(PORT_NAME, 1234, 5678, PORT_NAME, 30000, "HTTP"); + ServicePort port = ServiceUtils.createServicePort(PORT_NAME, 1234, PORT_NAME, 30000, "HTTP"); assertThat(port.getName(), is(PORT_NAME)); assertThat(port.getPort(), is(1234));