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

Allow including both podSelector and namespaceSelector in a NetworkPolicyPeer #60452

Merged

Conversation

danwinship
Copy link
Contributor

Updates NetworkPolicy API docs and validation to allow podSelector and namespaceSelector to be specified together in a NetworkPolicyPeer

Fixes #58637

Release note:

NetworkPolicies can now target specific pods in other namespaces by including both a namespaceSelector and a podSelector in the same peer element.

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Feb 26, 2018
@k8s-github-robot k8s-github-robot added the kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API label Feb 26, 2018
@danwinship
Copy link
Contributor Author

/sig network

Is there anything else I missed in kubernetes itself? We'll also need a docs PR and a kubectl PR...

@k8s-ci-robot k8s-ci-robot added the sig/network Categorizes an issue or PR as relevant to SIG Network. label Feb 26, 2018
@danwinship
Copy link
Contributor Author

Having actually written the docs now, I'm maybe more convinceable that we should go with podAndNamespaceSelector instead; it would work more cleanly with the idea of separately documenting each field in NetworkPolicyPeer like we do...

@caseydavenport
Copy link
Member

Having actually written the docs now, I'm maybe more convinceable that we should go with podAndNamespaceSelector instead; it would work more cleanly with the idea of separately documenting each field in NetworkPolicyPeer like we do...

I'd prefer to not introduce a new field such as podAndNamespaceSelector

As a user of the API, I think the AND of podSelector and namespaceSelector is exactly how I'd expect those two to behave when both specified. In fact, even a generic AND would make sense to me, though I don't see what use-case I'd have for it.

As an implementor, it's almost no work on my side to simply support the AND combination of pod / namespace, whereas there's more for me to do to support a new selector field.

@thockin
Copy link
Member

thockin commented Feb 26, 2018 via email

@caseydavenport
Copy link
Member

My concern is that the AND isn't generic (unless we make it so) and is
therefore vastly more confusing.

That may be, though with a well written out validation error I'd guess it would be fairly clear.

I understand it might be extra work for other implementors to do the generic AND, but from a Calico perspective it's trivial. So personally I'd rather have us implement the generic AND than add an extra type for people to reason with.

@danwinship
Copy link
Contributor Author

That may be, though with a well written out validation error I'd guess it would be fairly clear.

"may not specify both ipBlock and another peer"

@thockin
Copy link
Member

thockin commented Feb 27, 2018 via email

@Lion-Wei
Copy link

I like this, is this anything I can help? Maybe the kubectl pr? @danwinship

@danwinship
Copy link
Contributor Author

@Lion-Wei: sure. "kubectl describe" needs to be extended to be able to describe policies where a NetworkPolicyPeer has both podSelector and namespaceSelector set (describing it according to the semantics seen in the API docs here).

@danwinship
Copy link
Contributor Author

/retest

Copy link
Member

@caseydavenport caseydavenport left a comment

Choose a reason for hiding this comment

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

This LGTM - one minor comment.

I'm in favor of merging as-is, and further relaxing the validation if we get feedback that it's confusing.

@@ -47,7 +47,7 @@ if ! ${ALL} ; then
echo "Running in short-circuit mode; run with FORCE_ALL=true to force all scripts to run."
fi

"${KUBE_ROOT}/hack/godep-restore.sh" ${V}
#"${KUBE_ROOT}/hack/godep-restore.sh" ${V}
Copy link
Member

Choose a reason for hiding this comment

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

Need to add this back?

@Lion-Wei
Copy link

Lion-Wei commented Mar 2, 2018

@danwinship I will push that pr as soon as this got merged. : )

@danwinship
Copy link
Contributor Author

@caseydavenport repushed with the stray update.sh change removed if you want to /lgtm it

@caseydavenport
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 2, 2018
@thockin
Copy link
Member

thockin commented Mar 3, 2018

/approve

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 3, 2018
@thockin
Copy link
Member

thockin commented Mar 5, 2018

This change is Reviewable

@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to fejta).

Review the full test history for this PR.

Silence the bot with an /lgtm cancel comment for consistent failures.

1 similar comment
@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to fejta).

Review the full test history for this PR.

Silence the bot with an /lgtm cancel comment for consistent failures.

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 9, 2018
@oivindoh
Copy link

oivindoh commented Mar 21, 2018

What's holding this thing of outstanding natural beauty back? Just re-applying /lgtm?

@danwinship
Copy link
Contributor Author

It's waiting for 1.10 to go out and master to reopen for 1.11. I'm not sure where the /lgtm went.

@thockin
Copy link
Member

thockin commented Mar 23, 2018

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 23, 2018
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: caseydavenport, danwinship, thockin

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to fejta).

Review the full test history for this PR.

Silence the bot with an /lgtm cancel comment for consistent failures.

3 similar comments
@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to fejta).

Review the full test history for this PR.

Silence the bot with an /lgtm cancel comment for consistent failures.

@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to fejta).

Review the full test history for this PR.

Silence the bot with an /lgtm cancel comment for consistent failures.

@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to fejta).

Review the full test history for this PR.

Silence the bot with an /lgtm cancel comment for consistent failures.

@k8s-github-robot
Copy link

/test all [submit-queue is verifying that this PR is safe to merge]

@k8s-github-robot
Copy link

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions here.

@k8s-github-robot k8s-github-robot merged commit 0b062e1 into kubernetes:master Mar 24, 2018
@danwinship danwinship deleted the networkpolicy-pod-plus-ns branch March 26, 2018 13:28
@ahmetb
Copy link
Member

ahmetb commented May 8, 2018

Is this technically a breaking change in the behavior? (or was it impossible to specify both namespaceSelector and podSelector on the same peer spec?)

@oivindoh
Copy link

oivindoh commented May 8, 2018

@caseydavenport does this require a change in calico to work?

@danwinship
Copy link
Contributor Author

@ahmetb It was previously impossible to specify both; validation would reject the resource in that case

@caseydavenport
Copy link
Member

@oivindoh yeah, we'll need to make a minor change to Calico in order to make this work. Should be really straightforward.

Calico supports this already within its policy model, but the code which converts kubernetes policies doesn't yet expect this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/network Categorizes an issue or PR as relevant to SIG Network. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants