tektoncd / pipeline

A cloud-native Pipeline resource.
https://tekton.dev
Apache License 2.0
8.44k stars 1.77k forks source link

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

Closed maxres-fr closed 4 years ago

maxres-fr commented 4 years ago

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

❯ 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"}
❯ 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 https://github.com/tektoncd/pipeline/blob/6b1579c89d75ec4e58c5630819429709e21f7332/pkg/git/git.go#L59-L107

ghost commented 4 years ago

I believe this is a dupe of #2282 and should be resolved by https://github.com/tektoncd/pipeline/pull/2320 ?

bobcatfish commented 4 years ago

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

maxres-fr commented 4 years ago

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