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

starting work on file assets builder #3085

Merged
merged 1 commit into from Aug 20, 2017

Conversation

chrislovecnm
Copy link
Contributor

@chrislovecnm chrislovecnm commented Jul 28, 2017

I refactored to the dockerassets pkg to assetstasks, in order to not add yet another package. Added file copy task, that I have tested with s3 locally, but not certain how to add memfs tests.

Fixes: #3086

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jul 28, 2017
@k8s-github-robot k8s-github-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 28, 2017
)

// AssetBuilder discovers and remaps assets
type FileAssetBuilder struct {
Copy link
Member

Choose a reason for hiding this comment

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

I think you could incorporate this into AssetBuilder, rather than needing a separate class, but we can see how it plays out..

if f.AssetsLocation != nil && f.AssetsLocation.FileRepository != nil {
fileURL, err := url.Parse(file)
if err != nil {
return "", fmt.Errorf("unable to parse file url: %q, %v", file, err)
Copy link
Member

Choose a reason for hiding this comment

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

typically ...file url %q: %v but NBD

fileRepo += "/"
}

fileAsset.File = fileRepo + "/" + fileURL.Path
Copy link
Member

Choose a reason for hiding this comment

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

Presumably we don't want the + "/" here given we just added it above?

kopsAssets *kops.Assets
}{
{
// FIXME - need https://s3.amazonaws.com/k8s-for-greeks-kops/kubernetes-release/release/v1.7.2/bin/linux/amd64/kubelet
Copy link
Member

Choose a reason for hiding this comment

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

I realized that - specifically for S3 - we can use a signed URL

}

// TODO SHA
// TODO need to map file in the same manner and include vfs and http location
Copy link
Member

Choose a reason for hiding this comment

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

Are these still outstanding?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Open question I have, and I updated the comment, is do we have the SHA url with the file URL.

}

func transferFile(source string, target string, sourceSHA string, sourceSHALocation string) error {
data, err := vfs.Context.ReadFile(source)
Copy link
Member

Choose a reason for hiding this comment

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

Ouch... these files could be big!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

testing worked ok, do we have another method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you want me to write the file to disk? I think it needs to be in memory in order to compare the SHAs anyways.

Copy link
Member

Choose a reason for hiding this comment

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

It's fine for now, but streaming is going to be preferable for big files, and that probably does mean a tempfile if you effectively have to do two passes (compare SHAs and then copy to a destination).


if sha != "" {

trimmedSHA := strings.TrimSuffix(sha, "\n")
Copy link
Member

Choose a reason for hiding this comment

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

TrimSpace might be easier

return err
}

b := bytes.NewBufferString(sha)
Copy link
Member

Choose a reason for hiding this comment

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

I think you can just use []byte(sha)

trimmedSHA := strings.TrimSuffix(sha, "\n")

in := bytes.NewReader(data)
dataHash, err := hashing.HashesForResource(in, []hashing.HashAlgorithm{hashing.HashAlgorithmSHA1})
Copy link
Member

Choose a reason for hiding this comment

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

You can use hashing.HashAlgorithmSHA1.Hash(in)

//path := strings.Join(pathSlice, "/")

// TODO I am not a huge fan of this, but it would work
// TODO @justinsb should we require an URL?
Copy link
Member

Choose a reason for hiding this comment

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

Yes, I would just have the task expect "real" vfs path strings, i.e. ones that would work with vfs.Context.BuildVfsPath. From a vfs.Path you can get the path using Path()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Need more context please

@justinsb
Copy link
Member

justinsb commented Aug 1, 2017

A few simplifications possible, and it would be great to get at least one usage of RemapFile so we can see whether FileAssetBuilder should be merged with AssetBuilder

@chrislovecnm
Copy link
Contributor Author

@justinsb I can refactor to just use on builder. Doing that now, and I have some questions

@k8s-github-robot
Copy link

@chrislovecnm PR needs rebase

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 4, 2017
Assets []*Asset
ContainerAssets []*ContainerAsset
FileAssets []*FileAsset
AssetsLocation *kops.Assets
Copy link
Member

Choose a reason for hiding this comment

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

Probably assetsLocation as I would guess no need to export (?), but NBD.

}

fileRepo := strings.TrimSuffix(*a.AssetsLocation.FileRepository, "/")
fileAsset.File = fileRepo + fileURL.Path
Copy link
Member

Choose a reason for hiding this comment

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

It may turn out we want the Host in here also, as otherwise we risk collisions (and it'll be more self explanation with the Host I would guess), but we can see how it goes...

kopsAssets *kops.Assets
}{
{
// FIXME - need https://s3.amazonaws.com/k8s-for-greeks-kops/kubernetes-release/release/v1.7.2/bin/linux/amd64/kubelet
Copy link
Member

Choose a reason for hiding this comment

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

We do, but this only applies to nodeup, right? Because AIUI once we are in nodeup we can (more) easily download from a secured bucket. But nodeup is tricky, and we either want to remap or use a signed URL.

We can also remap on the upload, i.e. we can recognize that a write to https://s3.amazonaws.com/k8s-for-greeks-kops/ becomes a write to s3://k8s-for-greeks-kops/, using a public ACL.

To my mind, a signed URL is going to be best, because I don't think people that want to run mirrors are going to love the idea of public buckets.

Not sure if this FIXME is a blocker for merge? I'm guessing not, because it doesn't cause any regression in existing behaviour (i.e. this doesn't work yet anyway)?

SourceFile *string
TargetFile *string
// @justinsb not sure I like this but the problem is knowing if the sha is a file or a string
// so I did a location or a sha. We have both SHAs in remote file locations, and SHAs in strings
Copy link
Member

Choose a reason for hiding this comment

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

I'm saying when you build CopyFile, you can the SHA URL at that time, so that CopyFile always has a SHA directly in a string value.

}

func transferFile(source string, target string, sourceSHA string, sourceSHALocation string) error {
data, err := vfs.Context.ReadFile(source)
Copy link
Member

Choose a reason for hiding this comment

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

It's fine for now, but streaming is going to be preferable for big files, and that probably does mean a tempfile if you effectively have to do two passes (compare SHAs and then copy to a destination).


b := bytes.NewBufferString(sha)
if err := writeFile(shaVFS, b.Bytes()); err != nil {
return fmt.Errorf("Error uploading file %q: %v", shaVFS, err)
Copy link
Member

Choose a reason for hiding this comment

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

Writing the target file before writing the target SHA is going to be safer..

@justinsb
Copy link
Member

justinsb commented Aug 6, 2017

A few suggestions but can be done as the code evolves.

I believe this is additive - only comes in to play if users configure an assetLocation, so LGTM

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 6, 2017
@k8s-github-robot
Copy link

/lgtm cancel //PR changed after LGTM, removing LGTM. @chrislovecnm @justinsb

@k8s-github-robot k8s-github-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Aug 11, 2017
@k8s-github-robot
Copy link

@chrislovecnm PR needs rebase

@justinsb
Copy link
Member

Needs rebase again but then LGTM

@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 18, 2017
@chrislovecnm
Copy link
Contributor Author

@justinsb needs another lgtm, as I do not like self merging :(

@justinsb
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 20, 2017
@k8s-github-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: chrislovecnm, justinsb

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these OWNERS Files:
  • OWNERS [chrislovecnm,justinsb]

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-github-robot
Copy link

/test all [submit-queue is verifying that this PR is safe to merge]

@k8s-github-robot
Copy link

Automatic merge from submit-queue

@k8s-github-robot k8s-github-robot merged commit 9c86800 into kubernetes:master Aug 20, 2017
@chrislovecnm chrislovecnm deleted the file-asset-tasks branch December 30, 2017 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants