CentaurusInfra / mizar

Mizar – Experimental, High Scale and High Performance Cloud Network https://mizar.readthedocs.io
https://mizar.readthedocs.io
GNU General Public License v2.0
112 stars 50 forks source link

Implement Label Based Network Policies - Watch policy changes and generate label-policy data #481

Closed Hong-Chang closed 3 years ago

Hong-Chang commented 3 years ago

What does this PR do? When there is network policy created or updated, create corresponding label based data. The data will be sent into XDP tables in later code. The calculated data is "pod_label_policy_table", "namespace_label_policy_table" and "pod_and_namespace_label_policy_table". The sample calculated data looks like followed: "pod_label_policy_table": [ {"pod_label_value": 13, "bit_value": 3}, {"pod_label_value": 14, "bit_value": 3}, ], "namespace_label_policy_table": [ {"namespace_label_value": 2, "bit_value": 3}, {"namespace_label_value": 3, "bit_value": 1}, ], "pod_and_namespace_label_policy_table": [ {"pod_label_value": 13, "namespace_label_value": 2, "bit_value": 3}, {"pod_label_value": 13, "namespace_label_value": 3, "bit_value": 3}, {"pod_label_value": 14, "namespace_label_value": 2, "bit_value": 3}, {"pod_label_value": 14, "namespace_label_value": 3, "bit_value": 3}, ]

How was this tested? I did manual e2e test and verified the calculated data is correct.

Are there any user facing / API changes? No.

vinaykul commented 3 years ago

Can we please add unit tests? While it looks OK to me, I think I'll rely on Cathy signing off for this.

Hong-Chang commented 3 years ago

Can we please add unit tests? While it looks OK to me, I think I'll rely on Cathy signing off for this.

There is no unit test for this part. For networkpolicy util, originally we should create multiple modules in different layers and it will be easy for unit test. But later we decided to put only one file so it's not unit testable.

phudtran commented 3 years ago

LGTM

vinaykul commented 3 years ago

/lgtm

vinaykul commented 3 years ago

Can we please add unit tests? While it looks OK to me, I think I'll rely on Cathy signing off for this.

Looked again, there is no unit tests at all. We need to add unit testing to all the code in next release.