Skip to content
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

Merged
merged 10 commits into from
Nov 10, 2024

Conversation

venkatesh2090
Copy link
Contributor

@venkatesh2090 venkatesh2090 commented Nov 3, 2024

Type of change

Enhancement / new feature

Description

Enabling users to configure spec.allocateLoadBalancerNodePorts in an external LoadBalancer type Service by providing an option in GenericKafkaListenerConfiguration.

Checklist

Please go through this checklist and make sure all applicable tasks have been done

  • Write tests
  • Make sure all tests pass
  • Update documentation
  • Check RBAC rights for Kubernetes / OpenShift roles
  • Try your changes from Pod inside your Kubernetes and OpenShift cluster, not just locally
  • Reference relevant issue(s) and close them after merging
  • Update CHANGELOG.md
  • Supply screenshots for visual changes, such as Grafana dashboards

@venkatesh2090 venkatesh2090 force-pushed the feat/allocateLoadBalancerNodePorts branch from 858a79f to 12b80ac Compare November 3, 2024 14:42
@venkatesh2090 venkatesh2090 marked this pull request as draft November 3, 2024 15:44
Signed-off-by: Venkatesh Kannan <[email protected]>
@venkatesh2090 venkatesh2090 force-pushed the feat/allocateLoadBalancerNodePorts branch from 9fd38e2 to 1d501b8 Compare November 3, 2024 17:19
@@ -58,6 +58,7 @@ public class GenericKafkaListenerConfiguration implements UnknownPropertyPreserv
private String hostTemplate;
private String advertisedHostTemplate;
private Map<String, Object> additionalProperties;
private Boolean allocateLoadBalancerNodePorts = true;
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

@scholzj scholzj left a 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.

@scholzj scholzj added this to the 0.45.0 milestone Nov 3, 2024
@venkatesh2090
Copy link
Contributor Author

I have pushed some tests, but the tests in KafkaClusterTest are seemingly incomplete. The testGenerateExternalBootstrapService and testGeneratePerPodService is supposed to assert other fields but I don't have enough context to add those. Moreover I am not sure if it even belongs in this PR. I have only added asserts for the allocateLoadBalancerNodePorts field.

Comment on lines 157 to 164
new GenericKafkaListenerBuilder()
.withName("lb")
.withPort(9094)
.withType(KafkaListenerType.LOADBALANCER)
.withNewConfiguration()
.withAllocateLoadBalancerNodePorts(false)
.endConfiguration()
.build())
Copy link
Member

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.

Comment on lines 865 to 884
@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));
}
Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

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.

Comment on lines 768 to 777
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));
Copy link
Member

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.

Copy link
Contributor Author

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]>
@scholzj
Copy link
Member

scholzj commented Nov 6, 2024

/azp run regression

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Member

@scholzj scholzj left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks.

@scholzj scholzj requested a review from ppatierno November 6, 2024 04:57
Copy link
Member

@ppatierno ppatierno left a 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;
}
Copy link
Member

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;

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, that is fine.

@venkatesh2090 venkatesh2090 force-pushed the feat/allocateLoadBalancerNodePorts branch from 869ba8b to 225bc90 Compare November 7, 2024 22:01
Signed-off-by: Venkatesh Kannan <[email protected]>
@scholzj
Copy link
Member

scholzj commented Nov 8, 2024

/azp run regression

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@scholzj
Copy link
Member

scholzj commented Nov 8, 2024

I started the regression tests and if they pass we can merge it.

@venkatesh2090
Copy link
Contributor Author

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

@scholzj
Copy link
Member

scholzj commented Nov 9, 2024

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.

@scholzj
Copy link
Member

scholzj commented Nov 10, 2024

Thanks for the PR!

@scholzj scholzj merged commit c0f4a0f into strimzi:main Nov 10, 2024
21 checks passed
@venkatesh2090 venkatesh2090 deleted the feat/allocateLoadBalancerNodePorts branch November 10, 2024 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants