首页 > 其他分享 >tekton TriggerBinding资源

tekton TriggerBinding资源

时间:2022-12-16 23:06:00浏览次数:45  
标签:git name triggers tekton params TriggerBinding message 资源


公众号:

tekton TriggerBinding资源_云原生


什么是TriggerBinding

校验事件并提取相关字段属性

资源详解

例子

triggerBinding/binding.yaml

apiVersion: triggers.tekton.dev/v1alpha1
kind: TriggerBinding
metadata:
name: binding
spec:
params:
- name: gitrevision
value: $(body.head_commit.id)
- name: gitrepositoryurl
value: $(body.repository.url)
- name: contenttype
value: $(header.Content-Type)


表达式


$(body) -> "{"key1": "value1", "key2": {"key3": "value3"}, "key4": ["value4", "value5", "value6"]}"

$(body.key1) -> "value1"

$(body.key2) -> "{"key3": "value3"}"

$(body.key2.key3) -> "value3"

$(body.key4[0]) -> "value4"

$(body.key4[0:2]) -> "{"value4", "value5"}"

# $(header) is replaced by all of the headers from the event.

$(header) -> "{"One":["one"], "Two":["one","two","three"]}"

$(header.One) -> "one"

$(header.one) -> "one"

$(header.Two) -> "one two three"

$(header.Two[1]) -> "two"


多绑定

triggerBinding/multi-binding.yaml


apiVersion: triggers.tekton.dev/v1alpha1
kind: TriggerBinding
metadata:
name: event-binding
spec:
params:
- name: gitrevision
value: $(body.head_commit.id)
- name: gitrepositoryurl
value: $(body.repository.url)
---
apiVersion: triggers.tekton.dev/v1alpha1
kind: TriggerBinding
metadata:
name: prod-env
spec:
params:
- name: environment
value: prod
---
apiVersion: triggers.tekton.dev/v1alpha1
kind: TriggerBinding
metadata:
name: staging-env
spec:
params:
- name: environment
value: staging
---
apiVersion: triggers.tekton.dev/v1alpha1
kind: EventListener
metadata:
name: listener
spec:
triggers:
- name: prod-trigger
bindings:
- ref: event-binding
- ref: prod-env
template:
ref: pipeline-template
- name: staging-trigger
bindings:
- ref: event-binding
- ref: staging-env
template:
ref: pipeline-template


ClusterTriggerBinding

triggerBinding/cluster/message-clusterbinding.yaml

apiVersion: triggers.tekton.dev/v1alpha1
kind: ClusterTriggerBinding
metadata:
name: message-clusterbinding
spec:
params:
- name: message
value: Hello from the Triggers EventListener!

triggerBinding/cluster/pipeline-clusterbinding.yaml

apiVersion: triggers.tekton.dev/v1alpha1
kind: ClusterTriggerBinding
metadata:
name: pipeline-clusterbinding
spec:
params:
- name: gitrevision
value: $(body.head_commit.id)
- name: gitrepositoryurl
value: $(body.repository.url)
- name: contenttype
value: $(header.Content-Type)


triggerBinding/cluster/sa-rbac.yaml

apiVersion: v1
kind: ServiceAccount
metadata:
name: tekton-triggers-example-sa
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: tekton-triggers-example-minimal
rules:
# EventListeners need to be able to fetch all namespaced resources
- apiGroups: ["triggers.tekton.dev"]
resources: ["eventlisteners", "triggerbindings", "triggertemplates", "triggers"]
verbs: ["get", "list", "watch"]
- apiGroups: [""]
# configmaps is needed for updating logging config
resources: ["configmaps"]
verbs: ["get", "list", "watch"]
# Permissions to create resources in associated TriggerTemplates
- apiGroups: ["tekton.dev"]
resources: ["pipelineruns", "pipelineresources", "taskruns"]
verbs: ["create"]
- apiGroups: [""]
resources: ["serviceaccounts"]
verbs: ["impersonate"]
- apiGroups: ["policy"]
resources: ["podsecuritypolicies"]
resourceNames: ["tekton-triggers"]
verbs: ["use"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: tekton-triggers-example-binding
subjects:
- kind: ServiceAccount
name: tekton-triggers-example-sa
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: tekton-triggers-example-minimal
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: tekton-triggers-example-clusterrole
rules:
# EventListeners need to be able to fetch any clustertriggerbindings
- apiGroups: ["triggers.tekton.dev"]
resources: ["clustertriggerbindings", "clusterinterceptors"]
verbs: ["get", "list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: tekton-triggers-example-clusterbinding
subjects:
- kind: ServiceAccount
name: tekton-triggers-example-sa
namespace: tekton
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: tekton-triggers-example-clusterrole

triggerBinding/cluster/task-pipeline.yaml

apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: say-hello
spec:
params:
- name: contenttype
description: The Content-Type of the event
type: string
resources:
inputs:
- name: git-source
type: git
steps:
- name: say-hi
image: bash
command: ["bash", "-c"]
args:
- echo -e 'Hello Triggers!\nContent-Type is $(params.contenttype)'
---
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: say-message
spec:
params:
- name: message
description: The message to print
default: This is the default message
type: string
resources:
inputs:
- name: git-source
type: git
steps:
- name: say-message
image: bash
command: ["bash", "-c"]
args:
- echo '$(params.message)'
---
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: say-bye
spec:
resources:
inputs:
- name: git-source
type: git
steps:
- name: say-bye
image: bash
command: ["bash", "-c"]
args:
- echo 'Goodbye Triggers!'
---
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: simple-pipeline
spec:
params:
- name: message
description: The message to print
default: This is the default message
type: string
- name: contenttype
description: The Content-Type of the event
type: string
resources:
- name: git-source
type: git
tasks:
- name: say-hello
taskRef:
name: say-hello
params:
- name: contenttype
value: $(params.contenttype)
resources:
inputs:
- name: git-source
resource: git-source
- name: say-message
runAfter: [say-hello]
taskRef:
name: say-message
params:
- name: message
value: $(params.message)
resources:
inputs:
- name: git-source
resource: git-source
- name: say-bye
runAfter: [say-message]
taskRef:
name: say-bye
resources:
inputs:
- name: git-source
resource: git-source

triggerBinding/cluster/trigger-template.yaml


apiVersion: triggers.tekton.dev/v1alpha1
kind: TriggerTemplate
metadata:
name: pipeline-template
spec:
params:
- name: gitrevision
description: The git revision
default: main
- name: gitrepositoryurl
description: The git repository url
- name: message
description: The message to print
default: This is the default message
- name: contenttype
description: The Content-Type of the event
resourcetemplates:
- apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
generateName: simple-pipeline-run-
spec:
pipelineRef:
name: simple-pipeline
params:
- name: message
value: $(tt.params.message)
- name: contenttype
value: $(tt.params.contenttype)
resources:
- name: git-source
resourceSpec:
type: git
params:
- name: revision
value: $(tt.params.gitrevision)
- name: url
value: $(tt.params.gitrepositoryurl)


triggerBinding/cluster/listener.yaml

apiVersion: triggers.tekton.dev/v1alpha1
kind: EventListener
metadata:
name: listener
spec:
serviceAccountName: tekton-triggers-example-sa
triggers:
- name: foo-trig
bindings:
- ref: pipeline-clusterbinding
kind: ClusterTriggerBinding
- ref: message-clusterbinding
kind: ClusterTriggerBinding
template:
ref: pipeline-template

curl -v \
-H 'X-GitHub-Event: pull_request' \
-H 'X-Hub-Signature: sha1=ba0cdc263b3492a74b601d240c27efe81c4720cb' \
-H 'Content-Type: application/json' \
-d '{"action": "opened", "pull_request":{"head":{"sha": "28911bbb5a3e2ea034daf1f6be0a822d50e31e73"}},"repository":{"url": "https://github.com/tektoncd/triggers.git"}}' \
http://10.68.194.93:8080

标签:git,name,triggers,tekton,params,TriggerBinding,message,资源
From: https://blog.51cto.com/u_11979904/5948803

相关文章

  • 事务(进程 ID %1!)与另一个进程已被死锁在资源 {%2!} 上,且该事务已被选作死锁牺牲品。请
    --检测死锁--如果发生死锁了,我们怎么去检测具体发生死锁的是哪条SQL语句或存储过程?--这时我们可以使用以下存储过程来检测,就可以查出引起死锁的进程和SQL语句。SQLServe......
  • gateway资源详解
    学习目标什么是gateway在Kubernetes环境中,KubernetesIngress用于配置需要在集群外部公开的服务。但是在Istio服务网格中,更好的方法是使用新的配置模型,即IstioGateway。Gat......
  • VirtualService资源详解
    **VirtualService资源详解学习目标什么是virtualService​​VirtualService​​中文名称虚拟服务,是istio中一个重要的资源,它定义了一系列针对指定服务的流量路由规则。每个......
  • tekton task资源
     欢迎关注我的公众号: 目前刚开始写一个月,一共写了18篇原创文章,文章目录如下:​​istio多集群探秘,部署了50次多集群后我得出的结论​​​​istio多集群链路追踪,附实操视频​......
  • springMVC10(放行静态资源访问)
    一、放行静态资源访问的目的:为了让静态资源不被"springMVC"访问,而被拦截。我们需要让它被"放行"二、目录结构是什么样?2.1.1-在main包下2.1.2-和java包同"级别"2......
  • Docker的资源控制管理
    一、CPU控制cgroups,是一个非常强大的linux内核工具,他不仅可以限制被namespace隔离起来的资源,还可以为资源设置权重、计算使用量、操控进程启停等等。所以cgroups(Contr......
  • 【快应用】重新打开快应用, 保存/上传的图片资源不显示
    ​ 现象描述将上传的图片或者保存在手机本地的图片在快应用中显示出来,但是退出快应用后再次打开会无法显示. 问题分析此问题是由于将图片的路径保存在Temp区(表示从......
  • 【快应用】重新打开快应用, 保存/上传的图片资源不显示
     现象描述将上传的图片或者保存在手机本地的图片在快应用中显示出来,但是退出快应用后再次打开会无法显示.问题分析此问题是由于将图片的路径保存在Temp区(表示从外部映射过......
  • express的安装,使用,请求,自动更新,静态资源托管(一)
    1.打开编辑器vscode2.安装express  [email protected].创建文件index.js4.导入express  constexpress=require('express')5.创建web服务器  con......
  • Linux 控制CPU资源使用
    限制CPU的方式有以下几种:1、taskset2、cpulimit一、taskset-p,--pid对一个已存在的pid进行操作-c,--cpu-list限定进程到指定的cpu上,可以指定多个,以逗号分隔,......