-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Kraft post Confluent Platform 7.4.0 #7014
Changes from 7 commits
0e5fc6f
0288f10
d1ca523
4cbc82d
66ff671
14a3148
29731d7
ab8c1e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
import org.testcontainers.utility.ComparableVersion; | ||
import org.testcontainers.utility.DockerImageName; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
/** | ||
* This container wraps Confluent Kafka and Zookeeper (optionally) | ||
|
@@ -29,11 +29,13 @@ public class KafkaContainer extends GenericContainer<KafkaContainer> { | |
// https://docs.confluent.io/platform/7.0.0/release-notes/index.html#ak-raft-kraft | ||
private static final String MIN_KRAFT_TAG = "7.0.0"; | ||
|
||
public static final String DEFAULT_CLUSTER_ID = "4L6g3nShT-eMCtK--X86sw"; | ||
|
||
protected String externalZookeeperConnect = null; | ||
|
||
private boolean kraftEnabled = false; | ||
|
||
private String clusterId; | ||
private String clusterId = DEFAULT_CLUSTER_ID; | ||
|
||
/** | ||
* @deprecated use {@link KafkaContainer(DockerImageName)} instead | ||
|
@@ -115,7 +117,13 @@ private void verifyMinKraftVersion() { | |
} | ||
} | ||
|
||
private boolean isLessThanCP740() { | ||
String actualVersion = DockerImageName.parse(getDockerImageName()).getVersionPart(); | ||
return new ComparableVersion(actualVersion).isLessThan("7.4.0"); | ||
} | ||
|
||
public KafkaContainer withClusterId(String clusterId) { | ||
Objects.requireNonNull(clusterId, "clusterId cannot be null"); | ||
this.clusterId = clusterId; | ||
return self(); | ||
} | ||
|
@@ -136,6 +144,8 @@ protected void configure() { | |
} | ||
|
||
protected void configureKraft() { | ||
//CP 7.4.0 | ||
getEnvMap().computeIfAbsent("CLUSTER_ID", key -> clusterId); | ||
withEnv( | ||
"KAFKA_NODE_ID", | ||
getEnvMap().computeIfAbsent("KAFKA_NODE_ID", key -> getEnvMap().get("KAFKA_BROKER_ID")) | ||
|
@@ -186,24 +196,25 @@ protected void containerIsStarting(InspectContainerResponse containerInfo) { | |
brokerAdvertisedListener(containerInfo) | ||
); | ||
|
||
command += (kraftEnabled) ? commandKraft() : commandZookeeper(); | ||
if (kraftEnabled && isLessThanCP740()) { | ||
// Optimization: skip the checks | ||
command += "echo '' > /etc/confluent/docker/ensure \n"; | ||
command += commandKraft(); | ||
} | ||
|
||
if (!kraftEnabled) { | ||
// Optimization: skip the checks | ||
command += "echo '' > /etc/confluent/docker/ensure \n"; | ||
command += commandZookeeper(); | ||
} | ||
|
||
// Optimization: skip the checks | ||
command += "echo '' > /etc/confluent/docker/ensure \n"; | ||
// Run the original command | ||
command += "/etc/confluent/docker/run \n"; | ||
copyFileToContainer(Transferable.of(command, 0777), STARTER_SCRIPT); | ||
} | ||
|
||
protected String commandKraft() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this only called for < CP 7.4? If yes, it may be good to add a defense in depth and check that it is indeed isLessThanCP740 () There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it supposed to be invoked in Zk mode or when Kraft AND CP <7.4 Would like to add a test? TBH, I'm questioning the optimization gains of removing the checks @eddumelendez here are the checks the script is performing... IMHO, the gain does not worth the "complexity" of the code... but that's my 2cts... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agree, the module is already complex enough 😅 Let's rollback that change, please There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
String command = "sed -i '/KAFKA_ZOOKEEPER_CONNECT/d' /etc/confluent/docker/configure\n"; | ||
try { | ||
if (clusterId == null) { | ||
clusterId = execInContainer("kafka-storage", "random-uuid").getStdout().trim(); | ||
} | ||
} catch (IOException | InterruptedException e) { | ||
logger().error("Failed to execute `kafka-storage random-uuid`. Exception message: {}", e.getMessage()); | ||
} | ||
command += | ||
"echo 'kafka-storage format --ignore-formatted -t \"" + | ||
clusterId + | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason to move it? I guess there is preferences but I think it doesn't hurt 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, definitively Kraft is the preferred option from now on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds like this change did not get merged. 😢
@eddumelendez as said, Kraft would be the preferred option, would you mind to invert the order and put Kraft first?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's up to the user. That's why I said it doesn't hurt.