复现
task-nodejs.yaml
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: build-node-project
spec:
workspaces:
- name: cache
mountPath: /root/.npm
- name: source
- name: output
params:
- name: imgTag
type: string
- name: run
type: string
- name: dir
type: string
steps:
- name: build
workingDir: "$(workspaces.source.path)/$(params.dir)"
image: "node:$(params.imgTag)"
script: |
rm -rf package-lock.json
npm install --registry=https://registry.npmmirror.com/
npm run $(params.run)
cp -r dist/* $(workspaces.output.path)/
taskrun.yaml
apiVersion: tekton.dev/v1
kind: TaskRun
metadata:
generateName: build-node-project-run-
generation: 1
namespace: cicd-services
spec:
params:
- name: dir
value: frontend
- name: imgTag
value: 21.6.2
- name: run
value: build
serviceAccountName: default
taskRef:
kind: Task
name: build-node-project
workspaces:
- name: cache
persistentVolumeClaim:
claimName: node-cache-pvc
- name: source
persistentVolumeClaim:
claimName: test-tekton-vue-pvc
- name: output
persistentVolumeClaim:
claimName: test-tekton-vue-output-pvc
运行之后会出现下面报错
TaskRunValidationFailed [User error] more than one PersistentVolumeClaim is bound
原因
报错翻译TaskRunValidationFailed[用户错误]绑定了多个PersistentVolumeClaim
,很明确他允许绑定多个pvc,这个蛮离谱的,cicd的过程中用到多个存储应该是很正常的事,tekton却默认不支持绑定多个pvc。
解决
修改tekton的配置把参数disable-affinity-assistant
修改为true
,即可
kubectl -n tekton-pipelines edit cm feature-flags
这个参数的作用如下
设置为 true 将阻止 Tekton 为共享了 workspace 的每个 TaskRun 创建 Affinity Assistant Pod。 这样就可以保证这些 pod 运行在同一个节点上,避免了跨节点访问 pvc 的问题。
还有就是这个功能在v0.60会被弃用,未来估计不会因为这个问题报这个错了。
参考
ISSUE: https://github.com/tektoncd/pipeline/issues/6543
TektonDocs: https://github.com/tektoncd/pipeline/blob/main/docs/affinityassistants.md
配置参考: https://www.soulchild.cn/post/tekton-operator%E9%85%8D%E7%BD%AE%E5%8F%82%E6%95%B0%E8%AF%A6%E8%A7%A3/