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

Allow user to specify git clone directory in gitRepo volume #15533

Merged
merged 1 commit into from Dec 1, 2015

Conversation

resouer
Copy link
Contributor

@resouer resouer commented Oct 13, 2015

Fix #15421

@k8s-bot
Copy link

k8s-bot commented Oct 13, 2015

Can one of the admins verify that this patch is reasonable to test? (reply "ok to test", or if you trust the user, reply "add to whitelist")

If this message is too spammy, please complain to ixdy.

@k8s-github-robot
Copy link

Labelling this PR as size/M

@k8s-github-robot k8s-github-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 13, 2015
@ncdc
Copy link
Member

ncdc commented Oct 13, 2015

@kubernetes/rh-cluster-infra @kubernetes/rh-storage @kubernetes/rh-dev-experience @kubernetes/rh-ux

} else {
if output, err := b.execCommand("git", []string{"clone", b.source}, dir); err != nil {
return fmt.Errorf("failed to exec 'git clone %s': %s: %v", b.source, output, err)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

More concise this way and also supports N git args in the error message:

    args := []string{"clone", b.source}
    if b.target != "" {
        args = append(args, b.target)
    }
    if output, err := b.execCommand("git", args, dir); err != nil {
        return fmt.Errorf("failed to exec 'git %s': %s: %v", strings.Join(append(args[:1], args[1:len(args)]...), " "), output, err)
    }

Copy link
Contributor

Choose a reason for hiding this comment

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

Will this part fail if you specify a target? The current implementation assumes there will be exactly 1 directory (the repo name) in the volume.

if len(files) != 1 {
        return fmt.Errorf("unexpected directory contents: %v", files)
    }

I couldn't comment on that line in the diff because you didn't edit it.

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 will fail when clone directory is '.'

Actually, see my comments here: #15421 (comment)

I'd like to update the code if we reached a agreement.

Copy link
Member

Choose a reason for hiding this comment

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

As per #15421

How urgent is this one small feature? I'm not deeply against adding it if
it solves real problems, but I'd rather focus energy on the git-sync
sidecar. Additionally, we need clarity on whether this is just "checkout
and rename" or whether "." is expected to be supported. Doing a checkout to
a subdir has one significant advantage - it can be updated atomically. This
means you could periodically sync to head of a branch, which seems like a
powerful feature to me.

If we support ".", that does not work.

On Wed, Oct 14, 2015 at 12:54 AM, Harry Zhang notifications@github.com
wrote:

In pkg/volume/git_repo/git_repo.go
#15533 (comment)
:

@@ -138,8 +140,15 @@ func (b *gitRepoVolumeBuilder) SetUpAt(dir string) error {
return err
}

  • if output, err := b.execCommand("git", []string{"clone", b.source}, dir); err != nil {
  •   return fmt.Errorf("failed to exec 'git clone %s': %s: %v", b.source, output, err)
    
  • // If provided target directory
  • if "" != b.target {
  •   if output, err := b.execCommand("git", []string{"clone", b.source, b.target}, dir); err != nil {
    
  •       return fmt.Errorf("failed to exec 'git clone %s %s': %s: %v", b.source, b.target, output, err)
    
  •   }
    
  • } else {
  •   if output, err := b.execCommand("git", []string{"clone", b.source}, dir); err != nil {
    
  •       return fmt.Errorf("failed to exec 'git clone %s': %s: %v", b.source, output, err)
    
  •   }
    
    }

This will fail when clone directory is '.'

Actually, see my comments here: #15421 (comment)
#15421 (comment)

I'd like to update the code if we reached a agreement.


Reply to this email directly or view it on GitHub
https://github.com/kubernetes/kubernetes/pull/15533/files#r41964131.

@resouer resouer force-pushed the git-volume branch 3 times, most recently from b86afb4 to 4ae9844 Compare October 17, 2015 04:38
@resouer
Copy link
Contributor Author

resouer commented Oct 17, 2015

@markturansky Although discusss is in progess in original issue, I updated this with tests

@resouer resouer force-pushed the git-volume branch 2 times, most recently from 5ebab60 to e70b708 Compare October 17, 2015 14:19
@k8s-github-robot k8s-github-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 17, 2015
@k8s-github-robot
Copy link

Labelling this PR as size/XXL

@resouer
Copy link
Contributor Author

resouer commented Oct 17, 2015

serialization_test.go continually fails unless I run ./hack/update-codecgen.sh, which leads to a huge change ... don't know how to solve this for now ...

return fmt.Errorf("unexpected directory contents: %v", files)
}
subdir = path.Join(dir, files[0].Name())
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Better to use switch over if/else:

switch {
case b.target == "":
case b.target != "" && len(files) == 1:
case b.target != && len(files) != 1
}

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 21, 2015
@k8s-bot
Copy link

k8s-bot commented Oct 21, 2015

Can one of the admins verify that this patch is reasonable to test? (reply "ok to test", or if you trust the user, reply "add to whitelist")

If this message is too spammy, please complain to ixdy.

if len(files) != 1 {
return fmt.Errorf("unexpected directory contents: %v", files)
}

if len(b.revision) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

len(b.revision) == 0 and b.target != "" are the same (in effect) but different implementations. They should be consistent. I've mostly seen (and used) empty string "" comparison instead of string length check.

@markturansky
Copy link
Contributor

What kind of validation is required for the target directory? "." and a path are valid. Is "../path" valid? numbers/spaces/special characters?

What's the worst someone can put into the target string?

@resouer
Copy link
Contributor Author

resouer commented Oct 24, 2015

@markturansky I don't think numbers/special characters are harmful, at firs glance.
But I can see path abusing will be a hidden trouble, for example, clone to any places out of the volume path.
So, need to restrict directory to:

  1. relative path
  2. not '..'
  3. no spaces

Or, we can only allow: [a-z][0-9][.], and refuse others. I prefer this way in this PR.

@k8s-github-robot
Copy link

Labelling this PR as size/XS

@k8s-github-robot k8s-github-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Dec 1, 2015
@k8s-bot
Copy link

k8s-bot commented Dec 1, 2015

GCE e2e test build/test passed for commit d051cc1de6ab715ea7e8a00b36c26a3ddeb4ffc9.

@k8s-bot
Copy link

k8s-bot commented Dec 1, 2015

GCE e2e test build/test passed for commit d65fedc29537b502671115658a25e8204eb2246a.

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 1, 2015
@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 1, 2015
@k8s-github-robot
Copy link

Labelling this PR as size/L

@k8s-github-robot k8s-github-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Dec 1, 2015
@k8s-bot
Copy link

k8s-bot commented Dec 1, 2015

GCE e2e test build/test passed for commit e6ff227aa79ebea18082ace79b473489c9bfb98c.

Update validate and gitRepo

Update generated code
@pmorie pmorie added lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-merge labels Dec 1, 2015
@pmorie pmorie assigned pmorie and unassigned thockin Dec 1, 2015
@k8s-github-robot
Copy link

Continuous integration appears to have missed, closing and re-opening to trigger it

@k8s-bot
Copy link

k8s-bot commented Dec 1, 2015

GCE e2e test build/test passed for commit 70a9c0b.

@k8s-github-robot
Copy link

@k8s-bot test this [submit-queue is verifying that this PR is safe to merge]

@k8s-bot
Copy link

k8s-bot commented Dec 1, 2015

GCE e2e test build/test passed for commit 70a9c0b.

@k8s-github-robot
Copy link

Automatic merge from submit-queue

k8s-github-robot pushed a commit that referenced this pull request Dec 1, 2015
Auto commit by PR queue bot
@k8s-github-robot k8s-github-robot merged commit 727412c into kubernetes:master Dec 1, 2015
@resouer resouer deleted the git-volume branch December 2, 2015 01:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet