-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Add allocateLoadBalancerNodePorts configuration to listeners configuration #10792
Add allocateLoadBalancerNodePorts configuration to listeners configuration #10792
Conversation
Signed-off-by: Venkatesh Kannan <[email protected]>
858a79f
to
12b80ac
Compare
Credit: @pillai-ashwin Signed-off-by: Venkatesh Kannan <[email protected]>
Signed-off-by: Venkatesh Kannan <[email protected]>
7f56f0d
to
22a9685
Compare
Signed-off-by: Venkatesh Kannan <[email protected]>
Signed-off-by: Venkatesh Kannan <[email protected]>
9fd38e2
to
1d501b8
Compare
@@ -58,6 +58,7 @@ public class GenericKafkaListenerConfiguration implements UnknownPropertyPreserv | |||
private String hostTemplate; | |||
private String advertisedHostTemplate; | |||
private Map<String, Object> additionalProperties; | |||
private Boolean allocateLoadBalancerNodePorts = true; |
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.
If we don't leave this as null
, should it be boolean
instead? Or maybe you should keep it as Boolean
, have it default to null
and then in the code check if it is set which might be better approach.
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.
Thanks for the review. Yes I will keep it null and change the generate functions to check for null.
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.
Thanks for the PR. You will also need to write some unit tests for this before we can merge it. The ListenerUtils and ListenersValidators have their own, we should probably have it also in the KafkaCluster tests.
Signed-off-by: Venkatesh Kannan <[email protected]>
Signed-off-by: Venkatesh Kannan <[email protected]>
I have pushed some tests, but the tests in |
new GenericKafkaListenerBuilder() | ||
.withName("lb") | ||
.withPort(9094) | ||
.withType(KafkaListenerType.LOADBALANCER) | ||
.withNewConfiguration() | ||
.withAllocateLoadBalancerNodePorts(false) | ||
.endConfiguration() | ||
.build()) |
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 don't think you should add it here and have it in all tests. Add it only to the Kafka CR used in the unit test focusing on this.
@ParallelTest | ||
public void testGenerateExternalBootstrapServices() { | ||
List<Service> services = KC.generateExternalBootstrapServices(); | ||
|
||
assertThat(services, hasSize(1)); | ||
Service service = services.get(0); | ||
|
||
assertThat(service.getSpec().getAllocateLoadBalancerNodePorts(), is(false)); | ||
} | ||
|
||
@ParallelTest | ||
public void testGeneratePerPodServices() { | ||
List<Service> services = KC.generatePerPodServices(); | ||
|
||
assertThat(services, hasSize(5)); | ||
assertThat(services.stream() | ||
.filter(s -> !s.getSpec().getAllocateLoadBalancerNodePorts()) | ||
.collect(Collectors.toList()), | ||
hasSize(5)); | ||
} |
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 this works. Maybe you can have a single unit test to cover both and you should have the listener configured for this in this method and not in the static resource. Then it would not be needed to include it in all the other tests.
And in one of the generic tests for the services you should also check that the value is not set in other cases.
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 have moved this test to KafkaClusterListenerTest
like you suggested. It creates another KafkaCluster
instance instead of using the static one
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'm not sure if I suggested to add it to this class ... but it would make more sense in KafkaClusterListenersTest
.
assertThat(internalListeners.stream() | ||
.filter(l -> ListenersUtils.allocateLoadBalancerNodePorts(l) == null || | ||
ListenersUtils.allocateLoadBalancerNodePorts(l)) | ||
.collect(Collectors.toList()), | ||
hasSize(4)); | ||
assertThat(allListeners.stream() | ||
.filter(l -> ListenersUtils.allocateLoadBalancerNodePorts(l) == null || | ||
ListenersUtils.allocateLoadBalancerNodePorts(l)) | ||
.collect(Collectors.toList()), | ||
hasSize(13)); |
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.
To be honest, I have no idea what are these tests trying to do. I would just create 3 listeners here - one with the flag set to true, one with it set to false and one with it not set. And just call the method on them and assert the result.
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.
addressed this as well. Thanks
Signed-off-by: Venkatesh Kannan <[email protected]>
/azp run regression |
Azure Pipelines successfully started running 1 pipeline(s). |
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.
LGTM. Thanks.
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.
LGTM. Just one nit.
return listener.getConfiguration().getAllocateLoadBalancerNodePorts(); | ||
} else { | ||
return true; | ||
} |
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.
why not just ....
return listener.getConfiguration() != null ? listener.getConfiguration().getAllocateLoadBalancerNodePorts() : true;
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.
No particular reason. I just copied what the other methods were doing. I was going to return null, so the Utils method takes over with the null check. But one of the bug check CI pipelines caught it as a bug.
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 @ppatierno highlights what I missed ... it should probably return null
(not configured) and not true
. Whether it is in the longer code or shorter does not matter that much for me.
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.
Just ignored it in spotbugs. Hope that's alright
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.
Yeah, that is fine.
Signed-off-by: Venkatesh Kannan <[email protected]>
869ba8b
to
225bc90
Compare
Signed-off-by: Venkatesh Kannan <[email protected]>
/azp run regression |
Azure Pipelines successfully started running 1 pipeline(s). |
I started the regression tests and if they pass we can merge it. |
Is it possible for the regression tests to fail intermittently? I ran the failing test CruiseControlST locally with a Kind cluster and it didn't fail for me. Wondering if you could rerun those failing pipelines? I'm guessing I don't have permissions for obvious reasons. This was the command I used, FYI DOCKER_TAG=0.44.1 \
DOCKER_REGISTRY=localhost:5001 \
ST_KAFKA_VERSION=3.8.0 \
KAFKA_VERSION=3.8.0 \
STRIMZI_USE_KRAFT_IN_TESTS=true \
STRIMZI_USE_NODE_POOLS_IN_TESTS=true \
STRIMZI_RBAC_SCOPE=CLUSTER \
BRIDGE_IMAGE=latest-released \
mvn \
-DexcludeGroups=flaky,loadbalancer,networkpolicies \
-Dmaven.javadoc.skip=true \
-Dfailsafe.rerunFailingTestsCount=2 \
-Djunit.jupiter.execution.parallel.enabled=1 \
-Dskip.surefire.tests \
-f systemtest/pom.xml \
-DskipTests=false \
-Dgroups=regression,kafkasmoke \
-Dit.test='cruisecontrol/CruiseControlST' \
verify |
It could definitely be flaky. I restarted it and let's see how it goes now. I think it is unlikely that you really broke anything here. |
Thanks for the PR! |
Type of change
Enhancement / new feature
Description
Enabling users to configure
spec.allocateLoadBalancerNodePorts
in an externalLoadBalancer
typeService
by providing an option inGenericKafkaListenerConfiguration
.Checklist
Please go through this checklist and make sure all applicable tasks have been done