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

[add] Support namespace scoped chaos #872

Merged
merged 26 commits into from
Sep 25, 2020

Conversation

STRRL
Copy link
Member

@STRRL STRRL commented Sep 6, 2020

What problem does this PR solve?

Make chaos-mesh controller could work without permission of cluster scope, like pod list from cluster scope.

Related issue: #487

What is changed and how does it work?

This PR makes three things:

  • Add new configurations to switch on namespace scope mode, and target namespace for chaos injecting within namespace scope mode.
  • Make controller manager only watch chaos objects belongs to target namespace; Make pod selector only list pods belongs to target namespace;
  • Create configuration validation and other logic to reject out-of-scoped behaviors.

Checklist

Todos:

  • kubebuilder controller manager support namespace scoped mode
  • K8sConfigMapWatcher support namespace scoped mode
  • helm configs
    - [ ] enhance webhook (like, using namespaceSelector)
  • controller manager could skip chaos that does not belong to target namespace.
    - [ ] e2e tests It's hard to test as expected operation is NOOP.
  • new rbac yaml, as a mininum permission list, for controller serviceaccount
  • found the mininum permission list to install chaos-mesh
  • update the document

Tests

  • Unit test
  • E2E test
  • Manual test (add detailed scripts or steps below)
  • No code

Manually test steps:

WIP

Side effects

  • Breaking backward compatibility

Related changes

  • Need to update the documentation

Does this PR introduce a user-facing change?

No

NONE

… mode

Signed-off-by: STRRL <str_ruiling@outlook.com>
…cope

Signed-off-by: STRRL <str_ruiling@outlook.com>
@STRRL STRRL force-pushed the faeature-namespace-scoped-mode branch from 21bf986 to 980cb96 Compare September 6, 2020 06:01
@cwen0 cwen0 requested a review from Yisaer September 7, 2020 03:18
@cwen0
Copy link
Member

cwen0 commented Sep 7, 2020

@Yisaer PTAL

@STRRL
Copy link
Member Author

STRRL commented Sep 7, 2020

I found that K8sConfigMapWatcher also need some patches, I will finish these changes very soon.

@STRRL
Copy link
Member Author

STRRL commented Sep 7, 2020

Hi @cwen0 @Gallardot mentors, one more thing, shall we consider to split out namespace which inject chaos and namespace which running controller?

For example, running chaos-controller-manager in ns chaos-control-plane, and create a IOChaos in another ns chaos-testing.

Or we should play in ONLY ONE namespace.

@STRRL STRRL marked this pull request as draft September 7, 2020 12:30
cmd/controller-manager/main.go Outdated Show resolved Hide resolved
cmd/controller-manager/main.go Outdated Show resolved Hide resolved
pkg/utils/selector.go Show resolved Hide resolved
@Yisaer
Copy link
Contributor

Yisaer commented Sep 8, 2020

Basically LGTM except the selector is too complex for now. Maybe we need to find a better way to refactor it. Adding an e2e test to verify the namespace-scoped would be better. @STRRL

@STRRL
Copy link
Member Author

STRRL commented Sep 8, 2020

Hi @Yisaer , could you take a little while on this #872 (comment) ? Please give me your opinion about this question.

Thanks!

…ped mode or cluster scoped

Signed-off-by: STRRL <str_ruiling@outlook.com>
…actions;

Signed-off-by: STRRL <str_ruiling@outlook.com>
… and injecting chaos

Signed-off-by: STRRL <str_ruiling@outlook.com>
@STRRL
Copy link
Member Author

STRRL commented Sep 8, 2020

Hi @cwen0 @Gallardot mentors, one more thing, shall we consider to split out namespace which inject chaos and namespace which running controller?

For example, running chaos-controller-manager in ns chaos-control-plane, and create a IOChaos in another ns chaos-testing.

Or we should play in ONLY ONE namespace.

I am working on this, it could improve isolation of our system.

@STRRL STRRL force-pushed the faeature-namespace-scoped-mode branch from 980cb96 to ad37f8a Compare September 8, 2020 15:03
@STRRL STRRL force-pushed the faeature-namespace-scoped-mode branch 2 times, most recently from 0cb5f2d to a446991 Compare September 8, 2020 17:12
@STRRL
Copy link
Member Author

STRRL commented Sep 9, 2020

Basically LGTM except the selector is too complex for now. Maybe we need to find a better way to refactor it.

Hi @Yisaer . I create new issue to track this. #886

I do not recommend refactoring while appending new features. :D

@Yisaer
Copy link
Contributor

Yisaer commented Sep 9, 2020

Basically LGTM except the selector is too complex for now. Maybe we need to find a better way to refactor it.

Hi @Yisaer . I create new issue to track this. #886

I do not recommend refactoring while appending new features. :D

Thanks for your contribution. I didn't mean refactoring selector in this request either. This should be tracked by a new issue and still need to be discussed.

Copy link
Contributor

@Yisaer Yisaer left a comment

Choose a reason for hiding this comment

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

I suggest using namespaceSelector for webhook while namespace-scoped is enabled.

As namespaceSelector need apiserver >= 1.15(need to be verified), the if-else template rendering could refer to here

helm/chaos-mesh/values.yaml Show resolved Hide resolved
@Yisaer
Copy link
Contributor

Yisaer commented Sep 9, 2020

ning chaos-controller-manager in ns chaos-control-plane, and create a IOChaos in another ns chaos-testing.

Or we should play in ONLY ONE name

For this question, my answer is no (do not split the manager and chaos in different namespaces). The origin demand for this feature is to limit the range for the chaos mesh (namespace scoped is common for the most controllers while it is more important for chaos-mesh comparing to other controllers as we do need to control the effected range by chaos-mesh)

And this question also remind me that the manager's servceiaccount should be bound by role instead of clusterRole. The role is the only way to guarantee that the manager won't affect other namespaces.

@STRRL
Copy link
Member Author

STRRL commented Sep 9, 2020

Hi @Yisaer mentor, I still do not figure out why. 😅

Deploying chaos-controller-manager and applications which are the target of chaos-testing into SAME namespace is DANGEROUS.

For example, if user using a bad selector, it might inject chaos into controller itself.

Other operators like prometheus-operator and openkruise have their own namespace which only running controller. I am very sure that your will NOT put your application into kube-prometheus orkube-system (doge.

And this question also remind me that the manager's servceiaccount should be bound by role instead of clusterRole. The role is the only way to guarantee that the manager won't affect other namespaces.

role and clusterRole is not the key, binding is the key. We could create a RoleBinding related to a ClusterRole. It is the way to grant a serviceaccount cross-namespace permissions.

It seems that we have opposite opinions, I am very pleasure to discuss this question on wechat or slack. :D

@Yisaer
Copy link
Contributor

Yisaer commented Sep 9, 2020

RoleBinding related to a ClusterRole is great! Thanks for pointing it out! @STRRL

In this way, deploying chaos-mesh into its own namespace and affecting other limit namespaces is ok to me.

@STRRL STRRL force-pushed the faeature-namespace-scoped-mode branch 2 times, most recently from d4dc2dc to 9d1349e Compare September 10, 2020 16:52
Signed-off-by: STRRL <str_ruiling@outlook.com>
Signed-off-by: STRRL <str_ruiling@outlook.com>
@STRRL STRRL force-pushed the faeature-namespace-scoped-mode branch from cccb5e9 to 3af5f80 Compare September 25, 2020 04:35
@STRRL
Copy link
Member Author

STRRL commented Sep 25, 2020

HI, @Yisaer , PTAL

@STRRL STRRL requested a review from Yisaer September 25, 2020 05:17
@cwen0
Copy link
Member

cwen0 commented Sep 25, 2020

@Gallardot @Yisaer PTAL

Signed-off-by: STRRL <str_ruiling@outlook.com>
Copy link
Member

@cwen0 cwen0 left a comment

Choose a reason for hiding this comment

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

LGTM

@cwen0
Copy link
Member

cwen0 commented Sep 25, 2020

/merge

@ti-srebot
Copy link
Contributor

/run-all-tests

@ti-srebot ti-srebot merged commit 212da2d into chaos-mesh:master Sep 25, 2020
@ti-srebot
Copy link
Contributor

cherry pick to release-1.0 failed

STRRL added a commit to STRRL/chaos-mesh that referenced this pull request Sep 25, 2020
STRRL added a commit to STRRL/chaos-mesh that referenced this pull request Sep 25, 2020
Signed-off-by: STRRL <str_ruiling@outlook.com>
STRRL added a commit to STRRL/chaos-mesh that referenced this pull request Sep 25, 2020
Signed-off-by: STRRL <str_ruiling@outlook.com>
STRRL added a commit to STRRL/chaos-mesh that referenced this pull request Sep 25, 2020
Signed-off-by: STRRL <str_ruiling@outlook.com>
cwen0 pushed a commit that referenced this pull request Sep 25, 2020
Signed-off-by: STRRL <str_ruiling@outlook.com>
@dcalvin dcalvin mentioned this pull request Feb 5, 2021
@STRRL STRRL deleted the faeature-namespace-scoped-mode branch February 23, 2021 06:18
sjwsl pushed a commit to sjwsl/chaos-mesh that referenced this pull request May 6, 2021
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.

None yet

6 participants