Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
toTriggerTemplate()

add spec.params to tt.params conversion

add toTriggers

add el/rbac for workflows

add repos/events

Add interceptor based on eventType

Update example for demo

small changes for demo

Add gitRef fields

Depends on tektoncd#806 for annotation based remote resolution to work

Add minimal + example.yaml

remove illegal char
  • Loading branch information
dibyom committed Sep 29, 2022
1 parent 2009bc3 commit e5d2100
Show file tree
Hide file tree
Showing 44 changed files with 3,783 additions and 190 deletions.
11 changes: 5 additions & 6 deletions workflows/cmd/run/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,14 @@ func runWorkflow(fileName string) error {
return fmt.Errorf("error decoding workflow: %v", err)
}
}

pr, err := w.ToPipelineRun()
tt, err := w.ToTriggers()
if err != nil {
return fmt.Errorf("error workflow to pipelinerun: %w", err)
return fmt.Errorf("error converting to trigger: %s", err)
}
pry, err := yaml.Marshal(pr)
tty, err := yaml.Marshal(tt[0])
if err != nil {
return fmt.Errorf("error convering pipelinerun to yaml: %w", err)
return fmt.Errorf("error convering trigger to yaml: %w", err)
}
fmt.Printf("%s", pry)
fmt.Printf("%s", tty)
return nil
}
31 changes: 31 additions & 0 deletions workflows/config/rbac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: tekton-triggers-example-sa
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding # TODO: Use a rolebinding and only create pipelineruns in specific namespaces
metadata:
name: triggers-example-eventlistener-binding
subjects:
- kind: ServiceAccount
name: tekton-triggers-example-sa
namespace: default
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: tekton-triggers-eventlistener-roles
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: triggers-example-eventlistener-clusterbinding
subjects:
- kind: ServiceAccount
name: tekton-triggers-example-sa
namespace: default
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: tekton-triggers-eventlistener-clusterroles
---
12 changes: 12 additions & 0 deletions workflows/config/workflows-el.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: triggers.tekton.dev/v1beta1
kind: EventListener
metadata:
name: workflows-listener
spec:
serviceAccountName: tekton-triggers-example-sa
resources:
kubernetesResource:
serviceType: LoadBalancer
labelSelector:
matchLabels:
managed-by: tekton-workflows
37 changes: 28 additions & 9 deletions workflows/example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,43 @@ spec:
ref: npm-publish-token # Refers to a K8s secret with this name
- name: git-clone-secret
ref: git-clone-secret

triggers:
- name: on-pr
event:
source:
url: https://github.com/dibyom/tkndemo
type: "pull_request"
secret:
secretName: "repo-secret"
secretKey: "token"
interceptors:
- name: "only_opened_prs"
ref:
name: cel
params:
- name: "filter"
value: "body.action in ['opened', 'synchronize', 'reopened']"
bindings:
- name: commit-sha
value: $(body.pull_request.head.sha)
- name: url
value: $(body.repository.clone_url)
params:
- name: url
default: https://github.com/tektoncd/pipeline
default: "https://github.com/dibyom/tkndemo"
- name: commit-sha
default: main

workspaces:
- name: clone-secret # Mount secret into a workspace
secret: "$(secrets.git-clone-secret)"
- name: source
volumeClaimTemplate: # Current Tekton Workspace syntax. We can simplify
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
pipeline:
spec:
params:
Expand Down
24 changes: 13 additions & 11 deletions workflows/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@ go 1.16
require (
github.com/GoogleCloudPlatform/cloud-builders/gcs-fetcher v0.0.0-20210729182058-ea1f5c7c37f1
github.com/google/go-cmp v0.5.6
github.com/spf13/cobra v1.1.1
github.com/tektoncd/pipeline v0.27.2
github.com/tektoncd/plumbing v0.0.0-20210514044347-f8a9689d5bd5
go.uber.org/zap v1.18.1
k8s.io/api v0.20.7
k8s.io/apimachinery v0.20.7
k8s.io/client-go v0.20.7
k8s.io/code-generator v0.20.7
k8s.io/kube-openapi v0.0.0-20210113233702-8566a335510f
knative.dev/pkg v0.0.0-20210730172132-bb4aaf09c430
sigs.k8s.io/yaml v1.2.0
github.com/spf13/cobra v1.2.1
github.com/tektoncd/pipeline v0.32.1
github.com/tektoncd/plumbing v0.0.0-20211012143332-c7cc43d9bc0c
github.com/tektoncd/triggers v0.18.0
go.uber.org/zap v1.19.1
k8s.io/api v0.22.5
k8s.io/apiextensions-apiserver v0.22.5
k8s.io/apimachinery v0.22.5
k8s.io/client-go v0.22.5
k8s.io/code-generator v0.22.5
k8s.io/kube-openapi v0.0.0-20211109043538-20434351676c
knative.dev/pkg v0.0.0-20220104185830-52e42b760b54
sigs.k8s.io/yaml v1.3.0
)

// Knative deps (release-0.20)
Expand Down
1,156 changes: 1,089 additions & 67 deletions workflows/go.sum

Large diffs are not rendered by default.

40 changes: 40 additions & 0 deletions workflows/minimal.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
apiVersion: experimental.tekton.dev/v1alpha1
kind: Workflow
metadata:
name: from-git
spec:
repos:
- name: tkndemo
url: "https://github.com/dibyom/tkndemo"
triggers:
- name: on-pr
event:
source:
url: https://github.com/dibyom/tkndemo
type: "pull_request"
secret:
secretName: "repo-secret"
secretKey: "token"
interceptors:
- name: "only_opened_prs"
ref:
name: cel
params:
- name: "filter"
value: "body.action in ['opened', 'synchronize', 'reopened']"
bindings:
- name: commit-sha
value: $(body.pull_request.head.sha)
- name: url
value: $(body.repository.clone_url)
params:
- name: url
default: "https://github.com/dibyom/tkndemo"
- name: commit-sha
default: main
pipeline:
git:
repo: "tkndemo"
commit: $(params.commit-sha)
path: pipeline.yaml
pipeline: p
Loading

0 comments on commit e5d2100

Please sign in to comment.