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

Support 'ignore' mode in ConfigReconciler. #476

Merged
merged 1 commit into from
Mar 5, 2020

Conversation

sophieliu15
Copy link
Contributor

@sophieliu15 sophieliu15 commented Mar 2, 2020

This PR adds the support for 'ignore' mode in ConfigReconciler. Specifically, it adds following features:

  • If the mode of a type is set to 'ignore', the corresponding object reconciler will ignore all subsequent reconciliations (e.g., new or changed objects will not be propagated).
  • If the mode of a type is changed from 'ignore' to 'propagate', reconciliations for all existing objects of the type in the cluster will be triggered.
  • If a mode of a type is unrecognized, it will be treated as 'ignore'.
  • If a mode of a type is unset, it will be treated as 'propagate'.

Tested: GKE cluster; unit tests.

Design doc: http://bit.ly/hnc-type-configuration
Issue: #411

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Mar 2, 2020
@k8s-ci-robot
Copy link
Contributor

Hi @sophieliu15. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Mar 2, 2020
@sophieliu15
Copy link
Contributor Author

@adrianludwin and @yiqigao217 PTAL. As usual, I cannot change existing reviewers.

@adrianludwin
Copy link
Contributor

I'll review this when the other change goes in but for now:

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Mar 3, 2020
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Mar 3, 2020
@sophieliu15 sophieliu15 force-pushed the ignore branch 3 times, most recently from 0349e98 to 5f2c839 Compare March 3, 2020 16:32
sophieliu15 added a commit to sophieliu15/multi-tenancy that referenced this pull request Mar 3, 2020
This PR adds the support for 'remove' mode in ConfigReconciler. If the mode of a type is set to 'remove', all the propagated objects (i.e., objects created by HNC) of the type will be removed. However, source objects (i.e., objects created by users) of the type will not be removed.

Tested: GKE cluster; unit tests.

This PR contains changes introduced in kubernetes-retired#476.

Design doc: http://bit.ly/hnc-type-configuration
Issue: kubernetes-retired#411
incubator/hnc/pkg/forest/forest.go Outdated Show resolved Hide resolved
incubator/hnc/pkg/reconcilers/hnc_config.go Outdated Show resolved Hide resolved
incubator/hnc/pkg/reconcilers/hnc_config.go Outdated Show resolved Hide resolved
incubator/hnc/pkg/reconcilers/hnc_config.go Outdated Show resolved Hide resolved
incubator/hnc/pkg/reconcilers/hnc_config.go Outdated Show resolved Hide resolved
incubator/hnc/pkg/reconcilers/hnc_config.go Outdated Show resolved Hide resolved
incubator/hnc/pkg/reconcilers/hnc_config.go Outdated Show resolved Hide resolved
incubator/hnc/pkg/reconcilers/object.go Outdated Show resolved Hide resolved
incubator/hnc/pkg/reconcilers/object.go Outdated Show resolved Hide resolved
sophieliu15 added a commit to sophieliu15/multi-tenancy that referenced this pull request Mar 3, 2020
This PR adds the support for 'remove' mode in ConfigReconciler. If the mode of a type is set to 'remove', all the propagated objects (i.e., objects created by HNC) of the type will be removed. However, source objects (i.e., objects created by users) of the type will not be removed.

Tested: GKE cluster; unit tests.

This PR contains changes introduced in kubernetes-retired#476.

Design doc: http://bit.ly/hnc-type-configuration
Issue: kubernetes-retired#411
@adrianludwin
Copy link
Contributor

/lgtm
/approve
/hold
/assign @rjbez17

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 4, 2020
@rjbez17
Copy link

rjbez17 commented Mar 4, 2020

Bear with my dumb question here, but can you confirm the workflow in the following scenario?

  1. I deploy HNC, I set the Config to Remove objects of type Foo.Bar
  2. Foo.Bar Object types DNE on the cluster so it is set to Ignore
  3. I deploy a CRD of type Foo.Bar into the cluster
  4. ?

Looking at the code, it seems that Foo.Bar will be locked into Ignore until you essentially 'touch' the HNC Config. Is that correct? Is that desired? (I could have missed something in the code, I haven't had coffee yet)

I'm less concerned about Remove here as it wouldn't really matter in this usecase. But if we add more mode types in the future, I'd like to understand the flow.

Similarly, it'd seem that in step 1, if I explicitly set Foo.Bar to Propagate it would end up being Ignore while if I did not explicitly set it, it would be set to Propagate.

If we self correct without a manual 'touch' here then just ignore me :)

@k8s-ci-robot k8s-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Mar 4, 2020
@sophieliu15 sophieliu15 force-pushed the ignore branch 2 times, most recently from 3ba5dcd to 9fa1a42 Compare March 4, 2020 19:53
incubator/hnc/pkg/reconcilers/hnc_config.go Outdated Show resolved Hide resolved
incubator/hnc/pkg/reconcilers/hnc_config_test.go Outdated Show resolved Hide resolved
incubator/hnc/pkg/reconcilers/object.go Outdated Show resolved Hide resolved
incubator/hnc/pkg/reconcilers/object.go Outdated Show resolved Hide resolved
@sophieliu15
Copy link
Contributor Author

sophieliu15 commented Mar 4, 2020

Hi @rjbez17

IIUC, is your concern about configuring a custom resource in the HNCConfiguration object instead of build-in resource (e.g., roles, rolebindings, secrets)? That is a good point. I haven't considered supporting customized resource in
HNCConfiguration yet. Right now I am assuming the CRD exists before adding the type in the config (i.e., mostly I only consider types we previously supported in gvk.go). I experimented the workflow with the CronTab custom resource as defined here. Please see my comments below about current behaviors and desired behaviors.

Bear with my dumb question here, but can you confirm the workflow in the following scenario?

  1. I deploy HNC, I set the Config to Remove objects of type Foo.Bar

At this point, if Foo.Bar is a random type that hasn't been defined (i.e., CRD does not exist), we will not create an object reconciler for it.
For the config object, it will have an entry in Status indicating the object reconciler creation failed. Here is an example, CronTab is a random type that I haven't defined yet.

Spec:
  Types:
    API Version:  v1
    Kind:         CronTab
    Mode:         remove
    API Version:  rbac.authorization.k8s.io/v1
    Kind:         Role
    Mode:         propagate
    API Version:  rbac.authorization.k8s.io/v1
    Kind:         RoleBinding
    Mode:         propagate
Status:
  Conditions:
    Code:  objectReconcilerCreationFailed
    Msg:   Couldn't create ObjectReconciler for type stable.example.com/v1, Kind=CronTab: no matches for kind "CronTab" in version "stable.example.com/v1"

  1. Foo.Bar Object types DNE on the cluster so it is set to Ignore

We do not change the spec of config object, so if you look at the content of config object (above), you will see the Mode for Foo.Bar is what you set before (i.e., remove). In terms of the "mode" of object reconciler (you can think of that as the behavior of the object reconciler or the Mode field of the ObjectReconciler struct), it is not set to anything because the object reconciler does not even exists.

  1. I deploy a CRD of type Foo.Bar into the cluster

The object reconciler for Foo.Bar still does not exist; therefore, if you start to create Foo.Bar objects, it will not be propagated. This is the same behavior as ignore mode if the reconciler exists.

From my experiment, even you retouch the config object to trigger the reconciliation of ConfigReconciler, the object reconciler for Foo.Bar still cannot be created with the same error. Only when I reinstall HNC (make deploy), the object reconciler will be created.

Once the object reconciler is created, the mode of that object reconciler will be ignore because we treat remove as an unrecognized mode in this PR (see getValidateMode in object.go), but it will be remove mode once we support remove.

  1. ?

Looking at the code, it seems that Foo.Bar will be locked into Ignore until you essentially 'touch' the HNC Config. Is that correct? Is that desired? (I could have missed something in the code, I haven't had coffee yet)

The Foo.Bar objects will not be reconciled because the object reconciler for Foo.Bar does not exist. We will create object reconciler for it not after we retouch config object, but after we reinstall HNC.

This may not be ideal but I feel the solution might more on the documentation side than technical side. For example, we can add in the user guide that:

  • Only add type in config object if the type exists or
  • Reinstall HNC if they add a new CRD while the HNC is running.

At the same time, we can also add a feature when we implement the admission controller to automatically remove undefined type from the spec (not sure if this is feasible), but this does not solve the issue that we need to reinstall HNC to recognize custom resource defined while running HNC.

I'm less concerned about Remove here as it wouldn't really matter in this usecase. But if we add more mode types in the future, I'd like to understand the flow.

Similarly, it'd seem that in step 1, if I explicitly set Foo.Bar to Propagate it would end up being Ignore while if I did not explicitly set it, it would be set to Propagate.

For step 1, if the Foo.Bar type does not exist, the mode in Spec will be whatever you set it to be. However, this does not matter since the object reconciler for Foo.Bar does not exist.

If the type exists, Propagate and Ignore will still be Propagate and Ignore. If it is not set, it will be Propagate, anything else will be Ignore (including Remove until we start to support that mode). See details in getValidateMode in object.go

If we self correct without a manual 'touch' here then just ignore me :)

Feel free to let me know if there are any questions or your thoughts about this issue.

(Also add @adrianludwin in the discussion for his thoughts)

@sophieliu15 sophieliu15 force-pushed the ignore branch 2 times, most recently from cb46656 to 5a888a5 Compare March 4, 2020 22:16
This PR adds the support for 'ignore' mode in ConfigReconciler. Specifically, it adds following features:

If the mode of a type is set to 'ignore', the corresponding object reconciler will ignore all subsequent reconciliations (e.g., new or changed objects will not be propagated).
If the mode of a type is changed from 'ignore' to 'propagate', reconciliations for all existing objects of the type in the cluster will be triggered.
If a mode of a type is unrecognized, it will be treated as 'ignore'.
If a mode of a type is unset, it will be treated as 'propagate'.
Tested: GKE cluster; unit tests.

This PR includes changes introduced in kubernetes-retired#462

Design doc: http://bit.ly/hnc-type-configuration
Issue: kubernetes-retired#411
@adrianludwin
Copy link
Contributor

From my experiment, even you retouch the config object to trigger the reconciliation of ConfigReconciler, the object reconciler for Foo.Bar still cannot be created with the same error. Only when I reinstall HNC (make deploy), the object reconciler will be created.

This is a bug, and I'm pretty sure we can find a way to fix it - let's just file an issue for now. For example, we can add a watch onto CRD types - or maybe just use the webhook to stop it from happening. You can also always just kill the manager pod to restart HNC, you don't need to fully reinstall it.

@adrianludwin
Copy link
Contributor

@rjbez17 , did Sophie answer your questions?

@sophieliu15
Copy link
Contributor Author

From my experiment, even you retouch the config object to trigger the reconciliation of ConfigReconciler, the object reconciler for Foo.Bar still cannot be created with the same error. Only when I reinstall HNC (make deploy), the object reconciler will be created.

This is a bug, and I'm pretty sure we can find a way to fix it - let's just file an issue for now. For example, we can add a watch onto CRD types - or maybe just use the webhook to stop it from happening. You can also always just kill the manager pod to restart HNC, you don't need to fully reinstall it.

Fired #488 to track this issue.

sophieliu15 added a commit to sophieliu15/multi-tenancy that referenced this pull request Mar 5, 2020
This PR adds the support for 'remove' mode in ConfigReconciler. If the mode of a type is set to 'remove', all the propagated objects (i.e., objects created by HNC) of the type will be removed. However, source objects (i.e., objects created by users) of the type will not be removed.

Tested: GKE cluster; unit tests.

This PR contains changes introduced in kubernetes-retired#476.

Design doc: http://bit.ly/hnc-type-configuration
Issue: kubernetes-retired#411
sophieliu15 added a commit to sophieliu15/multi-tenancy that referenced this pull request Mar 5, 2020
This PR adds the support for 'remove' mode in ConfigReconciler. If the mode of a type is set to 'remove', all the propagated objects (i.e., objects created by HNC) of the type willbe removed. However, source objects (i.e., objects created by users) of the type will not be removed.

Tested: GKE cluster; unit tests.

This PR contains changes introduced in kubernetes-retired#476.

Design doc: http://bit.ly/hnc-type-configuration
Issue: kubernetes-retired#411
sophieliu15 added a commit to sophieliu15/multi-tenancy that referenced this pull request Mar 5, 2020
This PR adds the support for 'remove' mode in ConfigReconciler. If the mode of a type is set to 'remove', all the propagated objects (i.e., objects created by HNC) of the type willbe removed. However, source objects (i.e., objects created by users) of the type will not be removed.

Tested: GKE cluster; unit tests.

This PR contains changes introduced in kubernetes-retired#476.

Design doc: http://bit.ly/hnc-type-configuration
Issue: kubernetes-retired#411
@rjbez17
Copy link

rjbez17 commented Mar 5, 2020

/lgtm
/approve
/hold cancel

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: adrianludwin, rjbez17, sophieliu15

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,rjbez17]

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

@k8s-ci-robot k8s-ci-robot merged commit 4cba582 into kubernetes-retired:master Mar 5, 2020
sophieliu15 added a commit to sophieliu15/multi-tenancy that referenced this pull request Mar 5, 2020
This PR adds the support for 'remove' mode in ConfigReconciler. If the mode of a type is set to 'remove', all the propagated objects (i.e., objects created by HNC) of the type willbe removed. However, source objects (i.e., objects created by users) of the type will not be removed.

Tested: GKE cluster; unit tests.

This PR contains changes introduced in kubernetes-retired#476.

Design doc: http://bit.ly/hnc-type-configuration
Issue: kubernetes-retired#411
sophieliu15 added a commit to sophieliu15/multi-tenancy that referenced this pull request Mar 6, 2020
This PR adds the support for 'remove' mode in ConfigReconciler. If the mode of a type is set to 'remove', all the propagated objects (i.e., objects created by HNC) of the type willbe removed. However, source objects (i.e., objects created by users) of the type will not be removed.

Tested: GKE cluster; unit tests.

This PR contains changes introduced in kubernetes-retired#476.

Design doc: http://bit.ly/hnc-type-configuration
Issue: kubernetes-retired#411
sophieliu15 added a commit to sophieliu15/multi-tenancy that referenced this pull request Mar 6, 2020
This PR adds the support for 'remove' mode in ConfigReconciler. If the mode of a type is set to 'remove', all the propagated objects (i.e., objects created by HNC) of the type willbe removed. However, source objects (i.e., objects created by users) of the type will not be removed.

Tested: GKE cluster; unit tests.

This PR contains changes introduced in kubernetes-retired#476.

Design doc: http://bit.ly/hnc-type-configuration
Issue: kubernetes-retired#411
sophieliu15 added a commit to sophieliu15/multi-tenancy that referenced this pull request Mar 6, 2020
This PR adds the support for 'remove' mode in ConfigReconciler. If the mode of a type is set to 'remove', all the propagated objects (i.e., objects created by HNC) of the type willbe removed. However, source objects (i.e., objects created by users) of the type will not be removed.

Tested: GKE cluster; unit tests.

This PR contains changes introduced in kubernetes-retired#476.

Design doc: http://bit.ly/hnc-type-configuration
Issue: kubernetes-retired#411
sophieliu15 added a commit to sophieliu15/multi-tenancy that referenced this pull request Mar 6, 2020
This PR adds the support for 'remove' mode in ConfigReconciler. If the mode of a type is set to 'remove', all the propagated objects (i.e., objects created by HNC) of the type willbe removed. However, source objects (i.e., objects created by users) of the type will not be removed.

Tested: GKE cluster; unit tests.

This PR contains changes introduced in kubernetes-retired#476.

Design doc: http://bit.ly/hnc-type-configuration
Issue: kubernetes-retired#411
@sophieliu15 sophieliu15 deleted the ignore branch March 6, 2020 19:15
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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. 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.

5 participants