使用 Hub Resolver 消费资源

功能概览

Tekton hub resolver 可以在 TektonConfig 将 Artifact Hub 端点指向 shim API 时,从 artifacthub-shim 获取远程 TaskPipelineStepAction 清单。

resolver 的 catalog 参数必须与 ConfigMap 支持的仓库对应的 repository.yaml gitRepositories[].repositories[].name 值匹配,或者是以下内置 catalog 名称之一:

内置 catalogKind
catalogtask
catalog-pipelinespipeline
catalog-stepactionsstepaction

只有当打包的 catalog 包含 stepaction/ 目录时,才会注册内置 StepAction catalog。

前提条件

  • 已安装并可用 artifacthub-shim
  • 已启用 Tekton hub resolver。
  • TektonConfig.spec.pipeline.hub-resolver-config.default-type 已设置为 artifact,或者每个引用都显式传递 type: artifact
  • default-tekton-hub-catalog 仍然设置为 catalog;当前 resolver 版本即使在 Artifact Hub 模式为默认值时也仍会读取该项。

引用 Task

taskRef 中使用远程 Task。

apiVersion: tekton.dev/v1
kind: TaskRun
metadata:
  name: run-remote-task
spec:
  taskRef:
    resolver: hub
    params:
      - name: type
        value: artifact
      - name: catalog
        value: catalog
      - name: kind
        value: task
      - name: name
        value: run-script
      - name: version
        value: "0.1.0"
  params:
    - name: script
      value: echo docs-verify

引用 Pipeline

pipelineRef 中使用远程 Pipeline。

apiVersion: tekton.dev/v1
kind: PipelineRun
metadata:
  name: run-remote-pipeline
spec:
  pipelineRef:
    resolver: hub
    params:
      - name: type
        value: artifact
      - name: catalog
        value: catalog-pipelines
      - name: kind
        value: pipeline
      - name: name
        value: build-deploy
      - name: version
        value: "0.2.0"

引用 StepAction

在 step 的 ref 中使用远程 StepAction。

apiVersion: tekton.dev/v1
kind: TaskRun
metadata:
  name: run-remote-stepaction
spec:
  taskSpec:
    steps:
      - name: echo
        ref:
          resolver: hub
          params:
            - name: type
              value: artifact
            - name: catalog
              value: catalog-stepactions
            - name: kind
              value: stepaction
            - name: name
              value: echo-message
            - name: version
              value: "0.1.0"

StepAction 引用应显式传递 catalog。当前 hub resolver 的默认值 仅包含 Artifact Hub 的 task 和 pipeline catalog 设置。

历史 Pipeline Catalog 兼容性

较旧的 Pipeline 引用可能会使用 catalog: catalog。新的引用应使用 catalog-pipelines,但 shim 会保留一个从 pipeline/catalogpipeline/catalog-pipelines 的内置 catalog 别名以保证兼容性。有关确切行为和建议的清理方式,请参阅 历史 Pipeline Catalog 引用

参数参考

ParameterDescriptionExample
typeHub 后端类型。对 artifacthub-shim 使用 artifactartifact
catalog由 shim 提供的 Artifact Hub 仓库名称。catalog
kindTekton 资源 kind。task
name资源包名称。run-script
version资源版本或受支持的版本约束。数字样式的值请使用引号括起。"0.1.0"

验证

如果资源未能解析,请先检查 TaskRunPipelineRun 状态:

kubectl get taskrun run-remote-task -o yaml

resolver 失败通常会在工作负载 Pod 创建之前出现。如果失败信息提到缺少 catalog、包或版本,请检查仓库 ConfigMap Events:

kubectl describe configmap <repository-configmap-name> \
  -n artifacthub-shim-system

查找 RepositorySourceReadyRepositorySourceInvalidRepositorySourceDegraded。仅当运行状态和仓库 Events 仍无法解释失败原因时,才使用 resolver 日志。

了解更多