Skip to content

Refactor ListenerConfig and ListenerRole into Listener class with constants#227

Open
guancioul wants to merge 3 commits into
strimzi:mainfrom
guancioul:extract-listener-config-212
Open

Refactor ListenerConfig and ListenerRole into Listener class with constants#227
guancioul wants to merge 3 commits into
strimzi:mainfrom
guancioul:extract-listener-config-212

Conversation

@guancioul

Copy link
Copy Markdown
Contributor

Close #212,

Summary

  • Extract the ListenerConfig inner class and ListenerRole enum from StrimziKafkaContainer into a new top-level Listener class (Listener.java), reducing the coupling between listener configuration and the container class
  • Define listener name constants (PLAINTEXT, CONTROLLER, CONTROLLER_EXTERNAL, INTER_BROKER_PREFIX) in Listener to eliminate magic strings scattered across StrimziKafkaContainer
  • Update all call sites in StrimziKafkaContainer and StrimziKafkaContainerTest to use the new Listener class and its constants

@guancioul guancioul force-pushed the extract-listener-config-212 branch from 9d7f39e to dacf587 Compare May 27, 2026 10:16
@see-quick see-quick added this to the 0.116.0 milestone May 27, 2026

@see-quick see-quick left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this change @guancioul, please also update all test suites which uses exact strings of the listeners and change it to Listener.PLAINTEXT ... (i.e.,StrimziKafkaContainerMockTest, StrimziKafkaClusterTest, StrimziKafkaContainerIT).

@guancioul

Copy link
Copy Markdown
Contributor Author

Thanks for the review. I have updated some missing references in those test suites in fb2948d. One thing I'd like to check — there are also usages where the listener name is embedded in a full URL string, for example:

assertThat(props.getProperty("advertised.listeners"), is("CONTROLLER://broker-1:9094"));
assertThat(networkBootstrapControllers, is("CONTROLLER://broker-1:9094"));

Should these also be updated to use the constants (e.g. Listener.CONTROLLER + "://broker-1:9094")? Personally I feel the current form is more readable since the full expected value is visible at a glance, but happy to update if you prefer consistency.

@see-quick

Copy link
Copy Markdown
Member

Should these also be updated to use the constants (e.g. Listener.CONTROLLER + "://broker-1:9094")? Personally I feel the current form is more readable since the full expected value is visible at a glance, but happy to update if you prefer consistency.

While I partially agree, I believe it would be better to define listener names from a single source of truth. This would help avoid making the same change in multiple places. If the listener name needs to be updated in the future, it could be done in one location, and all related tests would be updated automatically through refactoring.

@guancioul

Copy link
Copy Markdown
Contributor Author

Agree, I change the code to let listener names become a single source of truth. I also added SASL_PLAINTEXT and SASL_SSL constants to the Listener class, as those were also scattered as magic strings accross StrimziKafkaContainer and StrimziKafkaCluster.

@see-quick see-quick modified the milestones: 0.116.0, 0.117.0 Jun 9, 2026
@see-quick

Copy link
Copy Markdown
Member

Would you mind rebasing after this change #227?

…stener name constants

Signed-off-by: guancioul <guancioul@gmail.com>
Signed-off-by: guancioul <guancioul@gmail.com>
Signed-off-by: guancioul <guancioul@gmail.com>
@guancioul guancioul force-pushed the extract-listener-config-212 branch from 00ecdf0 to 68cc255 Compare June 17, 2026 14:32
@guancioul

Copy link
Copy Markdown
Contributor Author

Sure, I have rebased this branch!

@see-quick

Copy link
Copy Markdown
Member

Sure, I have rebased this branch!

Thanks, I will have a look once I find some time.

@see-quick see-quick left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks 👍

@see-quick see-quick requested a review from a team June 21, 2026 15:29
@see-quick

Copy link
Copy Markdown
Member

Please take a look on this @strimzi/maintainers .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extract ListenerConfig/ListenerRole into separate classes and define listener name constants

2 participants