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

Perform API discovery only as needed #8

Merged
merged 2 commits into from
Mar 27, 2023

Conversation

mprahl
Copy link
Contributor

@mprahl mprahl commented Mar 23, 2023

Generating a REST mapper is very expensive on the Kubernetes API. This approach just gets the information needed for the particular watch request and then caches the information.

This relates to this PR:
open-cluster-management-io/governance-policy-framework-addon#39

Copy link
Contributor

@JustinKuli JustinKuli left a comment

Choose a reason for hiding this comment

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

Should the items in the gvkToGVR cache ever expire? I didn't see any way for them to be refreshed - it seems like it only gets populated if it wasn't already present.

client/client.go Outdated Show resolved Hide resolved
Generating a REST mapper is very expensive on the Kubernetes API. This
approach just gets the information needed for the particular watch
request and then caches the information.

This relates to this PR:
open-cluster-management-io/governance-policy-framework-addon#39

Signed-off-by: mprahl <mprahl@users.noreply.github.com>
@mprahl
Copy link
Contributor Author

mprahl commented Mar 27, 2023

Should the items in the gvkToGVR cache ever expire? I didn't see any way for them to be refreshed - it seems like it only gets populated if it wasn't already present.

I didn't see a problem with this unless something funky happened with the CRDs and the resource was renamed but the kind was kept the same, but regardless, I added a cache expiration time of 10 minutes.

There seems to be a bug in the current version.

Signed-off-by: mprahl <mprahl@users.noreply.github.com>
@sonarcloud
Copy link

sonarcloud bot commented Mar 27, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

89.2% 89.2% Coverage
0.0% 0.0% Duplication

Copy link
Contributor

@JustinKuli JustinKuli left a comment

Choose a reason for hiding this comment

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

Should the items in the gvkToGVR cache ever expire? I didn't see any way for them to be refreshed - it seems like it only gets populated if it wasn't already present.

I didn't see a problem with this unless something funky happened with the CRDs and the resource was renamed but the kind was kept the same, but regardless, I added a cache expiration time of 10 minutes.

That would be pretty strange, but this seems quite robust now! Thanks for adding that. LGTM.

@openshift-ci openshift-ci bot added the lgtm label Mar 27, 2023
@openshift-ci
Copy link

openshift-ci bot commented Mar 27, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: JustinKuli, mprahl

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

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.

3 participants