-
Notifications
You must be signed in to change notification settings - Fork 198
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 Listener port validation #939
Conversation
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 contribution! Left some comments
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.
Looks good to me with the update Darren proposed regarding the t.Errorf
vs Require
logic!
96956cc
to
3b238d7
Compare
…hat and refactor umbrella functions accordingly
…ternal access logic
3b238d7
to
4f1fcdc
Compare
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 for the work. :)
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 at a glance with 1 comment.
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! Have one suggestion.
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.
Feel free to merge
c6f0ea7
d1064eb
What's in this PR?
This PR aims to add some validation for the port numbers under
spec.listenersConfig
of theKafkaCluster
CR.Example config pointing out the fields this PR adds validation for :
The validation logic added in this PR falls under 2 categories :
containerPort
(viaCommonListenerSpec
; applies to both internal and external listeners) and toexternalListeners[].externalStartingPort
Create
andUpdate
operations) forKafkaCluster
to check that:externalStartingPort + brokers[].id
is sane (1 < value < 65535)containerPort
is not duplicated between listeners because that would lead to aDuplicate value
error when creating the Kafka broker Service (headless or "all-brokers") (just a general rule of K8s Services)Port
reused under differentspec.ports[index]
):This PR also includes :
Create
operations (as well as the already existingUpdate
operations) and what I thought are the necessary translations of that into the helm charts.IsAdmissionInvalidExternalListenerPort()
)The new unit tests use testify/require.
Outdated: I chose to do matching with the
ElementsMatch
function because order doesn't matter even though it is deterministic. With the current test cases theEqual
function could be used just as well.Update: In
kafkacluster_validator_test.go
matching is done withrequire.Equal()
per the advice and explanations received during review.Why?
I reckon this deals with most of #913 (and a bit more).
Additional context
Tested on a real cluster (with
make deploy
) and, for the webhook, tested both Create and Update operations (with bothkubectl apply
andkubectl edit
forUpdate
).Example inputs and results:
Results in :
Also:
Results in :
Results in :
We get the same messages/errors when using
kubectl apply/create
and when usingkubectl edit
(depending on the operation Create/Update being performed).externalListeners[].accessMethod: NodePort
The checks proposed in this PR address generic well-known bounds for port numbers.
They don't address in any way the more restrictive port range at play when
externalListeners[].accessMethod: NodePort
--> the issue I detect here is that the nodePort range is a kubeapiserver input flag/parameter and I don't know how to query for that... also, even if we could do that we can't guarantee that a value is not already taken by another service. For this case, I think we'll have to keep relying on errors from the K8sService
controller during deployment.Naming scheme
Please also provide feedback on the name and message string of the new sentinel error in
pkg/webhooks/errors.go
and the exported function meant to "recognize it" (IsAdmission...()
).Please let me know if there are other cases I missed in the unit tests or, worse, the logic.