tektoncd / catalog

Catalog of shared Tasks and Pipelines.
Apache License 2.0
664 stars 577 forks source link

pipelinerun fails in git-clone task #968

Closed sergio-tarazona closed 2 years ago

sergio-tarazona commented 2 years ago

Expected Behavior

I'm trying to execute the pipeline in this guide: https://hashnode.com/post/tekton-ci-simplified-ckzleauyw0n6beks1diq6ejvv It should clone a repo, then create an image and push it to docker hub.

Actual Behavior

I'm getting this error:

sergio@sergio-Inspiron-3493:~/tekton/test$ k logs nodejs-pipeline-run-w9gr6-git-clone-pod
+ '[' false '=' true ]
+ '[' false '=' true ]
+ '[' false '=' true ]
+ CHECKOUT_DIR=/workspace/output/
+ '[' true '=' true ]
+ cleandir
+ '[' -d /workspace/output/ ]
+ rm -rf '/workspace/output//*'
+ rm -rf /workspace/output//.git
+ rm -rf '/workspace/output//..?*'
+ test -z 
+ test -z 
+ test -z 
+ /ko-app/git-init '-url=https://github.com/avinashupadhya99/kubegen' '-revision=' '-refspec=' '-path=/workspace/output/' '-sslVerify=true' '-submodules=true' '-depth=1' '-sparseCheckoutDirectories='
{"level":"error","ts":1649719197.5870123,"caller":"git/git.go:54","msg":"Error running git [fetch --recurse-submodules=yes --depth=1 origin --update-head-ok --force HEAD]: exit status 128\nfatal: unable to access 'https://github.com/avinashupadhya99/kubegen/': Could not resolve host: github.com\n","stacktrace":"github.com/tektoncd/pipeline/pkg/git.run\n\tgithub.com/tektoncd/pipeline/pkg/git/git.go:54\ngithub.com/tektoncd/pipeline/pkg/git.Fetch\n\tgithub.com/tektoncd/pipeline/pkg/git/git.go:149\nmain.main\n\tgithub.com/tektoncd/pipeline/cmd/git-init/main.go:53\nruntime.main\n\truntime/proc.go:204"}
{"level":"fatal","ts":1649719197.5874116,"caller":"git-init/main.go:54","msg":"Error fetching git repository: failed to fetch [HEAD]: exit status 128","stacktrace":"main.main\n\tgithub.com/tektoncd/pipeline/cmd/git-init/main.go:54\nruntime.main\n\truntime/proc.go:204"}

Steps to Reproduce the Problem

Follow this steps: https://hashnode.com/post/tekton-ci-simplified-ckzleauyw0n6beks1diq6ejvv 1.Create the tasks (clone, lint, npm and kaniko) 2.Create the pipeline 3.Create the pipelinerun

  1. Check the logs

Additional Info

sergio@sergio-Inspiron-3493:~/tekton/test$ kubectl version
Client Version: version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.1", GitCommit:"5e58841cce77d4bc13713ad2b91fa0d961e69192", GitTreeState:"clean", BuildDate:"2021-05-12T14:18:45Z", GoVersion:"go1.16.4", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.10", GitCommit:"a7a32748b5c60445c4c7ee904caf01b91f2dbb71", GitTreeState:"clean", BuildDate:"2022-02-16T11:18:16Z", GoVersion:"go1.16.14", Compiler:"gc", Platform:"linux/amd64"}

sergio@sergio-Inspiron-3493:~/tekton/test$ tkn version
Client version: 0.23.1
Pipeline version: v0.34.1
Dashboard version: v0.25.0
vdemeester commented 2 years ago

@sergio-tarazona Looking at the error, either there is a network problem on the node the task was running or pods in your cluster do not have access to external network by default.

[…] unable to access 'https://github.com/avinashupadhya99/kubegen/': Could not resolve host: github.com […]

This is from the error you sent, and it says it cannot resolve github.com (aka no dns, no network, …)

sergio-tarazona commented 2 years ago

@vdemeester thanks for your feedback, I created a pod with the image git-init to check DNS resolution:

sergio@sergio-Inspiron-3493:~/tekton/test$ kubectl run git -ti --image=gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/git-init:v0.21.0 --command -- '/bin/sh'
If you don't see a command prompt, try pressing enter.

/ # nslookup github.com 
Server:     10.43.0.10
Address:    10.43.0.10:53

Non-authoritative answer:

Non-authoritative answer:
Name:   github.com
Address: 20.201.28.151

/ # nslookup github.com 
Server:     10.43.0.10
Address:    10.43.0.10:53

Non-authoritative answer:

Non-authoritative answer:
Name:   github.com
Address: 20.201.28.151

/ # nslookup github.com 
Server:     10.43.0.10
Address:    10.43.0.10:53

Name:   github.com
Address: 20.201.28.151

/ # nslookup github.com 
Server:     10.43.0.10
Address:    10.43.0.10:53

Name:   github.com
Address: 20.201.28.151

I don't know why it fails because the resolution seems ok, the workaround I found was to add this line in git-clone task:

echo "$(sed '2,$c nameserver 8.8.8.8' /etc/resolv.conf)" > /etc/resolv.conf

So far it's working.

Thanks, Sergio

mb-wali commented 1 year ago

@sergio-tarazona - I also have this issue, any update? how did you add this command: echo "$(sed '2,$c nameserver 8.8.8.8' /etc/resolv.conf)" > /etc/resolv.conf while running as non-root with fsgroup:65532?