fix(msk): populate currentBrokerSoftwareInfo in cluster describe response (#1238)

* fix(msk): populate currentBrokerSoftwareInfo in cluster describe response

* fix(msk): map provisioned.kafkaVersion in CreateClusterV2

Addresses review feedback: V2 create requests carry kafkaVersion under
provisioned, not at the top level, so it was always falling back to the
default. Adds integration test coverage for the V1 path, V2 with
provisioned.kafkaVersion, and V2 default fallback.

* fix(msk): update RedpandaManagerTest for MskCluster 3-arg constructor
This commit is contained in:
Fábio Silva authored and GitHub committed 2026-06-12 17:45:09 -05:00
1 parent c476aca00b
commit ce12e0284b
7 files changed
+130 -5

No files matched your search

@@ -23,16 +23,20 @@ public class MskController {
@Path("/v1/clusters")
public Response createCluster(Map<String, Object> request) {
String clusterName = (String) request.get("clusterName");
MskCluster cluster = mskService.createCluster(clusterName);
String kafkaVersion = (String) request.get("kafkaVersion");
MskCluster cluster = mskService.createCluster(clusterName, kafkaVersion);
return Response.ok(Map.of("clusterArn", cluster.getClusterArn(), "clusterName", cluster.getClusterName(), "state", cluster.getState())).build();
}
@POST
@Path("/api/v2/clusters")
@SuppressWarnings("unchecked")
public Response createClusterV2(Map<String, Object> request) {
// Simple mapping to V1 for now
String clusterName = (String) request.get("clusterName");
MskCluster cluster = mskService.createCluster(clusterName);
Map<String, Object> provisioned = (Map<String, Object>) request.get("provisioned");
String kafkaVersion = provisioned != null ? (String) provisioned.get("kafkaVersion") : null;
MskCluster cluster = mskService.createCluster(clusterName, kafkaVersion);
return Response.ok(Map.of("clusterArn", cluster.getClusterArn(), "clusterName", cluster.getClusterName(), "state", cluster.getState())).build();
}
@@ -29,6 +29,7 @@ import java.util.concurrent.TimeUnit;
public class MskService {
private static final Logger LOG = Logger.getLogger(MskService.class);
private static final String DEFAULT_KAFKA_VERSION = "3.6.0";
private final StorageBackend<String, MskCluster> storage;
private final EmulatorConfig config;
private final RegionResolver regionResolver;
@@ -60,6 +61,10 @@ public class MskService {
}
public MskCluster createCluster(String clusterName) {
return createCluster(clusterName, DEFAULT_KAFKA_VERSION);
}
public MskCluster createCluster(String clusterName, String kafkaVersion) {
if (storage.scan(k -> true).stream().anyMatch(c -> c.getClusterName().equals(clusterName))) {
throw new AwsException("ConflictException", "Cluster already exists: " + clusterName, 409);
}
@@ -67,7 +72,8 @@ public class MskService {
String accountId = regionResolver.getAccountId();
String clusterArn = AwsArnUtils.Arn.of("kafka", config.defaultRegion(), accountId, "cluster/" + clusterName + "/" + java.util.UUID.randomUUID()).toString();
MskCluster cluster = new MskCluster(clusterArn, clusterName);
String resolvedKafkaVersion = (kafkaVersion == null || kafkaVersion.isBlank()) ? DEFAULT_KAFKA_VERSION : kafkaVersion;
MskCluster cluster = new MskCluster(clusterArn, clusterName, resolvedKafkaVersion);
cluster.setAccountId(accountId);
cluster.setVolumeId(String.format("%06x", new SecureRandom().nextInt(0xFFFFFF)));
@@ -0,0 +1,20 @@
package io.github.hectorvent.floci.services.msk.model;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.quarkus.runtime.annotations.RegisterForReflection;
@RegisterForReflection
public class BrokerSoftwareInfo {
@JsonProperty("kafkaVersion")
private String kafkaVersion;
public BrokerSoftwareInfo() {}
public BrokerSoftwareInfo(String kafkaVersion) {
this.kafkaVersion = kafkaVersion;
}
public String getKafkaVersion() { return kafkaVersion; }
public void setKafkaVersion(String kafkaVersion) { this.kafkaVersion = kafkaVersion; }
}
@@ -33,6 +33,9 @@ public class MskCluster {
@JsonProperty("zookeeperConnectString")
private String zookeeperConnectString;
@JsonProperty("currentBrokerSoftwareInfo")
private BrokerSoftwareInfo currentBrokerSoftwareInfo;
// Internal field, not directly in AWS response but needed for GetBootstrapBrokers
private String bootstrapBrokers;
@@ -47,7 +50,7 @@ public class MskCluster {
public MskCluster() {}
public MskCluster(String clusterArn, String clusterName) {
public MskCluster(String clusterArn, String clusterName, String kafkaVersion) {
this.clusterArn = clusterArn;
this.clusterName = clusterName;
this.state = ClusterState.CREATING;
@@ -55,6 +58,7 @@ public class MskCluster {
this.currentVersion = "K3V6I1"; // Example version
this.numberOfBrokerNodes = 1;
this.zookeeperConnectString = "localhost:2181"; // Mock ZK
this.currentBrokerSoftwareInfo = new BrokerSoftwareInfo(kafkaVersion);
}
public String getClusterArn() { return clusterArn; }
@@ -81,6 +85,9 @@ public class MskCluster {
public String getZookeeperConnectString() { return zookeeperConnectString; }
public void setZookeeperConnectString(String zookeeperConnectString) { this.zookeeperConnectString = zookeeperConnectString; }
public BrokerSoftwareInfo getCurrentBrokerSoftwareInfo() { return currentBrokerSoftwareInfo; }
public void setCurrentBrokerSoftwareInfo(BrokerSoftwareInfo currentBrokerSoftwareInfo) { this.currentBrokerSoftwareInfo = currentBrokerSoftwareInfo; }
public String getBootstrapBrokers() { return bootstrapBrokers; }
public void setBootstrapBrokers(String bootstrapBrokers) { this.bootstrapBrokers = bootstrapBrokers; }