Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

CSI: replace structs->api with serialization extension #12583

Merged
merged 1 commit into from
Apr 15, 2022

Conversation

tgross
Copy link
Member

@tgross tgross commented Apr 15, 2022

Fixes #10470

The CSI HTTP API has to transform the CSI volume to redact secrets,
remove the claims fields, and to consolidate the allocation stubs into
a single slice of alloc stubs. This was done manually in #8590 but
this is a large amount of code and has proven both very bug prone
(see #8659, #8666, #8699, #8735, and #12150) and requires updating
lots of code every time we add a field to volumes or plugins.

In #10202 we introduce encoding improvements for the Node struct
that allow a more minimal transformation. Apply this same approach to
serializing structs.CSIVolume to API responses.

Also, the original reasoning behind #8590 for plugins no longer holds
because the counts are now denormalized within the state store, so we
can simply remove this transformation entirely.


I don't think this needs a changelog? It's not a user-facing behavior change and #10202 didn't include one.

I've tested this change by running capturing the output of nomad volume status :volume_id, nomad plugin status :plugin_id, nomad operator api /v1/volume/csi/:volume_id | jq . and nomad operator api '/v1/plugin/csi/:plugin_id' | jq . for the following interesting states:

  • plugin with only one type (controllers vs nodes)
  • plugin with both types
  • unclaimed volume
  • claimed volume

I then captured the outputs before and after the update and compared them with diff to verify that nothing other than timestamps have changed.

The CSI HTTP API has to transform the CSI volume to redact secrets,
remove the claims fields, and to consolidate the allocation stubs into
a single slice of alloc stubs. This was done manually in #8590 but
this is a large amount of code and has proven both very bug prone
(see #8659, #8666, #8699, #8735, and #12150) and requires updating
lots of code every time we add a field to volumes or plugins.

In #10202 we introduce encoding improvements for the `Node` struct
that allow a more minimal transformation. Apply this same approach to
serializing `structs.CSIVolume` to API responses.

Also, the original reasoning behind #8590 for plugins no longer holds
because the counts are now denormalized within the state store, so we
can simply remove this transformation entirely.
@tgross tgross marked this pull request as ready for review April 15, 2022 15:26
Copy link
Member

@shoenig shoenig left a comment

Choose a reason for hiding this comment

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

LGTM!

@@ -8,8 +8,10 @@ var (
// extendedTypes is a mapping of extended types to their extension function
// TODO: the duplicates could be simplified by looking up the base type in the case of a pointer type in ConvertExt
Copy link
Member

Choose a reason for hiding this comment

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

totally untested (and unnecessary), but you might also be able to re-frame this map as a type switch with the 2 types per case statement

Copy link
Member Author

Choose a reason for hiding this comment

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

It looks like we could that in ConvertExt but we'd still need the list for calling SetInterfaceExt on the codec in NomadJsonEncodingExtensions

@tgross
Copy link
Member Author

tgross commented Apr 15, 2022

I'm going to plan on picking up #10471 in the next little bit as well. It'll be nice to ditch a bunch of this old grotty code.

@tgross tgross merged commit 0c2732d into main Apr 15, 2022
@tgross tgross deleted the csi-better-plugin-json-serialization branch April 15, 2022 18:29
@tgross tgross added this to the 1.3.0 milestone Aug 23, 2022
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 24, 2022
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

replace structs.CSIPlugin -> api.CSIPlugin conversion
2 participants