Skip to content
This repository has been archived by the owner on Jun 2, 2022. It is now read-only.

Implement Writable for the Volume plugin #771

Merged
merged 3 commits into from
Apr 17, 2020

Conversation

MikaelSmith
Copy link
Contributor

@MikaelSmith MikaelSmith commented Apr 14, 2020

Volumes now support writing content to files. Resolves #675.

Depends on #773 to ensure writes are immediately visible.

@MikaelSmith MikaelSmith marked this pull request as ready for review April 15, 2020 18:59
@MikaelSmith MikaelSmith requested a review from a team April 15, 2020 19:00
@ghost ghost requested review from ekinanp and removed request for a team April 15, 2020 19:00
volume/fs.go Outdated Show resolved Hide resolved
// VolumeWrite satisfies the Interface required by Write to write content to a file.
func (d *FS) VolumeWrite(ctx context.Context, path string, b []byte) error {
activity.Record(ctx, "Writing %v bytes to %v on %v", len(b), path, plugin.ID(d.executor))
command := d.selectShellCommand([]string{"cp", "/dev/stdin", path}, []string{"$input | Set-Content '" + path + "'"})
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we print the command that's running? If not, then we probably should. That would make it easier to make sense of the stdout:/stderr: output.

type doInContainerFn = func(containerDeleter) error

// Executes the callback while handling start and cleanup of an existing container.
func (v *volume) doInTemporaryContainer(ctx context.Context, cid string, fn doInContainerFn) error {
Copy link
Contributor

@ekinanp ekinanp Apr 16, 2020

Choose a reason for hiding this comment

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

Could createContainer's return signature be extended to (cid, deleteFunc, error), and make the post-condition be that it returns a running container? If so, then I don't think we need doInTemporaryContainer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I think so. At one point doInTemporaryContainer handled some of the defer calls, but that wasn't flexible enough.

@MikaelSmith MikaelSmith force-pushed the volume-write branch 2 times, most recently from ce95deb to bcccf34 Compare April 16, 2020 21:06
@MikaelSmith
Copy link
Contributor Author

I think this is ready again.

}
defer cleanup()

// Create a tar of the file contents and upload it.
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we tar'ing and copying? Some clarification would help. Seems weird that this is different from the Kubernetes PVC implementation.

Copy link
Contributor

Choose a reason for hiding this comment

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

Other than the clarification, PR looks good.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added. I suppose I could've done it with execs like everything else. That would avoid needing to pass in the permissions.

Copy link
Contributor

Choose a reason for hiding this comment

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

How hard would it be to do that? The inconsistency between this and Kube PVC is kind of weird.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll explore cleaning this up similar to Kubernetes.

I didn't add the same logic to identify an existing container because

  • Docker scheduling is a lot faster, so it's not much overhead compared to starting a new process
  • Docker doesn't have anything like ReadWriteOnce, so we can always get read/write access

Standardize and share more of the setup and teardown.

Signed-off-by: Michael Smith <michael.smith@puppet.com>
Volumes now support writing content to files.

Resolves puppetlabs-toy-chest#675.

Signed-off-by: Michael Smith <michael.smith@puppet.com>
Remove logging that's redundant because the API or FUSE layer already
logs the same info. Ensure each call to Exec logs what it's executing.

Signed-off-by: Michael Smith <michael.smith@puppet.com>
@MikaelSmith MikaelSmith merged commit 72896d6 into puppetlabs-toy-chest:master Apr 17, 2020
@MikaelSmith MikaelSmith deleted the volume-write branch April 17, 2020 18:27
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement Writable for Volumes
2 participants