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

API: Add ResourceConversion service #1044

Merged
merged 3 commits into from
Aug 15, 2024
Merged

Conversation

toddtreece
Copy link
Member

@toddtreece toddtreece commented Aug 6, 2024

What this PR does / why we need it:

This adds a ResourceConversion service to the pluginv2 protobuf and removes ConvertObject from the AdmissionControl service.

Admission hooks are used in the write path (create, update, delete) and conversion is used in the read path, so this PR separates the concepts.

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:
I will add test coverage before this merges if the general approach seems acceptable

@toddtreece toddtreece requested a review from a team as a code owner August 6, 2024 18:18
@toddtreece toddtreece requested review from wbrowne, andresmgot, xnyo and ryantxu and removed request for a team August 6, 2024 18:18
// Raw is the serialized object
bytes raw = 1;
// ContentType is the media type of the raw object
string content_type = 2;
Copy link
Member Author

Choose a reason for hiding this comment

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

i was thinking that content_type would most likely always be application/json, but this would allow additional encodings if needed in the future


// Objects to convert
// +listType=atomic
repeated RawObject objects = 3;
Copy link
Member Author

Choose a reason for hiding this comment

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

@ryantxu the CRD webhook supports multiple objects, so i added support for that. i'm assuming that's used by list requests to reduce the number of round trips

// otherwise identical (parallel requests, etc).
// The UID is meant to track the round trip (request/response) between the Kubernetes API server and the webhook, not the user request.
// It is suitable for correlating log entries between the webhook and apiserver, for either auditing or debugging.
string uid = 2;
Copy link
Member Author

Choose a reason for hiding this comment

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

uid is also something that is present in CRD conversion webhooks, so this is forwarding that information in case it's useful for debugging

PluginContext pluginContext = 1;

// The object kind
GroupVersionKind kind = 2;
Copy link
Member

Choose a reason for hiding this comment

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

it looks like the new conversion request does not specify the source GVK -- is that accurate? Does that mean we need to parse the raw bytes to detect it first? Does k8s know the value before sending?

Copy link
Member Author

Choose a reason for hiding this comment

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

@ryantxu the version can be different for every object in the request. maybe a helper could turn this back into a function that handles one object at a time?

Copy link
Contributor

@andresmgot andresmgot left a comment

Choose a reason for hiding this comment

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

I don't see anything against this since ConvertObject is not yet being used but why the change? Which component will use it? Why the change from convert a single object to multiple ones?

@toddtreece
Copy link
Member Author

why the change?

@andresmgot admission hooks are used in the k8s write path before the object is sent to storage and conversion is used in the read path, so they are separate concepts. it's possible that many simpler APIs might not have a need to implement custom admission logic, but would have a need to convert between API versions.

Which component will use it?

this will be used by k8s apiserver conversion workflow or the CRD conversion webhook to convert from the stored version to the version the user requested

Why the change from convert a single object to multiple ones?

i added this context in a comment instead of the description because i thought it would be easier to discover during review, but i think lint rules buried it. multiple should reduce the number of requests during list operations

backend/conversion.go Outdated Show resolved Hide resolved
@@ -321,9 +321,6 @@ service AdmissionControl {

// Return a modified copy of the request that can be saved or a descriptive error
rpc MutateAdmission(AdmissionRequest) returns (MutationResponse);

// Convert a resource to a new version
rpc ConvertObject(ConversionRequest) returns (ConversionResponse);
Copy link
Member Author

Choose a reason for hiding this comment

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

@andresmgot @wbrowne how should i handle these lint failures?

Copy link
Member

Choose a reason for hiding this comment

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

These checks aren't required to merge and are primarily there (IIRC) to ensure people are aware/conscious of when breaking changes are being made. We use the FILE category for breaking detection so we know when clients will break. Since these services aren't used yet (even though plugins will have been built with this capability and Grafana is setup to call them), it should be safe. It wouldn't hurt to do some manual validation though.

I'd say if you want to be extra careful then just add the new stuff and just deprecate the other instead if possible:

  // Convert a resource to a new version
  rpc ConvertObject(ConversionRequest) returns (ConversionResponse) {
    option deprecated = true;
  };

Copy link
Member Author

Choose a reason for hiding this comment

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

good call. i'll test this out with grafana and a plugin using the previous SDK version before merging. i'll add the deprecated method if there are any issues

@toddtreece
Copy link
Member Author

@ryantxu @andresmgot i added test coverage, so i think this is ready for a final review

@ryantxu
Copy link
Member

ryantxu commented Aug 7, 2024

LGTM -- still experimental, so I expect we will iterate a bit more 😃

Copy link
Contributor

@andresmgot andresmgot left a comment

Choose a reason for hiding this comment

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

Cool, thanks for the extra context 👍

@toddtreece toddtreece force-pushed the toddtreece/resource-conversion branch from 4d994c9 to d191d41 Compare August 15, 2024 13:55
@toddtreece toddtreece merged commit 6158ec5 into main Aug 15, 2024
2 of 4 checks passed
@toddtreece toddtreece deleted the toddtreece/resource-conversion branch August 15, 2024 17:27
@toddtreece
Copy link
Member Author

tested with grafana/grafana#91977

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants