Skip to content

Conversation

@Anatw
Copy link
Contributor

@Anatw Anatw commented Jan 8, 2024

Short description:
More details:
What this PR does / why we need it:
Which issue(s) this PR fixes:
Special notes for reviewer:
Bug:

@redhat-qe-bot
Copy link
Contributor

Report bugs in Issues

The following are automatically added:

  • Add reviewers from OWNER file (in the root of the repository) under reviewers section.
  • Set PR size label.
  • New issue is created for the PR. (Closed when PR is merged/closed)
  • Run pre-commit if .pre-commit-config.yaml exists in the repo.

Available user actions:

  • To mark PR as WIP comment /wip to the PR, To remove it from the PR comment /wip cancel to the PR.
  • To block merging of PR comment /hold, To un-block merging of PR comment /hold cancel.
  • To mark PR as verified comment /verified to the PR, to un-verify comment /verified cancel to the PR.
    verified label removed on each new commit push.
  • To cherry pick a merged PR comment /cherry-pick <target branch to cherry-pick to> in the PR.
    • Multiple target branches can be cherry-picked, separated by spaces. (/cherry-pick branch1 branch2)
    • Cherry-pick will be started when PR is merged
  • To build and push container image command /build-and-push-container in the PR (tag will be the PR number).
  • To add a label by comment use /<label name>, to remove, use /<label name> cancel
Supported /retest check runs
  • /retest tox: Retest tox
  • /retest sonarqube: Retest sonarqube
  • /retest python-module-install: Retest python-module-install
Supported labels
  • hold
  • verified
  • wip
  • lgtm

nad_name_for_policy (str): The name of the NetworkAttachmentDefinition to which the resources connected
the created policy will impact.
client (DynamicClient): Dynamic client for connecting to a remote cluster.
policy_types (list): one or both of the valid ip policies - "Ingress" and "Egress".
Copy link
Collaborator

Choose a reason for hiding this comment

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

do not include api-supported values

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack

self.res["metadata"]["annotations"] = {
f"{MultiNetworkPolicy.api_group}/policy-for": f"{self.namespace}" f"/{self.nad_name_for_policy}"
}
updated_data = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

set directly in self.res["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.

I don't understand. This is part of the metadata, not the spec.

Copy link
Collaborator

Choose a reason for hiding this comment

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

updated_data is set as spec
please see other resources to see how we set data under 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.

Ack

for policy in self.policy_types:
if policy == "Ingress":
ingress = "ingress"
if not self.ingress:
Copy link
Collaborator

Choose a reason for hiding this comment

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

this can be an empty list - see Deny ingress from all pods in all namespaces section

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack

}
}
self.res["spec"] = {}
for policy in self.policy_types:
Copy link
Collaborator

Choose a reason for hiding this comment

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

if a user sends self.ingress or self.egress; add it to 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.

ack

self.res["metadata"]["annotations"] = {
f"{MultiNetworkPolicy.api_group}/policy-for": f"{self.namespace}" f"/{self.nad_name_for_policy}"
}
updated_data = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

updated_data is set as spec
please see other resources to see how we set data under spec

@myakove
Copy link
Collaborator

myakove commented Jan 11, 2024

@Anatw Please do not resolve comments without pushing new code.

Copy link
Collaborator

@myakove myakove left a comment

Choose a reason for hiding this comment

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

None of the comments was addressed.

Comment on lines 28 to 31
policy_types (list): One or both of the valid ip policies - "Ingress" and "Egress".
ingress (list): list containing a dictionary specifying the allowed "from" parameters.
egress (list): list containing a dictionary specifying the allowed "to" parameters.
pod_selector (dict): Map a label to match.
Copy link
Collaborator

Choose a reason for hiding this comment

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

please add optional to those that are not mandatory

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack

raise ValueError("network_name is required")

self.res["metadata"]["annotations"] = {
f"{self.api_group}/policy-for": f"{self.namespace} /{self.network_name}"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
f"{self.api_group}/policy-for": f"{self.namespace} /{self.network_name}"
f"{self.api_group}/policy-for": f"{self.namespace}/{self.network_name}"

redundant space?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed

f"{self.api_group}/policy-for": f"{self.namespace} /{self.network_name}"
}
self.res["spec"] = {}
self.res["spec"].update({
Copy link
Collaborator

Choose a reason for hiding this comment

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

assign directly in self.res["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.

Ack

}
self.res["spec"] = {}
self.res["spec"].update({
"podSelector": {"matchLabels": self.pod_selector} if self.pod_selector else {},
Copy link
Collaborator

Choose a reason for hiding this comment

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

user should send the whole dict; empty dict will block all
this is mandatory

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack

"podSelector": {"matchLabels": self.pod_selector} if self.pod_selector else {},
"policyTypes": self.policy_types,
})
if self.ingress:
Copy link
Collaborator

Choose a reason for hiding this comment

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

can be empty list (deny all) - this condition will not apply what is requested by the user

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if the user want to deny all he should send an empty list.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If you tested it, and it's working, then I guess t is OK.
Did you test it?

Copy link
Collaborator

Choose a reason for hiding this comment

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

any update on this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the user can send an empty list

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure about it.

In [1]: ingress = []

In [2]: if ingress:
   ...:     print("ingress")
   ...: 

In [3]: 

How your code going to set [] if it will never get in here if the user send []?
What do I miss?

})
if self.ingress:
self.res["spec"].update({"ingress": self.ingress})
else: # self.egress
Copy link
Collaborator

Choose a reason for hiding this comment

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

  1. please remove the inline comment
  2. see comment on empty list above
  3. if one of them is mandatory, please add a check. if not, please add a separate condition - according to the doc, one of them must exist

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is possible to create a policy without self.ingress or self.egress:
apiVersion: k8s.cni.cncf.io/v1beta1
kind: MultiNetworkPolicy
metadata:
annotations:
k8s.cni.cncf.io/policy-for: flat-overlay-ns/flat-l2-nad
name: flat-overlay-mnp
namespace: flat-overlay-ns
spec:
podSelector:
matchLabels:
kubevirt.io/vm: vma
policyTypes:

  • Egress

Can you please refer me to where in the documentation you saw that including at least one of them is mandatory?

I added a condition instead of the 'else'.

Copy link
Contributor Author

@Anatw Anatw Jan 21, 2024

Choose a reason for hiding this comment

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

If you tested it, and it's working, then I guess t is OK.
Did you test it?
I can't respond to your original message so I'm responding here - I did test it and the policy is created successfully. If the documentation is specifically claiming otherwise I want to make sure this is not a bug.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 8, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@Anatw
Copy link
Contributor Author

Anatw commented Feb 8, 2024

/verified

@rnetser rnetser merged commit 81acadc into RedHatQE:main Feb 11, 2024
@Anatw
Copy link
Contributor Author

Anatw commented Feb 11, 2024

/cherry-pick v4.15

redhat-qe-bot2 pushed a commit that referenced this pull request Feb 11, 2024
Signed-off-by: Anat Wax <awax@redhat.com>
@redhat-qe-bot2
Copy link

Cherry-picked PR Add MultiNetworkPolicy resource into v4.15

redhat-qe-bot2 added a commit that referenced this pull request Feb 11, 2024
Signed-off-by: Anat Wax <awax@redhat.com>
Co-authored-by: ‪Anat Wax <46938838+Anatw@users.noreply.github.com>
myakove pushed a commit that referenced this pull request Aug 11, 2025
Signed-off-by: Anat Wax <awax@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants