From fa227cedd5f192334b532b7c55c05ba31ef3e7e9 Mon Sep 17 00:00:00 2001 From: Jakub Scholz Date: Sun, 28 Jul 2024 15:32:19 +0200 Subject: [PATCH] Remove `getPodName()` method from `AbstractModel` (#10397) Signed-off-by: Jakub Scholz --- .../strimzi/operator/cluster/model/AbstractModel.java | 10 ---------- .../operator/cluster/model/KafkaConnectCluster.java | 2 +- .../operator/cluster/model/ZookeeperCluster.java | 6 +++--- .../operator/assembly/KafkaConnectMigration.java | 2 +- .../operator/cluster/model/KafkaClusterPodSetTest.java | 2 +- .../operator/cluster/model/KafkaClusterTest.java | 8 -------- .../operator/cluster/model/ZookeeperClusterTest.java | 7 ------- 7 files changed, 6 insertions(+), 31 deletions(-) diff --git a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/AbstractModel.java b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/AbstractModel.java index 287e83196c5..9aa1dd8f5a6 100644 --- a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/AbstractModel.java +++ b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/AbstractModel.java @@ -150,16 +150,6 @@ public String getCluster() { return cluster; } - /** - * Gets the name of a given pod in a StrimziPodSet. - * - * @param podId The ID (ordinal) of the pod. - * @return The name of the pod with the given name. - */ - public String getPodName(Integer podId) { - return componentName + "-" + podId; - } - /** * @param cluster The cluster name * @return The name of the Cluster CA certificate secret. 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 c207481cc3f..723bbc706e7 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 @@ -517,7 +517,7 @@ public StrimziPodSet generatePodSet(int replicas, labels.strimziSelectorLabels().withStrimziPodSetController(componentName), podId -> WorkloadUtils.createStatefulPod( reconciliation, - getPodName(podId), + componentName + "-" + podId, namespace, labels, componentName, diff --git a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/ZookeeperCluster.java b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/ZookeeperCluster.java index 637d67bc0bb..17e1852d65f 100644 --- a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/ZookeeperCluster.java +++ b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/ZookeeperCluster.java @@ -413,7 +413,7 @@ public StrimziPodSet generatePodSet(int replicas, labels.strimziSelectorLabels(), podNum -> WorkloadUtils.createStatefulPod( reconciliation, - getPodName(podNum), + KafkaResources.zookeeperPodName(cluster, podNum), namespace, labels, componentName, @@ -425,7 +425,7 @@ public StrimziPodSet generatePodSet(int replicas, templatePod != null ? templatePod.getAffinity() : null, null, List.of(createContainer(imagePullPolicy)), - getPodSetVolumes(getPodName(podNum), isOpenShift), + getPodSetVolumes(KafkaResources.zookeeperPodName(cluster, podNum), isOpenShift), imagePullSecrets, securityProvider.zooKeeperPodSecurityContext(new PodSecurityProviderContextImpl(storage, templatePod)) ) @@ -636,7 +636,7 @@ public Set nodes() { Set nodes = new LinkedHashSet<>(); for (int i = 0; i < replicas; i++) { - nodes.add(new NodeRef(getPodName(i), i, null, false, false)); + nodes.add(new NodeRef(KafkaResources.zookeeperPodName(cluster, i), i, null, false, false)); } return nodes; diff --git a/cluster-operator/src/main/java/io/strimzi/operator/cluster/operator/assembly/KafkaConnectMigration.java b/cluster-operator/src/main/java/io/strimzi/operator/cluster/operator/assembly/KafkaConnectMigration.java index f66c4748162..5006adada0f 100644 --- a/cluster-operator/src/main/java/io/strimzi/operator/cluster/operator/assembly/KafkaConnectMigration.java +++ b/cluster-operator/src/main/java/io/strimzi/operator/cluster/operator/assembly/KafkaConnectMigration.java @@ -199,6 +199,6 @@ private Future scaleDownDeployment(int replicas) { private Future scaleUpStrimziPodSet(int replicas) { LOGGER.infoCr(reconciliation, "Scaling up StrimziPodSet {}", connect.getComponentName()); return podSetOperator.reconcile(reconciliation, reconciliation.namespace(), connect.getComponentName(), connect.generatePodSet(replicas, controllerAnnotations, podAnnotations, isOpenshift, imagePullPolicy, imagePullSecrets, customContainerImage)) - .compose(i -> podOperator.readiness(reconciliation, reconciliation.namespace(), connect.getPodName(replicas - 1), 1_000, operationTimeoutMs)); + .compose(i -> podOperator.readiness(reconciliation, reconciliation.namespace(), connect.getComponentName() + "-" + (replicas - 1), 1_000, operationTimeoutMs)); } } \ No newline at end of file diff --git a/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/KafkaClusterPodSetTest.java b/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/KafkaClusterPodSetTest.java index 01e731db77d..1f7ae50efb3 100644 --- a/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/KafkaClusterPodSetTest.java +++ b/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/KafkaClusterPodSetTest.java @@ -107,7 +107,7 @@ public class KafkaClusterPodSetTest { @ParallelTest public void testPodSet() { - StrimziPodSet ps = KC.generatePodSets(true, null, null, brokerId -> Map.of("test-anno", KC.getPodName(brokerId))).get(0); + StrimziPodSet ps = KC.generatePodSets(true, null, null, brokerId -> Map.of("test-anno", KafkaResources.kafkaPodName(CLUSTER, brokerId))).get(0); assertThat(ps.getMetadata().getName(), is(KafkaResources.kafkaComponentName(CLUSTER))); assertThat(ps.getMetadata().getLabels().entrySet().containsAll(KC.labels.withAdditionalLabels(null).toMap().entrySet()), is(true)); diff --git a/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/KafkaClusterTest.java b/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/KafkaClusterTest.java index 36a49fd1324..5e0ce40b4b0 100644 --- a/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/KafkaClusterTest.java +++ b/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/KafkaClusterTest.java @@ -751,14 +751,6 @@ public void testPerBrokerConfiguration() { assertThat(config, CoreMatchers.containsString("advertised.listeners=CONTROLPLANE-9090://foo-kafka-1.foo-kafka-brokers.test.svc:9090,REPLICATION-9091://foo-kafka-1.foo-kafka-brokers.test.svc:9091,PLAIN-9092://broker-1:9092,TLS-9093://broker-1:10001\n")); } - @ParallelTest - public void testPodNames() { - - for (int i = 0; i < REPLICAS; i++) { - assertThat(KC.getPodName(i), is(KafkaResources.kafkaComponentName(CLUSTER) + "-" + i)); - } - } - @ParallelTest public void testPvcNames() { Kafka kafkaAssembly = new KafkaBuilder(KAFKA) diff --git a/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/ZookeeperClusterTest.java b/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/ZookeeperClusterTest.java index 0625e3d34ed..cd40a4bc29f 100644 --- a/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/ZookeeperClusterTest.java +++ b/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/ZookeeperClusterTest.java @@ -371,13 +371,6 @@ public void testInvalidVersion() { }); } - @ParallelTest - public void testPodNames() { - for (int i = 0; i < REPLICAS; i++) { - assertThat(ZC.getPodName(i), is(KafkaResources.zookeeperPodName(CLUSTER, i))); - } - } - @ParallelTest public void testPvcNames() { Kafka ka = new KafkaBuilder(KAFKA)