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

Pipeline Resource of type git doesn't properly handle revisions that are tags #2425

Closed
maxres-fr opened this issue Apr 16, 2020 · 3 comments
Closed
Labels
triage/duplicate Indicates an issue is a duplicate of other open issue.

Comments

@maxres-fr
Copy link

Expected Behavior

A resource type of git should fetch and check out a tag if the revision parameter is a git tag.

        resources:
            - name: git-repo
              resourceSpec:
                type: git
                params:
                  - name: revision
                    value: $(params.gitrevision)
                  - name: url
                    value: $(params.gitrepositoryurl)
                  - name: depth
                    value: "0"

Where params.gitrevision is a git tag.

I expected that the task's workspace would have the tag checked out. e.g where the tag is 2020-04-06-AllaNorma running git status should look like

❯ git status
HEAD detached at 2020-04-06-AllaNorma

Actual Behavior

Tags are not fetched, the tag isn't checked out. Logs indicate it was, but the repo remains on master and has no tag refs from the cloned remote.

task release-notes has failed: "step-release-notes" exited with code 2 (image: "docker-pullable://gcr.io/engineering-devops/repo@sha256:28eec9174775971423149a4b396b2f5be263aa3793e12dbe6bb1c4328711eaac"); for logs run: kubectl -n tekton-pipelines logs tag-release-run-2w2x9-release-notes-m29zp-pod-jx7fk -c step-release-notes
[release-notes : git-source-git-repo-4cl6s] {"level":"info","ts":1587071797.55442,"caller":"git/git.go:105","msg":"Successfully cloned https://github.com/maxres-fr/forgeops.git @ 2020.04.04-ramen.2 in path /workspace/git-repo"}
[release-notes : git-source-git-repo-4cl6s] {"level":"warn","ts":1587071797.554581,"caller":"git/git.go:152","msg":"Unexpected error: creating symlink: symlink /tekton/home/.ssh /root/.ssh: file exists"}
[release-notes : git-source-git-repo-4cl6s] {"level":"info","ts":1587071797.599526,"caller":"git/git.go:133","msg":"Successfully initialized and updated submodules in path /workspace/git-repo"}

[release-notes : release-notes] + git --no-pager tag --list
[release-notes : release-notes] + git fetch --tags origin
[release-notes : release-notes] From https://github.com/maxres-fr/forgeops
[release-notes : release-notes]  * [new branch]        cloud-2105-forgeops-release-notes -> origin/cloud-2105-forgeops-release-notes
[release-notes : release-notes]  * [new branch]        master             -> origin/master
[release-notes : release-notes]  * [new branch]        poc-pr             -> origin/poc-pr
[release-notes : release-notes]  * [new tag]           2020.04.04-ramen   -> 2020.04.04-ramen
[release-notes : release-notes]  * [new tag]           2020.04.04-ramen.1 -> 2020.04.04-ramen.1
[release-notes : release-notes]  * [new tag]           2020.04.04-ramen.2 -> 2020.04.04-ramen.2
[release-notes : release-notes] + git status
[release-notes : release-notes] On branch master

Steps to Reproduce the Problem

  1. create a task w/ git
  2. trigger task with a resourceSpec and the parameter set to a tag
  3. start trigger

Additional Info

  • Kubernetes version:

    Output of kubectl version:

❯ kubectl version
Client Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.0", GitCommit:"70132b0f130acc0bed193d9ba59dd186f0e634cf", GitTreeState:"clean", BuildDate:"2019-12-07T21:20:10Z", GoVersion:"go1.13.4", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"15+", GitVersion:"v1.15.11-gke.3", GitCommit:"71631703d37fb1b4b333abd427deae839aeb2032", GitTreeState:"clean", BuildDate:"2020-03-24T18:54:48Z", GoVersion:"go1.12.17b4", Compiler:"gc", Platform:"linux/amd64"}
  • Tekton Pipeline version:

    Output of tkn version or kubectl get pods -n tekton-pipelines -l app=tekton-pipelines-controller -o=jsonpath='{.items[0].metadata.labels.version}'

❯ tkn version
Client version: 0.8.0
Pipeline version: v0.11.1

Based on a conversation on the tektoncd slack channel, it's believed that the issue is in this func

pipeline/pkg/git/git.go

Lines 59 to 107 in 6b1579c

// Fetch fetches the specified git repository at the revision into path.
func Fetch(logger *zap.SugaredLogger, spec FetchSpec) error {
if err := ensureHomeEnv(logger); err != nil {
return err
}
if spec.Revision == "" {
spec.Revision = "master"
}
if spec.Path != "" {
if _, err := run(logger, "", "init", spec.Path); err != nil {
return err
}
if err := os.Chdir(spec.Path); err != nil {
return fmt.Errorf("failed to change directory with path %s; err: %w", spec.Path, err)
}
} else if _, err := run(logger, "", "init"); err != nil {
return err
}
trimmedURL := strings.TrimSpace(spec.URL)
if _, err := run(logger, "", "remote", "add", "origin", trimmedURL); err != nil {
return err
}
if _, err := run(logger, "", "config", "--global", "http.sslVerify", strconv.FormatBool(spec.SSLVerify)); err != nil {
logger.Warnf("Failed to set http.sslVerify in git config: %s", err)
return err
}
fetchArgs := []string{"fetch", "--recurse-submodules=yes"}
if spec.Depth > 0 {
fetchArgs = append(fetchArgs, fmt.Sprintf("--depth=%d", spec.Depth))
}
fetchArgs = append(fetchArgs, "origin", spec.Revision)
if _, err := run(logger, "", fetchArgs...); err != nil {
// Fetch can fail if an old commitid was used so try git pull, performing regardless of error
// as no guarantee that the same error is returned by all git servers gitlab, github etc...
if _, err := run(logger, "", "pull", "--recurse-submodules=yes", "origin"); err != nil {
logger.Warnf("Failed to pull origin : %s", err)
}
if _, err := run(logger, "", "checkout", spec.Revision); err != nil {
return err
}
} else if _, err := run(logger, "", "reset", "--hard", "FETCH_HEAD"); err != nil {
return err
}
logger.Infof("Successfully cloned %s @ %s in path %s", trimmedURL, spec.Revision, spec.Path)
return nil
}

@ghost
Copy link

ghost commented Apr 16, 2020

I believe this is a dupe of #2282 and should be resolved by #2320 ?

@bobcatfish
Copy link
Collaborator

Whoa cool! Sorry for putting you though writing up an issue about this @maxres-fr i didnt know about those others, but the good news is that it looks like we almost have a fix already :D

@bobcatfish bobcatfish added the triage/duplicate Indicates an issue is a duplicate of other open issue. label Apr 16, 2020
@maxres-fr
Copy link
Author

@sbwsg @bobcatfish going to close this, I missed that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage/duplicate Indicates an issue is a duplicate of other open issue.
Projects
None yet
Development

No branches or pull requests

2 participants