-
Notifications
You must be signed in to change notification settings - Fork 423
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for ClusterTriggerBinding
This will add the support for ClusterTriggerBinding in triggers which is like TrigerBinding but cluster-scoped This is designed to encourage reusability across cluster You need to add Kind field along with TriggerBinding name to use ClusterTriggerBinding, by default it is TriggerBinding Add docs, examples, and tests for clustertriggerbinding Little refactoring in code. Add builders for multipleTriggerBindings in a trigger Refactored e2e test to use both triggerBinding and clusterTriggerBinding Closes #322
- Loading branch information
1 parent
a12bc58
commit 3af33c5
Showing
64 changed files
with
2,150 additions
and
192 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Copyright 2019 The Tekton Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
apiVersion: apiextensions.k8s.io/v1beta1 | ||
kind: CustomResourceDefinition | ||
metadata: | ||
name: clustertriggerbindings.tekton.dev | ||
spec: | ||
group: tekton.dev | ||
scope: Cluster | ||
names: | ||
kind: ClusterTriggerBinding | ||
plural: clustertriggerbindings | ||
singular: clustertriggerbinding | ||
shortNames: | ||
- ctb | ||
categories: | ||
- tekton | ||
- tekton-triggers | ||
subresources: | ||
status: {} | ||
version: v1alpha1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# ClusterTriggerBindings | ||
|
||
`ClusterTriggerBindings` is similar to TriggerBinding which is used to extract field from event payload. | ||
The only difference is it is cluster-scoped and designed to encourage reusability clusterwide. | ||
You can reference a ClusterTriggerBinding in any EventListener in any namespace. | ||
|
||
<!-- FILE: examples/clustertriggerbindings/clustertriggerbinding.yaml --> | ||
```YAML | ||
apiVersion: 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) | ||
``` | ||
You can specify multiple ClusterTriggerBindings in a Trigger. You can use a ClusterTriggerBinding in multiple Triggers. | ||
In case of using a ClusterTriggerBinding, the `Binding` kind should be added. The default | ||
kind is TriggerBinding which represents a namespaced TriggerBinding. | ||
|
||
<!-- FILE: examples/eventlisteners/eventlistener-clustertriggerbinding.yaml --> | ||
```YAML | ||
--- | ||
apiVersion: tekton.dev/v1alpha1 | ||
kind: EventListener | ||
metadata: | ||
name: listener-clustertriggerbinding | ||
spec: | ||
serviceAccountName: tekton-triggers-example-sa | ||
triggers: | ||
- name: foo-trig | ||
bindings: | ||
- name: pipeline-clusterbinding | ||
kind: ClusterTriggerBinding | ||
- name: message-clusterbinding | ||
kind: ClusterTriggerBinding | ||
template: | ||
name: pipeline-template | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
examples/clustertriggerbindings/clustertriggerbinding-message.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
apiVersion: tekton.dev/v1alpha1 | ||
kind: ClusterTriggerBinding | ||
metadata: | ||
name: message-clusterbinding | ||
spec: | ||
params: | ||
- name: message | ||
value: Hello from the Triggers EventListener! |
12 changes: 12 additions & 0 deletions
12
examples/clustertriggerbindings/clustertriggerbinding.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
apiVersion: 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) |
16 changes: 16 additions & 0 deletions
16
examples/eventlisteners/eventlistener-clustertriggerbinding.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
apiVersion: tekton.dev/v1alpha1 | ||
kind: EventListener | ||
metadata: | ||
name: listener-clustertriggerbinding | ||
spec: | ||
serviceAccountName: tekton-triggers-example-sa | ||
triggers: | ||
- name: foo-trig | ||
bindings: | ||
- name: pipeline-clusterbinding | ||
kind: ClusterTriggerBinding | ||
- name: message-clusterbinding | ||
kind: ClusterTriggerBinding | ||
template: | ||
name: pipeline-template |
11 changes: 11 additions & 0 deletions
11
examples/role-resources/clustertriggerbinding-roles/clusterbinding.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: tekton-triggers-example-clusterbinding | ||
subjects: | ||
- kind: ServiceAccount | ||
name: tekton-triggers-example-sa | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: ClusterRole | ||
name: tekton-triggers-example-clusterrole |
16 changes: 16 additions & 0 deletions
16
examples/role-resources/clustertriggerbinding-roles/clusterrole.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
kind: ClusterRole | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
metadata: | ||
name: tekton-triggers-example-clusterrole | ||
rules: | ||
# Permissions for every EventListener deployment to function | ||
- apiGroups: ["tekton.dev"] | ||
resources: ["clustertriggerbindings", "eventlisteners", "triggerbindings", "triggertemplates", "tasks", "taskruns"] | ||
verbs: ["get"] | ||
- apiGroups: [""] | ||
resources: ["configmaps", "secrets"] # secrets are only needed for Github/Gitlab interceptors | ||
verbs: ["get", "list", "watch"] | ||
# Permissions to create resources in associated TriggerTemplates | ||
- apiGroups: ["tekton.dev"] | ||
resources: ["pipelineruns", "pipelineresources", "taskruns"] | ||
verbs: ["create"] |
File renamed without changes.
File renamed without changes.
24 changes: 24 additions & 0 deletions
24
pkg/apis/triggers/v1alpha1/cluster_trigger_binding_defaults.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
Copyright 2019 The Tekton Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1alpha1 | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
// SetDefaults initializes ClusterTriggerBinding ctb with its default values. | ||
func (ctb *ClusterTriggerBinding) SetDefaults(ctx context.Context) {} |
69 changes: 69 additions & 0 deletions
69
pkg/apis/triggers/v1alpha1/cluster_trigger_binding_types.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
Copyright 2019 The Tekton Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1alpha1 | ||
|
||
import ( | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"knative.dev/pkg/apis" | ||
) | ||
|
||
// Check that ClusterTriggerBinding may be validated and defaulted. | ||
var _ apis.Validatable = (*ClusterTriggerBinding)(nil) | ||
var _ apis.Defaultable = (*ClusterTriggerBinding)(nil) | ||
|
||
// +genclient | ||
// +genclient:nonNamespaced | ||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object | ||
// +k8s:openapi-gen=true | ||
|
||
// ClusterTriggerBinding is a TriggerBinding with a cluster scope. | ||
// ClusterTriggerBindings are used to represent TriggerBindings that | ||
// should be publicly addressable from any namespace in the cluster. | ||
type ClusterTriggerBinding struct { | ||
metav1.TypeMeta `json:",inline"` | ||
// +optional | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
// Spec holds the desired state of the ClusterTriggerBinding from the client | ||
// +optional | ||
Spec TriggerBindingSpec `json:"spec,omitempty"` | ||
|
||
// +optional | ||
Status TriggerBindingStatus `json:"status"` | ||
} | ||
|
||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object | ||
|
||
// ClusterTriggerBindingList contains a list of ClusterTriggerBinding | ||
type ClusterTriggerBindingList struct { | ||
metav1.TypeMeta `json:",inline"` | ||
// +optional | ||
metav1.ListMeta `json:"metadata,omitempty"` | ||
Items []ClusterTriggerBinding `json:"items"` | ||
} | ||
|
||
func (ctb *ClusterTriggerBinding) TriggerBindingSpec() TriggerBindingSpec { | ||
return ctb.Spec | ||
} | ||
|
||
func (ctb *ClusterTriggerBinding) TriggerBindingMetadata() metav1.ObjectMeta { | ||
return ctb.ObjectMeta | ||
} | ||
|
||
func (ctb *ClusterTriggerBinding) Copy() TriggerBindingInterface { | ||
return ctb.DeepCopy() | ||
} |
Oops, something went wrong.