Skip to content

Commit

Permalink
Fix naming of bootstrap service for oddly named listener (#11016)
Browse files Browse the repository at this point in the history
Signed-off-by: Jakub Scholz <[email protected]>
  • Loading branch information
scholzj authored Jan 8, 2025
1 parent 5efc0d4 commit 962f663
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,7 @@ public static String backwardsCompatiblePortName(GenericKafkaListener listener)
* @return Name of the bootstrap service
*/
public static String backwardsCompatibleBootstrapServiceName(String clusterName, GenericKafkaListener listener) {
if (listener.getPort() == 9092 && "plain".equals(listener.getName()) && KafkaListenerType.INTERNAL == listener.getType()) {
return clusterName + "-kafka-bootstrap";
} else if (listener.getPort() == 9093 && "tls".equals(listener.getName()) && KafkaListenerType.INTERNAL == listener.getType()) {
return clusterName + "-kafka-bootstrap";
} else if (listener.getPort() == 9094 && "external".equals(listener.getName())) {
return clusterName + "-kafka-external-bootstrap";
} else if (KafkaListenerType.INTERNAL == listener.getType()) {
if (KafkaListenerType.INTERNAL == listener.getType()) {
return clusterName + "-kafka-bootstrap";
} else {
return clusterName + "-kafka-" + listener.getName() + "-bootstrap";
Expand All @@ -280,14 +274,10 @@ public static String backwardsCompatibleBootstrapServiceName(String clusterName,
* @return Name of the bootstrap service
*/
public static String backwardsCompatibleBootstrapRouteOrIngressName(String clusterName, GenericKafkaListener listener) {
if (listener.getPort() == 9092 && "plain".equals(listener.getName()) && KafkaListenerType.INTERNAL == listener.getType()) {
throw new UnsupportedOperationException("Bootstrap routes or ingresses are not used for internal listeners");
} else if (listener.getPort() == 9093 && "tls".equals(listener.getName()) && KafkaListenerType.INTERNAL == listener.getType()) {
if (KafkaListenerType.INTERNAL == listener.getType()) {
throw new UnsupportedOperationException("Bootstrap routes or ingresses are not used for internal listeners");
} else if (listener.getPort() == 9094 && "external".equals(listener.getName())) {
return clusterName + "-kafka-bootstrap";
} else if (KafkaListenerType.INTERNAL == listener.getType()) {
throw new UnsupportedOperationException("Bootstrap routes or ingresses are not used for internal listeners");
} else {
return clusterName + "-kafka-" + listener.getName() + "-bootstrap";
}
Expand All @@ -306,14 +296,10 @@ public static String backwardsCompatibleBootstrapRouteOrIngressName(String clust
* @return Name of the bootstrap service
*/
public static String backwardsCompatiblePerBrokerServiceName(String baseName, int pod, GenericKafkaListener listener) {
if (listener.getPort() == 9092 && "plain".equals(listener.getName()) && KafkaListenerType.INTERNAL == listener.getType()) {
throw new UnsupportedOperationException("Per-broker services are not used for internal listener");
} else if (listener.getPort() == 9093 && "tls".equals(listener.getName()) && KafkaListenerType.INTERNAL == listener.getType()) {
if (KafkaListenerType.INTERNAL == listener.getType()) {
throw new UnsupportedOperationException("Per-broker services are not used for internal listener");
} else if (listener.getPort() == 9094 && "external".equals(listener.getName())) {
return baseName + "-" + pod;
} else if (KafkaListenerType.INTERNAL == listener.getType()) {
throw new UnsupportedOperationException("Per-broker services are not used for internal listener");
} else {
return baseName + "-" + listener.getName() + "-" + pod;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,15 @@ public void testBackwardsCompatibleServiceNames() {
assertThat(ListenersUtils.backwardsCompatibleBootstrapServiceName(clusterName, newTls), is(clusterName + "-kafka-bootstrap"));
assertThat(ListenersUtils.backwardsCompatibleBootstrapServiceName(clusterName, newLoadBalancer), is(clusterName + "-kafka-lb1-bootstrap"));
assertThat(ListenersUtils.backwardsCompatibleBootstrapServiceName(clusterName, newNodePort), is(clusterName + "-kafka-np1-bootstrap"));

// Test internal listener with old external naming -> should have a regular internal service name
GenericKafkaListener internalWithOldExternalNaming = new GenericKafkaListenerBuilder()
.withName("external")
.withPort(9094)
.withType(KafkaListenerType.INTERNAL)
.withTls(true)
.build();
assertThat(ListenersUtils.backwardsCompatibleBootstrapServiceName(clusterName, internalWithOldExternalNaming), is(clusterName + "-kafka-bootstrap"));
}

@ParallelTest
Expand Down

0 comments on commit 962f663

Please sign in to comment.