通过 TektonConfig 配置增强功能

本指南介绍如何使用 TektonConfig 和 spec.pipeline.options.configMaps 来管理增强功能配置。

命名空间说明:在本指南中,<tekton-pipelines> 用作你的 Tekton 命名空间占位符。请将其替换为你的实际命名空间名称。默认安装使用 tekton-pipelines 命名空间。

前提条件

  • 已安装 Tekton Operator。
  • TektonConfig 资源已存在(通常名为 config)。
  • 你可以在集群中编辑 TektonConfig。

步骤

1. 使用 spec.pipeline.options.configMaps 更新 TektonConfig

该 options 结构遵循与 调整子组件的可选配置项 中所述相同的模式。

使用如下 TektonConfig 补丁:

apiVersion: operator.tekton.dev/v1alpha1
kind: TektonConfig
metadata:
  name: config
spec:
  targetNamespace: <tekton-pipelines>
  pipeline:
    options:
      configMaps:
        tektoncd-enhancement-config:
          data:
            config: |
              # Shared configuration for enhancement features.
              template-render:
                # Template to build the details URL.
                details-url-template: "{{- if .isPipelineRun -}}{{ .platformURL }}/console-acp/workspace/{{ .project }}~{{ .cluster }}~{{ .namespace }}/pipeline/pipelineRuns/detail/{{ .pipelineRunName }}{{- else -}}{{ .platformURL }}/console-acp/workspace/{{ .project }}~{{ .cluster }}~{{ .namespace }}/pipeline/taskRuns/detail/{{ .taskRunName }}{{- end -}}"
                # Empty value means using the container local time zone.
                time-zone: ""
              pac-webhook-registration:
                # Register GitLab/GitHub webhooks for PAC Repository resources.
                # The default is true. Setting this to false deletes webhooks
                # previously managed by tektoncd-enhancement.
                enabled: true
                # Keep enabled in production.
                webhook-target-tls-verify: true

2. 参数参考与默认值

参数含义默认值
template-render.details-url-template用于邮件/模板渲染上下文中生成 detailsURL 的 Go template。{{- if .isPipelineRun -}}{{ .platformURL }}/console-acp/workspace/{{ .project }}~{{ .cluster }}~{{ .namespace }}/pipeline/pipelineRuns/detail/{{ .pipelineRunName }}{{- else -}}{{ .platformURL }}/console-acp/workspace/{{ .project }}~{{ .cluster }}~{{ .namespace }}/pipeline/taskRuns/detail/{{ .taskRunName }}{{- end -}}
template-render.time-zone模板渲染的全局时区设置。""(使用容器本地时区)
pac-webhook-registration.enabled为 PAC Repository 资源启用 GitLab/GitHub webhook 的自动注册。设置为 false 时,控制器会删除其此前管理过的提供商 webhook,并将 Repository 标记为 Disabled。true
pac-webhook-registration.webhook-target-tls-verifyGit 提供商在投递事件时是否验证 PAC webhook URL 的证书。true

PAC webhook 注册会从 pipelines-as-code-info.data.controller-url 读取公开的 webhook URL。请通过 PAC component options 配置该值;参见 获取 PAC Webhook URL。

要使用自动 webhook 注册,请将每个 PAC Repository 的 spec.git_provider.type 设置为 github 或 gitlab。不支持的类型会被跳过,并将原因记录为 Repository Event 和状态注解。

WARNING

将 pac-webhook-registration.enabled 设置为 false 不只是暂停后续注册。它还会移除此前由增强控制器创建或更新的 Git 提供商 webhook。请将其重新设置为 true,以便控制器再次调谐符合条件的 PAC Repository 资源并重新创建或更新其 webhook。

对于处于活动状态的 Repository 资源,必须先完成清理,控制器才会移除受管理的 webhook 注解和 finalizer。如果凭证缺失或提供商 API 暂时不可达,请修复凭证或提供商访问问题,控制器会重试。删除 Repository 则不同:提供商清理采用尽力而为方式,因此在记录清理警告后可以移除 Kubernetes finalizer。

3. 验证 ConfigMap 更新

更新 TektonConfig 后,检查受管理的 ConfigMap 是否已完成调谐:

kubectl get configmap tektoncd-enhancement-config -n <tekton-pipelines> -o yaml

Tekton Operator 会应用来自 TektonConfig 的配置。请勿直接更新受管理的 Deployment 或 ConfigMap,因为这些更改可能会在下一次调谐时被覆盖。

4. 对于启动时加载的设置,重启控制器

pac-webhook-registration.* 设置会在 ConfigMap 更新后热重载。template-render.* 设置会在增强控制器启动时加载,因此在更改 template-render.details-url-template 或 template-render.time-zone 后,请重启 tektoncd-enhancement-controller:

kubectl rollout restart deployment tektoncd-enhancement-controller -n <tekton-pipelines>
kubectl rollout status deployment tektoncd-enhancement-controller -n <tekton-pipelines>

FAQ

我已经更新了 TektonConfig,但实际配置没有变化。我应该检查什么?

请按以下顺序检查:

  1. TektonConfig 已成功更新。
  2. 命名空间 <tekton-pipelines> 中的 tektoncd-enhancement-config 具有预期的 data.config。
  3. Tekton Operator 已对最新的 TektonConfig 完成调谐。
  4. 如果你更改了任何 template-render.* 设置,请确认在 ConfigMap 更新后已重启 tektoncd-enhancement-controller。