7.2. 将 Pipelines 配置为代码日志记录
您可以通过编辑 TektonConfig
自定义资源(CR)中的 pac-config-logging
配置映射将 Pipelines 配置为代码日志。
先决条件
- 在集群中安装了 Pipelines as Code。
流程
-
在 Web 控制台的 Administrator 视角中,进入 Administration
CustomResourceDefinitions。 -
使用 Search by name 字段搜索
tektonconfigs.operator.tekton.dev
自定义资源定义(CRD),然后点 TektonConfig 查看 CRD Details 页面。 - 点 实例 选项卡。
-
点 config 实例查看
TektonConfig
CR 详情。 - 点 YAML 标签。
根据您的要求,编辑
.options.configMaps.pac-config-logging.data
参数下的loglevel.
字段。将 Pipelines as Code 日志级别字段设置为
warn
的TektonConfig
CR 示例apiVersion: operator.tekton.dev/v1alpha1 kind: TektonConfig metadata: name: config spec: platforms: openshift: pipelinesAsCode: options: configMaps: pac-config-logging: data: loglevel.pac-watcher: warn 1 loglevel.pipelines-as-code-webhook: warn 2 loglevel.pipelinesascode: warn 3 zap-logger-config: | { "level": "info", "development": false, "sampling": { "initial": 100, "thereafter": 100 }, "outputPaths": ["stdout"], "errorOutputPaths": ["stderr"], "encoding": "json", "encoderConfig": { "timeKey": "ts", "levelKey": "level", "nameKey": "logger", "callerKey": "caller", "messageKey": "msg", "stacktraceKey": "stacktrace", "lineEnding": "", "levelEncoder": "", "timeEncoder": "iso8601", "durationEncoder": "", "callerEncoder": "" } }
可选:通过更改
.options.deployments
字段中每个组件的.env.value
,为 Pipelines 作为代码组件创建一个自定义日志配置映射。以下示例显示了带有名为custom-pac-config-logging
的自定义配置映射的配置。带有 Pipelines as Code 自定义日志配置映射的
TektonConfig
CR 示例apiVersion: operator.tekton.dev/v1alpha1 kind: TektonConfig metadata: name: config spec: platforms: openshift: pipelinesAsCode: enable: true options: configMaps: custom-pac-config-logging: data: loglevel.pac-watcher: warn loglevel.pipelines-as-code-webhook: warn loglevel.pipelinesascode: warn zap-logger-config: | { "level": "info", "development": false, "sampling": { "initial": 100, "thereafter": 100 }, "outputPaths": ["stdout"], "errorOutputPaths": ["stderr"], "encoding": "json", "encoderConfig": { "timeKey": "ts", "levelKey": "level", "nameKey": "logger", "callerKey": "caller", "messageKey": "msg", "stacktraceKey": "stacktrace", "lineEnding": "", "levelEncoder": "", "timeEncoder": "iso8601", "durationEncoder": "", "callerEncoder": "" } } deployments: pipelines-as-code-controller: spec: template: spec: containers: - name: pac-controller env: - name: CONFIG_LOGGING_NAME value: custom-pac-config-logging pipelines-as-code-watcher: spec: template: spec: containers: - name: pac-watcher env: - name: CONFIG_LOGGING_NAME value: custom-pac-config-logging pipelines-as-code-webhook: spec: template: spec: containers: - name: pac-webhook env: - name: CONFIG_LOGGING_NAME value: custom-pac-config-logging