40 Commits

Author SHA1 Message Date
Roman Dobosz
58e3ca2829 Enable IPv6 in network policy driver.
In network policy driver we are using security groups for the OpenStack
side to create appropriate port ranges to be open for certain hosts (or
all hosts). In this patch we add a mechanism for selecting right IP
version to the rule, or create rules for both (IPv4 and IPv6) network
types.

Implements: blueprint kuryr-ipv6-support
Change-Id: Ie7544aeebb1d18038ebc19c8f815b69213b55a88
2020-05-07 17:09:53 +00:00
Roman Dobosz
61f9c85456 Throw an exception in case of exceeding quota.
Sometimes we create a lot of security group rules, which might exceed
the quotas. In this patch we propose to distinguish conflict exceptions
for quota exceeding from rule already exists.

Change-Id: Icea686ec9d1fcb701f1853c40d6cfd4ca20fd0ac
2020-04-30 09:08:28 +02:00
Michał Dulko
ecda137ddc Remove MEMOIZE from get_pod_ip
get_pod_ip() does not make any API calls and just gets the IP from VIF
annotation. Maybe it would make some sense to cache it to avoid several
dict lookups, but current version bases cache on whole pod object, which
we know may change often over time, so I don't think there's a point in
keeping the cache here.

Change-Id: Id441700ac7add94a675c3a38434abae0b826b766
2020-04-09 17:32:34 +02:00
Luis Tomas Bolivar
780c4dfa09 Namespace event handling through KuryrNet CRD
This patch moves the namespace handling to be more aligned
with the k8s style.

Depends-on: If0aaf748d13027b3d660aa0f74c4f6653e911250

Change-Id: Ia2811d743f6c4791321b05977118d0b4276787b5
2020-03-13 12:30:07 +01:00
Roman Dobosz
ded6b6debc Removing six library.
Since we already migrated fully to Python3, it's time to also remove
bits needed for Python2. One of those libs is six.

Change-Id: Ib984d7b4b3c1048ed091c78986c634689a8ace8c
2020-02-28 14:45:46 +01:00
Michał Dulko
1045bcb02a Bump hacking to newer version
Our hacking module is ancient and makes Python 3.6's f-strings to fail
PEP8 check. This commit bumps hacking to newer version and fixes
violations found by it.

Change-Id: If8769f7657676d71bcf84c08108e728836071425
2020-02-21 12:02:58 +01:00
Roman Dobosz
19d55152bb Update exceptions handling for openstacksdk.
Implements: blueprint switch-to-openstacksdk
Change-Id: I6d9ce11af7e24533ee52e2f50af9a4eb0294c3a1
2020-01-30 14:08:51 +01:00
Roman Dobosz
be132b1aeb Use openstacksdk for setting the tags.
Implements: blueprint switch-to-openstacksdk
Change-Id: I1f91227c855b64872476d807838e55254ca219d5
2020-01-27 14:34:32 +01:00
Roman Dobosz
3a35761feb Use openstacksdk for update_port_pci_info function.
Implements: blueprint switch-to-openstacksdk
Change-Id: Ie188378866b8a9838deb697efe2f387cd0283cbf
2020-01-27 14:33:32 +01:00
Roman Dobosz
29e49616d1 Remove get_ports_by_attrs by simply use args in query ports.
get_ports_by_attrs was using neutron client for obtaining ports with
specified attribites. OpenStackSDK have this OOTB, so that one can query
for ports simply by using os.network.ports(name=…, tags=[…], …), so,
there is no need for additional function.

Also, make use of previously added real port object in tests. By using
openstack.network.v2.port.Port objects we gain such confidence
that we are dealing with an port object, dict, tuple, or any other data
type, so that we can treat it accordingly in the code.

Implements: blueprint switch-to-openstacksdk
Change-Id: I7b597f7229113a598de631641bde04e083fea4b5
2020-01-22 11:42:10 +01:00
Roman Dobosz
e54ff6221c Refactor of os_vif_util module.
Besides refactor itself, there was several issues resolved, like
appropriate data handling - because macvlan driver is still using
neutron client, we have to deal with dict data and openstacksdk objects
at the same time in couple of helper methods in os_vif_util module.

Furthermore, helper method for creating port object for test purposes
was moved to fake module, since it is also utilized in test for os vif
utils.

Change-Id: Iefc758ac22e1688ca9d017d5a4c1d32c4cf0583a
Implements: blueprint switch-to-openstacksdk
2020-01-22 11:40:30 +01:00
Roman Dobosz
b5244a16bb Update network_policy driver to use OpenStackSDK.
Besides driver itself, there was a change also for utils/os_vif_util
modules, since while changing neutron objects to OpenStackSDK objects,
signature has also changed.

Also, favor of using attribute based access for Munch objects (all
OpenStackSDK objects are basically Munch based), so that we can also
have these working in older version of OpenStackSDK.

Implements: blueprint switch-to-openstacksdk
Change-Id: I7db217aa9f2b09b38d5e8709cf3712646f6b6893
2020-01-20 09:58:27 +01:00
Michał Dulko
7ed6e86744 Basic Python 3 compatibility fixes
This is result of running 2to3 without dict fix (as it seems
unnecessary for most of our cases).

In Python 3 {}.values() returns a view that is not indexable. This
commit uses list() on that to make AddHandler.should_callback compatible
with Python 3.

Change-Id: I354597f43d43630f9fb875dd8c9ab741c35af723
2019-11-22 09:19:14 +01:00
Maysa Macedo
b0b78b423c Ensure LB SG is not updated for egress only policy
When an egress Network Policy is enforced, there is no
need to allow the update of the LB SG. Right now, as this
operation is being allowed, we can end up with ingress
rules being removed from the LB.

Closes-Bug: 1850715
Change-Id: Idcdef5c4f2f47a165bfb9b38779b591d5b995216
2019-10-30 20:49:50 +00:00
Maysa Macedo
474495f8c5 Ensure no KuryrNet addition is tried when namespace is not present
In case the KuryrNet CRD addition is being handled and the
namespace is not present on the cluster anymore, the Kuryr Controller
is marked as unhealthy and restarted. This commit ensures
any event that tries to get a not present namespace is skipped.

Closes-Bug: 1846525
Change-Id: I9468785e79c5692709e5c50a3b92cc30f6a37fd8
2019-10-04 14:26:42 +00:00
Zuul
de68d1e9d8 Merge "Ensure no LBaaS SG update is triggered for SVCs without selectors and ports" 2019-09-30 13:55:18 +00:00
Maysa Macedo
68145b9b58 Ensure no LBaaS SG update is triggered for SVCs without selectors and ports
When a Network Policy is enforced we shouldn't try to update the
SG of a LBaaS that would map to a SVC without selector, as this
kind of SVC is not wired by Kuryr. Also, we shouldn't try to update
the LBaaS SG when no ports are defined in the SVC spec.

Closes-Bug: 1845917
Change-Id: I94a288f2b66bd2444d177931f509e1b6ef250235
2019-09-30 09:41:23 +00:00
Maysa Macedo
9dfc5a1dd3 Ensure pod IP is retrieved from annotation
We are retrieving the pod IP from a nonexistent annotation
field, when should be from the annotations in the pod metadata.
Also, when this information is not present we keep retrying with
the same pod object, which doesn't contains an annotation
causing the controller restart.

Closes-Bug: 1845635
Change-Id: I04095a7d36219175c09d4503f2347ab035d3e242
2019-09-27 11:11:25 +00:00
Luis Tomas Bolivar
5e0dec62db Avoid Kuryrnet populating pools before namespace handler finishes
This patch sets ensures kuryrnet handler does not start with the
pools prepopulation for a newly created subnets as soon as the
kuryrnet crd object is created, but waits for the namespace handler
to complete the namespace creation actions (subnet creations, sgs,
and finally namespace annotations with kuryrnetcrd)

Change-Id: Id85eace3763a67d404e3785003490478734af3c9
2019-08-30 16:45:42 +02:00
Maysa Macedo
b0dfb4e5e0 Ensure Pod IP is retrieved after pod is annoated with the VIF
When a pod takes a while to get annotated with the VIF information,
the retrieval of the pod IP from the annotations might fail due to
missing annotation, causing the controller to restart.
This commit fixes the issue by ensuring the pod IP is only retrieved
after the pod is annotated.

Change-Id: Iac1570b76783d532b77e7d8be96f2b71a19f8409
Closes-Bug: 1841758
2019-08-28 16:04:10 +02:00
Luis Tomas Bolivar
bfa1acf27f Ensure namespace network resources are cleaned up
In case of kuryr-controller crash/restart while creating a namespace
it may happen that some network resources are leftover as the kuryr
net crd was not yet created. This may lead to a waste of OpenStack
network resources (networks, subnets). This patch ensures the namespace
is cleaned up before creating the resources in case a previous attempt
was made without completing the kuryr net crd creation.

Change-Id: Iddc03090dc8a847abe4afa2bed0900f0c7cf6936
2019-08-09 11:03:04 +02:00
Luis Tomas Bolivar
e2e63cfc4d Ensure kuryrnet does not perform multiple repopulations
This patch makes use of the KuryrNet CRD spec to ensure pools
population actions on a new namespace only happen once.

Closes-Bug: 1833032

Change-Id: Ia561833d594c55c17a9dc1a588d39bf3410cdf81
2019-06-18 17:56:23 +02:00
Maysa Macedo
8f035cd1c1 Fix Pod creation do not triggers affected SVC SG update
The LBaaS SG is not updated when a pod that is referenced by a
service has a network policy that restrict/accept traffic from
pods in different namespaces. For example: pod-A on namespace-A is
created and according to a network policy should affects the traffic
to pod-B on namespace-B, and consequently to the service that has
pod B as a backend pod.

Change-Id: Idb3365e70e66dd8544f5b97aece312bc18c57ee5
Closes-Bug: 1830598
2019-06-02 03:50:02 -04:00
Danil Golov
14a685d9e1 Update sriov neutron ports with pci info
This commit updates neutron sriov ports when
POD that contains it is in Running state.
It makes request to neutron API to update ports
with binding:profile information.
Due to this it is required to make actions with
privileged user having admin rights.

Change-Id: Iade446cefd78b494291729939db7db75692392c9
Closes-Bug: 1818606
Signed-off-by: Danil Golov <d.golov@samsung.com>
2019-05-20 14:16:04 +03:00
Maysa Macedo
b644083835 Add support for text ports on Network Policy Spec
This commit adds support for Network Policies that define ports
with text. In the case of ingress rule with named port, the pods
selected by NetworkPolicySpec's podSelector has its containers
verified to check for ports with same name. In case of egress rule
all the pods selected by the NetworkPolicyEgressRule's selector
have its containers verified to check if the containers ports
have the same name as the ones defined in policy rule ports.
If matched, a security Group rule with
a 'remote_ip_prefixes' field pointing to that pod is created.

Change-Id: If1eddc3e6cc4884ca53e81e4f87b5fae80fed70e
Closes-Bug: 1818983
2019-04-16 08:59:43 +00:00
Luis Tomas Bolivar
7d03fb19f8 Ensure port_range_min is optional
Ensure port_range_min can be skip as the default value (all ports)
is considered anyway.

Closes-Bug: 1824366
Change-Id: Ic0e724458176b451c3e67413d27a12885f965b99
2019-04-11 16:47:17 +02:00
Maysa Macedo
660bbf039a Ensure only affected services are updated on Pod/NetworkPolicy events
When Pods or Network Policies are created/updated/deleted, only the affected
service(s) should have the SG updated. Right now, all the services are updated.

This commit fixes the issue, on the Network Policy side, by checking if any of
the pods selected by a Service is also selected by a Network Policy, and if so
update the SG of that LBaaS.
And on the Pods side, by matching the Service selectors and Network Policy
selectors, when this NP got the pointed pods SG updated. If the selectors
match the LBaaS SG is updated.

Closes-Bug: 1818203
Change-Id: Id996651a7d03bc7621e57b46825ddfa9d98e48ce
2019-03-08 11:25:01 +00:00
Maysa Macedo
ba89bd027f Fix LBaaS sg rules update on deployment scale
When a service is created with a Network Policy applied and
deployments are scaled up or down, the LBaaS SG rules should be
updated accordindly. Right now, the LBaaS/Service do not react on
deployment scales.
This commit fixes the issue by ensuring that the LBaaS SG is updated
on pod events.

Also, when Pods, Network Policies and SVCs are created together it might
happen that the LBaaS SG remains with default SG rules, even though
the policy is being enforced. This commit ensures the right SG rules
are applied on a LBaaS regardless the order of k8s resources creation.
This happens by setting the LBaaS Spec annotation whenever a request
to update the SG rules has been made and retrieving the Spec again
whenever a LBaaS member is created.

Change-Id: I1c54d17a5fcff5387ffae2b132f5036ee9bf07ca
Closes-Bug: 1816015
2019-03-04 15:57:47 +00:00
Zuul
ce3fe712ac Merge "Add option to tag Neutron resources created by us" 2019-03-04 14:42:48 +00:00
Michał Dulko
88e38e8e94 Add option to tag Neutron resources created by us
If we consider a K8s cluster running on OpenStack VM's, which is a
perfect use case for Kuryr-Kubernetes, we can easily imagine creating
multiple clusters in a single OpenStack public or private cloud. In such
use case those K8s clusters may come and go. As Kuryr is creating some
OpenStack resources, such as ports, networks, subnets, floating IP's or
SG's, it's useful to have a way of identifying those Kuryr-created
resources to delete them along with the K8s cluster that used them.

This commit makes that possible by adding an option to add tag to all
Neutron resources created by Kuryr.

Change-Id: If75028e17d13ec62fb414fa9797ee7ac02d948d1
Implements: blueprint kuryr-resources-tagging
2019-02-21 19:40:36 +01:00
Maysa Macedo
5cf4b41772 Fix CRD podSelector update
When the podSelector of a NP is updated, the podSelector
on the respective CRD must also be updated with the same
value. However, this do not happen in case the field of a label
is updated, for example: Label {'app: demo'} is updated to
{'context:demo'} the result given is {'app: demo', 'context:demo'}
when should be {'context:demo'}. And after that, if the updated label
{'context:demo'} is removed from the NP, it will not be removed from the CRD.
These cases happen because the podSelector field is a dict and not
a list.

This commit fixes the issue by changing the merge strategy to
JSON Patch, instead of JSON Merge Patch.

Change-Id: Ic629c1ba4ac13c2bfaffdf7f904b69abf9521ed3
Closes-Bug: 1810394
2019-02-18 20:43:18 +00:00
Maysa Macedo
9deb322962 Update CRD when NP has namespaceSelectors
When a namespace is created, deleted or updated and
its labels matches the namespaceSelector of a NP,
the CRD and the respective sg must be updated.

Partially Implements: blueprint k8s-network-policies

Change-Id: I515de28647f5f06248555733c27dd4f5a56149ec
2019-01-08 20:22:02 +00:00
Luis Tomas Bolivar
b200d368cd Add Network Policy support to services
This patch adds support for Network Policy on services. It
applies pods' security groups onto the services in front of them.
It makes the next assumptions:
- All the pods pointed by one svc have the same labels, thus the same
sgs being enforced
- Only copies the SG rules that have the same protocol and direction
as the listener being created
- Adds a default rule to NP to enable traffic from services subnet CIDR

Partially Implements: blueprint k8s-network-policies
Change-Id: Ibd4b51ff40b69af26ab7e7b81d18e63abddf775b
2019-01-08 06:35:55 -05:00
Maysa Macedo
0b95415c14 Update CRD when NP has podSelectors
When a pod gets created, deleted or updated and its labels
matches the PodSelector of a NP, the sg must be updated.

Partially Implements: blueprint k8s-network-policies

Change-Id: Ic0dd3bc93e2453460c4d8dea360efd414b6ae42b
2019-01-02 22:14:44 +00:00
Irena Berezovsky
f520f12f99 Trivial Fix: fix typos and set default param
Change-Id: I0159226f80d63fd3831f710460434af95d6efa7f
2018-12-16 11:51:29 +02:00
Luis Tomas Bolivar
30369502bb Add support for podSelector
This include support for both types, when pod selector is used alone
or together with a namespace selector.

TODO in follow up patch sets:
- React to new pods/namespaces created with labels
- React to pod/namespaces relabeling/deletion

Partially Implements: blueprint k8s-network-policies

Change-Id: Ie29b9da64fcd5df7b9a0e9af7b4835208f76da66
2018-12-14 09:02:56 +01:00
Maysa Macedo
8f42cd84d1 Add support to match expressions in Network Policies
This commit adds support to match expressions and redesigns how
Security Groups are fetched and applied to pods that matches
a Network Policy.

Change-Id: I5d2831b09e24a2adc3c26aa29f1e7b131e9314ba
2018-12-12 10:50:58 +00:00
Luis Tomas Bolivar
791d8dc29d Ensure pod_label handler skips host_network pods
Closes-Bug: 1807690
Partially Implements: blueprint k8s-network-policies

Change-Id: Ie1e278836107ab88d8d55fc093b400b1a8d87fd6
2018-12-10 13:07:50 +01:00
Luis Tomas Bolivar
d029ddb277 Ensure existing pods use the right network policy
This patch set ensures that:
- A new network policy is applied to existing pods
- A modification on the network policy selector gets applied on the
associated pods
- Deleting a network policy updated the access policies on the
associated pods
- There is no race at deleting the network policy, ensuring the
security group is first deleted from the ports and then removed
as part of the network policy deletion process

Partially Implements: blueprint k8s-network-policies

Change-Id: I25aa23b87947662333c021b9df3e83b9de2515e2
2018-11-29 14:27:52 +01:00
Alexey Perevalov
776e3e1760 Separate helper function for pod
Several functions, such as _get_network_id, _get_port_name,
_get_device_id, _get_host_id were member of NeutronPodVIFDriver, but
didn't use neither state of class instance nor class itself. These
functions will be used in several places e.g. SriovVIFDriver.
Also there was code duplication in vif_pool.py.

Not all functions, that work with pod and doesn't touch class/instance state,
will be moved to utils.py, due to these functions aren't used somewhere else.

Change-Id: Id9dcb2ab2aeffc74b15cface18659557b2efb3b7
Signed-off-by: Alexey Perevalov <a.perevalov@samsung.com>
2018-08-10 11:23:58 +00:00