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 support for kubernetes endport field #1080

Merged
merged 1 commit into from
Jun 17, 2021

Conversation

rikatz
Copy link
Contributor

@rikatz rikatz commented May 11, 2021

This PR adds support for the recently added endPort field in kubernetes, which now is feature gated but will be marked as default in next release.

TODO:

  • Improve tests
  • Validate functioning with Kubernetes
  • Verify need to change docs

@aauren
Copy link
Collaborator

aauren commented May 13, 2021

@rikatz Thanks for thinking of us and submitting this! Definitely appreciate it!

Give me a shout when you finish with the other checkboxes in there and want a review and I'll take another look.

I was looking at the documentation for this feature (https://kubernetes.io/docs/concepts/services-networking/network-policies/#targeting-a-range-of-ports) and I can't tell if this is only for egress, or if endPort can show up in both ingress and egress. Did only the egress specification change or both?

@rikatz
Copy link
Contributor Author

rikatz commented May 13, 2021

Hey @aauren for sure. I'm getting some time during this weekend to finish here.

EndPort works for both Ingress and Egress: It's part of the NetworkPolicyPort struct (used in both). In case of Ingress it's more feasible when working with Intra Pod communications (or headless) as services nowadays does not support portRanges (yet! there's a KEP ongoing about that).

https://github.com/kubernetes/enhancements/blob/master/keps/sig-network/2079-network-policy-port-range/README.md Here's the specification if you wanna take a look :)

Thank you very much!

@rikatz rikatz force-pushed the endport-support branch from 2af4a07 to d92dc94 Compare May 30, 2021 20:18
@rikatz
Copy link
Contributor Author

rikatz commented May 30, 2021

@aauren I've added some unit tests, and tested the correct rule creation in Kubernetes as well. Everything seems to work fine, although I'm running inside KinD and it seems to be complaining about some things.

I'll try to run on a pure kubeadm cluster, but if you can take a look into the PR I would appreciate.

Thanks!!

Copy link
Collaborator

@aauren aauren left a comment

Choose a reason for hiding this comment

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

Overall it looks really good, thanks for implementing this for us!

I just and a question and two small changes requested.

}
}
portproto.protocol, portproto.port = protocol, npPort.Port.String()
numericPorts = append(numericPorts, portproto)
} else {
if protocol2eps, ok := namedPort2eps[npPort.Port.String()]; ok {
if numericPort2eps, ok := protocol2eps[string(*npPort.Protocol)]; ok {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you substitute out this conversion of string(*npPort.Protocol) to protocol like you refactored the others?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done :)

} else {
// Per k8s api validation we should never reach this
// but if EndPort is < than Port we should skip
continue
Copy link
Collaborator

Choose a reason for hiding this comment

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

With this, if endPort < Port then we don't add the port at all to the network policy rather than just resorting to the old functionality of only using the port. I would think that it would be better to resort to the old functionality of adding the Port and leaving off the endPort if it can't be validated.

Is this intended by the spec?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hum, agreed with you! Will change here. Actually the spec drops the netpol object in validation, when this situation happens so in this case this is a last resort here (we assume here that something wrong happened in k8s api validation).

@aauren
Copy link
Collaborator

aauren commented Jun 2, 2021

BTW I was also able to test this on my test cluster and validated that the rules were created as we expected.

@rikatz
Copy link
Contributor Author

rikatz commented Jun 9, 2021

Hey @aauren sorry for my long delay. I'll cycle back to this probably tomorrow :)

@rikatz rikatz force-pushed the endport-support branch from d92dc94 to ee4df09 Compare June 13, 2021 19:58
@rikatz
Copy link
Contributor Author

rikatz commented Jun 13, 2021

@aauren fixed per your comments and already squashed things (as those are minor changes!)

Sorry once more about the delay, things are pretty busy here :)

@murali-reddy
Copy link
Member

thanks @rikatz for adding support for port ranges.

@aauren thanks for revewing. I had a chance to look at the PR. Changes LGTM.

@murali-reddy murali-reddy merged commit 21473ed into cloudnativelabs:master Jun 17, 2021
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.

3 participants