Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

Make excluded namespace configurable #1444

Merged
merged 1 commit into from
Apr 6, 2021

Conversation

yiqigao217
Copy link
Contributor

@yiqigao217 yiqigao217 commented Mar 23, 2021

Fixes #374, #1023.
Part of #1443.
See design https://bit.ly/hnc-excluded-namespaces.

Add excluded-namespace container args in the
config/manager/manager.yaml to allow user defined excluded namespaces.
The default excluded namespaces are kube-system, kube-public, hnc-system
and kube-node-lease. Add excluded-namespace label to hnc-system by
default to avoid deadlock (between cert-rotator writing secret vs object
webhook failing CLOSE) when installing HNC. Let users to add
excluded-namespaces to other namespaces.

Replace the hard-coded EX excluded namespaces.

Add webhook patch only to the object validator with namespaceSelector to
filter excluded namespaces. Add comments on why not patching other
validators. Make object validator fail CLOSE now.

Patch object webhook to only apply on "namespaced" scope objects, so
that cert-rotator can insert certs to VWHConfiguration and namespaced
objects are indeed what we care in HNC.

Add webhook rules:

  1. Do not allow creating/updating non-excluded namespace with excluded
    label;
  2. Do not allow excluded namespaces to be created as a subnamespace;
  3. Do not allow setting an excluded namespace as a child.

Make hierarchyConfiguration reconciler remove excluded-namespace label
on non-excluded namespaces.

Add excluded-namespace label to user-guide/concepts.md doc.

Tested by make test and make test-e2e.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Mar 23, 2021
@k8s-ci-robot k8s-ci-robot requested review from Fei-Guo and srampal March 23, 2021 17:58
@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 23, 2021
@yiqigao217 yiqigao217 requested review from adrianludwin and removed request for srampal and Fei-Guo March 23, 2021 17:58
@yiqigao217
Copy link
Contributor Author

/assign @adrianludwin
/assign @rjbez17

(See commit message) I was not able to think of a good e2e test case for this, so I did a manual test. Please let me know if you have any sugguestions, thanks!

incubator/hnc/config/webhook/webhook_patch.yaml Outdated Show resolved Hide resolved
incubator/hnc/internal/reconcilers/anchor.go Outdated Show resolved Hide resolved
incubator/hnc/cmd/manager/main.go Outdated Show resolved Hide resolved
incubator/hnc/internal/reconcilers/suite_test.go Outdated Show resolved Hide resolved
incubator/hnc/internal/validators/namespace.go Outdated Show resolved Hide resolved
@yiqigao217
Copy link
Contributor Author

Please note in this PR, I added the hnc.x-k8s.io/excluded-namespace label to hnc-system namespace by default, so that HNC installation could work, because otherwise there will be a deadlock between cert-rotator writing secret VS object webhook failing CLOSE to block it. See PR message.

I will update the design doc to reflect it if it SGTY @adrianludwin @rjbez17 .

Additionally the e2e tests always pass on a clean cluster but may be flaky on problematic cluster (with resource stuck on terminating status). I will look further into it tomorrow.

incubator/hnc/config/webhook/webhook_patch.yaml Outdated Show resolved Hide resolved
incubator/hnc/cmd/manager/main.go Show resolved Hide resolved
incubator/hnc/config/webhook/webhook_patch.yaml Outdated Show resolved Hide resolved
incubator/hnc/docs/user-guide/concepts.md Outdated Show resolved Hide resolved
incubator/hnc/docs/user-guide/concepts.md Show resolved Hide resolved
incubator/hnc/internal/reconcilers/hierarchy_config.go Outdated Show resolved Hide resolved
incubator/hnc/internal/validators/anchor.go Show resolved Hide resolved
incubator/hnc/internal/validators/namespace.go Outdated Show resolved Hide resolved
@@ -99,6 +106,16 @@ func (v *Namespace) handle(req *nsRequest) admission.Response {
return allow("")
}

func (v *Namespace) illegalExcludedNamespaceLabel(req *nsRequest) admission.Response {
for l := range req.ns.Labels {
if l == api.LabelExcludedNamespace && !config.ExcludedNamespaces[req.ns.Name] {
Copy link
Contributor

Choose a reason for hiding this comment

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

What about if that namespace already has the label? Should we block further changes to that namespace until the label is deleted?

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, I updated the message to say "Please remove the %q label. See http://... for detail".

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not a huge fan of this. I feel like webhooks should only validate the changes in a resource, not what's already there. For example, imagine an automated process that's trying to make some unrelated change; we shouldn't block them. And we shouldn't have to ask the user to remove the label given that we've got a reconciler that can do it automatically.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sg. Changed the message back to "You cannot exclude this namespace using the %q label. See..for detail"
and commented here with:

			// Note: this only blocks the request if it has a newly added illegal
			// excluded-namespace label because existing illegal excluded-namespace
			// label should have already been removed by our reconciler. For example,
			// even when the VWHConfiguration is removed, adding the label to a non-
			// excluded namespace would pass but the label is immediately removed; when
			// the VWHConfiguration is there but the reconcilers are down, any request
			// gets denied anyway.

Copy link
Contributor

@adrianludwin adrianludwin left a comment

Choose a reason for hiding this comment

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

lgtm after these last few minor fixes

/cc @rjbez17

incubator/hnc/docs/user-guide/concepts.md Outdated Show resolved Hide resolved
incubator/hnc/internal/validators/anchor.go Outdated Show resolved Hide resolved
incubator/hnc/internal/validators/anchor.go Show resolved Hide resolved
incubator/hnc/internal/validators/anchor.go Outdated Show resolved Hide resolved
@k8s-ci-robot k8s-ci-robot requested a review from rjbez17 April 1, 2021 02:12
Fixes 374, 1023
Part of 1443.
See design https://bit.ly/hnc-excluded-namespaces.

Add `excluded-namespace` container args in the
config/manager/manager.yaml to allow user defined excluded namespaces.
The default excluded namespaces are kube-system, kube-public, hnc-system
and kube-node-lease. Add excluded-namespace label to hnc-system by
default to avoid deadlock (between cert-rotator writing secret vs object
webhook failing CLOSE) when installing HNC. Let users to add
excluded-namespaces to other namespaces.

Replace the hard-coded `EX` excluded namespaces.

Add webhook patch only to the object validator with namespaceSelector to
filter excluded namespaces. Add comments on why not patching other
validators. Make object validator fail CLOSE now.

Patch object webhook to only apply on "namespaced" scope objects, so
that cert-rotator can insert certs to VWHConfiguration and namespaced
objects are indeed what we care in HNC.

Add webhook rules:
1) Do not allow creating/updating non-excluded namespace with excluded
label;
2) Do not allow excluded namespaces to be created as a subnamespace;
3) Do not allow setting an excluded namespace as a child.

Make hierarchyConfiguration reconciler remove excluded-namespace label
on non-excluded namespaces.

Add excluded-namespace label to user-guide/concepts.md doc.

Tested by make test and make test-e2e.
@adrianludwin
Copy link
Contributor

/lgtm
/approve
/hold
/assign @rjbez17

@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm Indicates that a PR is ready to be merged. labels Apr 1, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: adrianludwin, yiqigao217

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:
  • OWNERS [adrianludwin,yiqigao217]

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

@yiqigao217
Copy link
Contributor Author

FYI the doc is updated in the "Detailed Design" section. PTAL thanks!
https://bit.ly/hnc-excluded-namespaces

Copy link

@rjbez17 rjbez17 left a comment

Choose a reason for hiding this comment

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

lgtm after the one question

Setting this label on namespaces that are not
listed in the HNC deployment as an `excluded-namespace` is not allowed.

As of March 2021, the default excluded namespaces listed in [config/manager/manager.yaml](https://github.com/kubernetes-sigs/multi-tenancy/blob/master/incubator/hnc/config/manager/manager.yaml)
Copy link

Choose a reason for hiding this comment

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

I kind of feel this should be called out in the installation section or linked from their. As it's a pre/post installation action that is somewhat hidden away but also highly recommended for users to do.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, it should probably be mentioned here, but it will be more important to call it out in the release notes, which is where the latest installation instructions are.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Filed #1466 to add excluded namespace configuration to v0.8 release notes and the installation instruction.

@yiqigao217
Copy link
Contributor Author

/hold cancel
Asked Ryan offline.

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 6, 2021
@k8s-ci-robot k8s-ci-robot merged commit 7683941 into kubernetes-retired:master Apr 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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. lgtm Indicates that a PR is ready to be merged. 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.

HNC: make controller exclusions configurable
4 participants