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

Add stage_publish_dir field to csi_plugin stanza of a job #13919

Merged
merged 7 commits into from
Aug 2, 2022

Conversation

ejweber
Copy link
Contributor

@ejweber ejweber commented Jul 25, 2022

Resolves #13263.

This PR adds a new field to the csi_plugin stanza of a job that determines the base (inside a CSI plugin's container) of CSI staging_target_path and target_path directories.

This is my first PR to Nomad. I have attempted to go through the bullets in the checklist below. Some of the bullets are (I think) not applicable. For the docs, I tried to find all locations within /docs where CSI is mentioned and add the field as appropriate.

I updated comments on a couple of fields that I found to be confusing while trying to figure out where and how to get this implemented. I'm obviously open to reverting anything that the maintainers think is not an improvement.

Code

  • Consider similar features in Consul, Kubernetes, and other tools. Is there prior art we should match? Terminology, structure, etc?
  • Add structs/fields to api/ package
    • api/ structs usually have Canonicalize and Copy methods
    • New fields should be added to existing Canonicalize, Copy methods
    • Test the structs/fields via methods mentioned above
  • Add structs/fields to nomad/structs package
    • structs/ structs usually have Copy, Equals, and Validate methods
    • Validation happens in this package and must be implemented
    • Note that analogous struct field names should match with api/ package
    • Test the structs/fields via methods mentioned above
    • Implement and test other logical methods
  • Add conversion between api/ and nomad/structs/ in command/agent/job_endpoint.go
    • Add test for conversion
  • Determine JSON encoding strategy for responses from RPC (see "JSON Encoding" below)
    • Write nomad/structs/ to api/ conversions if necessary and write tests
  • Implement diff logic for new structs/fields in nomad/structs/diff.go
    • Note that fields must be listed in alphabetical order in FieldDiff slices in nomad/structs/diff_test.go
    • Add test for diff of new structs/fields
  • Add change detection for new structs/fields in scheduler/util.go/tasksUpdated
    • Might be covered by .Equals but might not be, check.
    • Should return true if the task must be replaced as a result of the change.

Docs

@hashicorp-cla
Copy link

hashicorp-cla commented Jul 25, 2022

CLA assistant check
All committers have signed the CLA.

api/tasks.go Outdated
// e.g. staging_target_path = {StagePublishDir}/staging/{volume-id}/{usage-mode}
// e.g. target_path = {StagePublishDir}/per-alloc/{alloc-id}/{volume-id}/{usage-mode}
// Default is /local/csi.
StagePublishDir string `mapstructure:"stage_publish_dir" hcl:"stage_publish_dir,optional"`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This naming may or may not be controversial (as a new part of Nomad's public API). I tried to make it as descriptive as possible, but I'm definitely open to other ideas.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah seems like a tricky name to get right. Maybe StagePublishBaseDir and stage_publish_base_dir?

@tgross
Copy link
Member

tgross commented Jul 27, 2022

Thanks @ejweber! I'm going to review this but just FYI we've got a bit of disruption going on this week with a team conference. I'll do my best to look at this early next week.

Copy link
Member

@tgross tgross left a comment

Choose a reason for hiding this comment

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

Looking good @ejweber! I've pulled this down locally and run my usual tests with a NFS plugin and everything seems to work as expected.

I've left a few comments, mostly around docs and naming. If you want, you can also add a changelog entry at .changelog/13919.txt, similar to ones like .changelog/12193.txt

@@ -103,6 +103,16 @@ func newCSIPluginSupervisorHook(config *csiPluginSupervisorHookConfig) *csiPlugi
socketMountPoint := filepath.Join(config.clientStateDirPath, "csi",
"plugins", config.runner.Alloc().ID)

// In v1.3.0, Nomad started instructing CSI plugins to stage and publish
// within /csi/local. Plugins deployed after the introduction of
Copy link
Member

Choose a reason for hiding this comment

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

The code is right but this comment has swapped the path ordering. It's /local/csi.

HostPath: h.mountPoint,
Readonly: false,
PropagationMode: "bidirectional",
}
h.logger.Info("", "volumeStagingMounts", volumeStagingMounts) // TODO: Remove this before merge.
Copy link
Member

Choose a reason for hiding this comment

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

Don't forget to remove this! 😀

api/tasks.go Outdated
// e.g. staging_target_path = {StagePublishDir}/staging/{volume-id}/{usage-mode}
// e.g. target_path = {StagePublishDir}/per-alloc/{alloc-id}/{volume-id}/{usage-mode}
// Default is /local/csi.
StagePublishDir string `mapstructure:"stage_publish_dir" hcl:"stage_publish_dir,optional"`
Copy link
Member

Choose a reason for hiding this comment

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

Yeah seems like a tricky name to get right. Maybe StagePublishBaseDir and stage_publish_base_dir?

@@ -1263,6 +1263,7 @@ func ApiCSIPluginConfigToStructsCSIPluginConfig(apiConfig *api.TaskCSIPluginConf
sc.ID = apiConfig.ID
sc.Type = structs.CSIPluginType(apiConfig.Type)
sc.MountDir = apiConfig.MountDir
sc.StagePublishDir = apiConfig.StagePublishDir
Copy link
Member

Choose a reason for hiding this comment

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

Good catch 👍 I've still got #10471 open to remove this whole gross blob of code but we'll need it for now.

website/content/docs/concepts/plugins/csi.mdx Outdated Show resolved Hide resolved
website/content/docs/job-specification/csi_plugin.mdx Outdated Show resolved Hide resolved
@tgross tgross moved this from Needs Triage to In Progress in Nomad - Community Issues Triage Aug 1, 2022
@tgross
Copy link
Member

tgross commented Aug 2, 2022

LGTM. I'll drop a changelog entry here in a sec and once CI is green we'll get this merged.

@ejweber
Copy link
Contributor Author

ejweber commented Aug 2, 2022

Thanks for the changelog entry @tgross. I ran out of time last night or I would have taken a stab at it.

@tgross tgross merged commit 07bbf1f into hashicorp:main Aug 2, 2022
Nomad - Community Issues Triage automation moved this from In Progress to Done Aug 2, 2022
@tgross tgross added this to the 1.3.3 milestone Aug 2, 2022
@github-actions
Copy link

github-actions bot commented Dec 1, 2022

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 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backport/1.3.x backport to 1.3.x release line theme/storage
Projects
Development

Successfully merging this pull request may close these issues.

Make the base of CSI staging_target_paths and target_paths configurable
3 participants