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

#587 - Disable caching for packageRevisionResources #55

Merged
merged 5 commits into from
May 27, 2024

Conversation

kushnaidu
Copy link
Contributor

@kushnaidu kushnaidu commented May 21, 2024

This change disables caching for packageRevisionResources in the porch controller.
Context -
The use case works for creating a PVS, but after someone creates a PVS, the controller logs are populated with errors saying the controllers cannot 'watch' the packageRevisionResources because there is no 'watch' function on the porch server side.
Example -
E0523 16:49:14.393038 1 reflector.go:140] pkg/mod/k8s.io/client-go@v0.26.9/tools/cache/reflector.go:169: Failed to watch *v1alpha1.PackageRevisionResources: the server does not allow this method on the requested resource (get packagerevisionresources.porch.kpt.dev)

Signed-off-by: Kushal Harish Naidu <kushal.harish.naidu@ericsson.com>
@nagygergo
Copy link
Contributor

This is a generated file based on kubebuilder directives in the controller go code. Please update those instead of this file.

@kushnaidu
Copy link
Contributor Author

This is a generated file based on kubebuilder directives in the controller go code. Please update those instead of this file.

Sure, I'll make the change.

Signed-off-by: Kushal Harish Naidu <kushal.harish.naidu@ericsson.com>
Copy link
Member

@liamfallon liamfallon left a comment

Choose a reason for hiding this comment

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

/approve

Looks fine to me, let's get some more reviews.

@@ -73,6 +73,8 @@ const (
//+kubebuilder:rbac:groups=config.porch.kpt.dev,resources=packagevariantsets/status,verbs=get;update;patch
//+kubebuilder:rbac:groups=config.porch.kpt.dev,resources=packagevariantsets/finalizers,verbs=update
//+kubebuilder:rbac:groups=config.porch.kpt.dev,resources=packagevariants,verbs=create;delete;get;list;patch;update;watch
//+kubebuilder:rbac:groups=porch.kpt.dev,resources=packagerevisions,verbs=create;delete;get;list;patch;update;watch
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we really need this, which I can't see why we do, maybe refine the roles to only the required ones. list and watch.

@@ -73,6 +73,8 @@ const (
//+kubebuilder:rbac:groups=config.porch.kpt.dev,resources=packagevariantsets/status,verbs=get;update;patch
//+kubebuilder:rbac:groups=config.porch.kpt.dev,resources=packagevariantsets/finalizers,verbs=update
//+kubebuilder:rbac:groups=config.porch.kpt.dev,resources=packagevariants,verbs=create;delete;get;list;patch;update;watch
//+kubebuilder:rbac:groups=porch.kpt.dev,resources=packagerevisions,verbs=create;delete;get;list;patch;update;watch
//+kubebuilder:rbac:groups=porch.kpt.dev,resources=packagerevisionresources,verbs=create;delete;get;list;patch;update;watch
Copy link
Collaborator

Choose a reason for hiding this comment

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

Update controllergen to v0.15.0 and run make generate.
As I mentioned, the setup here is a bit messy. The changes here only get generated if/when we run the "make generate" target. The updated Roles/Bindings are updated but the reality is that the catalog porch pkg itself needs to be updated also. https://github.com/nephio-project/catalog/blob/main/nephio/core/porch/9-porch-controller-packagevariantsets-clusterrole.yaml

Copy link
Contributor Author

@kushnaidu kushnaidu May 22, 2024

Choose a reason for hiding this comment

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

Hey Fiachra, yes, I have discussed with greg, we're trying to reproduce this issue and re-verify. Might need an update to the code itself. Also, I just re-used the same roles from packagevariant_controller.go. I will refactor this if it is still needed. I've added the do-not-merge label for now.

Signed-off-by: Kushal Harish Naidu <kushal.harish.naidu@ericsson.com>
@kushnaidu kushnaidu changed the title #587 - add missing packagerevision roles for PVS rbac #587 - Disable caching for packageRevisionResources May 23, 2024
@liamfallon
Copy link
Member

/remove-approve

@nagygergo
Copy link
Contributor

To my understanding the following is the issue:

  1. controller-runtime runs caching clients by default, where the resources are list-and-watched by default. Because of this, when packageVariant controller runs the following line, the controller-runtime client starts watching the packageRevisionResources: client.Get
  2. On the porch-server side, there is no implementation of watch for packageRevisionResources, only for packageRevisions. The porch-controllers gets back an error related to this from porch-server, and it gets printed out to the porch-controllers error log.

So the cache was never working, but instead of it failing back ungracefully to requesting the data every time, the cache is disabled by default.

An alternative solution could be that watch is implemented for packageRevisionResources. The metadata updates, including the resourceVersion is shared between the packageRevisions and packageRevisionResources. But because packageRevisionResources include all the data from the kpt package itself, building an in-memory cache of those might be quite expensive. And as I understand, there is no cache eviction policy, and packageRevisions are edited for a short time, then they become dormant as they get approved. All in all, I don't think it's a good idea for any client to cache packageRevisionResources.

@efiacor
Copy link
Collaborator

efiacor commented May 24, 2024

To my understanding the following is the issue:

1. controller-runtime runs caching clients by default, where the resources are list-and-watched by default. Because of this, when packageVariant controller runs the following line, the controller-runtime client starts watching the packageRevisionResources: [client.Get](https://github.com/nordix/porch/blob/07d5d898731592b234bae7e9e3d124df46415eab/controllers/packagevariants/pkg/controllers/packagevariant/packagevariant_controller.go#L766)

2. On the porch-server side, there is no implementation of watch for packageRevisionResources, only for packageRevisions. The porch-controllers gets back an error related to this from porch-server, and it gets printed out to the porch-controllers error log.

So the cache was never working, but instead of it failing back ungracefully to requesting the data every time, the cache is disabled by default.

An alternative solution could be that watch is implemented for packageRevisionResources. The metadata updates, including the resourceVersion is shared between the packageRevisions and packageRevisionResources. But because packageRevisionResources include all the data from the kpt package itself, building an in-memory cache of those might be quite expensive. And as I understand, there is no cache eviction policy, and packageRevisions are edited for a short time, then they become dormant as they get approved. All in all, I don't think it's a good idea for any client to cache packageRevisionResources.

Nice explanation. Thanks @nagygergo

@efiacor
Copy link
Collaborator

efiacor commented May 24, 2024

/approve

@nephio-prow nephio-prow bot added the approved label May 24, 2024
Signed-off-by: Kushal Harish Naidu <kushal.harish.naidu@ericsson.com>
@liamfallon
Copy link
Member

/approve

@liamfallon
Copy link
Member

/approve
/lgtm

Copy link
Contributor

nephio-prow bot commented May 27, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: efiacor, kushnaidu, liamfallon

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

@kushnaidu kushnaidu marked this pull request as ready for review May 27, 2024 12:58
@nephio-prow nephio-prow bot requested review from henderiw and tliron May 27, 2024 12:58
@nephio-prow nephio-prow bot merged commit a03a8d2 into nephio-project:main May 27, 2024
5 checks passed
@kushnaidu kushnaidu deleted the pvs-rbac-fix branch May 28, 2024 13:58
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.

4 participants