Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POC: Canceling concurrent PipelineRuns #5501

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# MacOS file viewer garbage.
.DS_Store
*.venv

# Compiled Object files
*.slo
Expand Down
5 changes: 3 additions & 2 deletions cmd/webhook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ import (

var types = map[schema.GroupVersionKind]resourcesemantics.GenericCRD{
// v1alpha1
v1alpha1.SchemeGroupVersion.WithKind("PipelineResource"): &resourcev1alpha1.PipelineResource{},
v1alpha1.SchemeGroupVersion.WithKind("Run"): &v1alpha1.Run{},
v1alpha1.SchemeGroupVersion.WithKind("PipelineResource"): &resourcev1alpha1.PipelineResource{},
v1alpha1.SchemeGroupVersion.WithKind("Run"): &v1alpha1.Run{},
v1alpha1.SchemeGroupVersion.WithKind("ConcurrencyControl"): &v1alpha1.ConcurrencyControl{},
// v1beta1
v1beta1.SchemeGroupVersion.WithKind("Pipeline"): &v1beta1.Pipeline{},
v1beta1.SchemeGroupVersion.WithKind("Task"): &v1beta1.Task{},
Expand Down
10 changes: 10 additions & 0 deletions concurrencycontrol-example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: tekton.dev/v1alpha1
kind: ConcurrencyControl
metadata:
name: my-concurrency-control
namespace: concurrency
spec:
params:
- name: param-1
key: $(params.param-1)
strategy: Cancel
2 changes: 1 addition & 1 deletion config/200-clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ rules:
# Controller needs cluster access to all of the CRDs that it is responsible for
# managing.
- apiGroups: ["tekton.dev"]
resources: ["tasks", "clustertasks", "taskruns", "pipelines", "pipelineruns", "pipelineresources", "conditions", "runs"]
resources: ["tasks", "clustertasks", "taskruns", "pipelines", "pipelineruns", "pipelineresources", "conditions", "runs", "concurrencycontrols"]
verbs: ["get", "list", "create", "update", "delete", "patch", "watch"]
- apiGroups: ["tekton.dev"]
resources: ["taskruns/finalizers", "pipelineruns/finalizers", "runs/finalizers"]
Expand Down
30 changes: 30 additions & 0 deletions config/300-concurrencycontrol.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: concurrencycontrols.tekton.dev
labels:
app.kubernetes.io/instance: default
app.kubernetes.io/part-of: tekton-pipelines
pipeline.tekton.dev/release: "devel"
version: "devel"
spec:
group: tekton.dev
scope: Namespaced
names:
kind: ConcurrencyControl
plural: concurrencycontrols
singular: concurrencycontrol
shortNames:
- cc
categories:
- tekton
versions:
- name: v1alpha1
served: true
storage: true
schema:
openAPIV3Schema:
type: object
x-kubernetes-preserve-unknown-fields: true
subresources:
status: {}
47 changes: 47 additions & 0 deletions docs/concurrency.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
## Concurrency control primitives

The "ConcurrencyControl" CRD is used for higher-level systems to control concurrency of PipelineRuns.
To use concurrency controls, first create an instance of a ConcurrencyControl, for example:

```yaml
apiVersion: tekton.dev/v1alpha1
kind: ConcurrencyControl
metadata:
name: my-concurrency-control
spec:
params:
- name: param-1
- name: param-2
Comment on lines +12 to +14
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those would be "populated" by the PipelineRun params ?
What happens if there is a mismatch between PipelineRun's params and that ConcurrencyControl params?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those would be "populated" by the PipelineRun params ?

yup!

What happens if there is a mismatch between PipelineRun's params and that ConcurrencyControl params?

We would probably fail the PipelineRun (not sure how a separate controller outside of pipelines would do that though) or cancel it.

key: $(params.param-1)-$(params.param-2)
strategy: Cancel
```

The only currently supported strategy is "Cancel", which will patch other PipelineRuns with the same
concurrency key in the same namespace as Canceled.
The parameters defined by the ConcurrencyControl should match the parameters declared in the resource
it applies to (currently, only PipelineRuns are supported).
The ConcurrencyControl must be in the same namespace as any PipelineRuns using it.

Next, create your PipelineRun with the label "tekton.dev/concurrency": "insert-name-of-concurrency-control-here".

The PipelineRun controller will apply a concurrency key label to your PipelineRun.
For example, for the following PipelineRun:

```yaml
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
labels:
tekton.dev/concurrency: my-concurrency-control
spec:
params:
- name: param-1
value: foo
- name: param-2
value: bar
```

the controller will apply the label "tekton.dev/concurrency-key": "foo-bar".
If any PipelineRuns in the same namespace have the same concurrency key, they will be canceled
before the existing PipelineRun begins running.

42 changes: 22 additions & 20 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ require (
github.com/tektoncd/plumbing v0.0.0-20220817140952-3da8ce01aeeb
go.opencensus.io v0.23.0
go.uber.org/zap v1.23.0
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5
golang.org/x/oauth2 v0.0.0-20220524215830-622c5d57e401
gomodules.xyz/jsonpatch/v2 v2.2.0
k8s.io/api v0.23.9
k8s.io/apimachinery v0.23.9
Expand All @@ -33,7 +33,10 @@ require (
sigs.k8s.io/yaml v1.3.0
)

require github.com/benbjohnson/clock v1.1.0 // indirect
require (
github.com/benbjohnson/clock v1.1.0 // indirect
github.com/go-stack/stack v1.8.1 // indirect
)

require (
code.gitea.io/sdk/gitea v0.14.0
Expand All @@ -56,7 +59,7 @@ require (
)

require (
cloud.google.com/go/compute v1.5.0 // indirect
cloud.google.com/go/compute v1.6.1 // indirect
contrib.go.opencensus.io/exporter/ocagent v0.7.1-0.20200907061046-05415f1de66d // indirect
contrib.go.opencensus.io/exporter/prometheus v0.4.0 // indirect
github.com/Azure/azure-sdk-for-go v63.3.0+incompatible // indirect
Expand Down Expand Up @@ -105,15 +108,15 @@ require (
github.com/go-logfmt/logfmt v0.5.0 // indirect
github.com/go-logr/logr v1.2.2 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.5 // indirect
github.com/go-openapi/swag v0.19.15 // indirect
github.com/gobuffalo/flect v0.2.4 // indirect
github.com/go-openapi/jsonreference v0.19.6 // indirect
github.com/go-openapi/swag v0.21.1 // indirect
github.com/gobuffalo/flect v0.2.5 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v4 v4.3.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-containerregistry/pkg/authn/kubernetes v0.0.0-20220301182634-bfe2ffc6b6bd // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/gofuzz v1.2.1-0.20210504230335-f78f29fc09ea // indirect
github.com/googleapis/gnostic v0.5.5 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/hashicorp/go-version v1.3.0 // indirect
Expand All @@ -133,13 +136,13 @@ require (
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/openzipkin/zipkin-go v0.3.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.11.1 // indirect
github.com/prometheus/client_golang v1.12.1 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/prometheus/statsd_exporter v0.21.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/shurcooL/githubv4 v0.0.0-20190718010115-4ba037080260 // indirect
github.com/shurcooL/githubv4 v0.0.0-20210725200734-83ba7b4c9228 // indirect
github.com/shurcooL/graphql v0.0.0-20181231061246-d48a9a75455f // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
Expand All @@ -150,20 +153,19 @@ require (
go.uber.org/goleak v1.1.12 // indirect
go.uber.org/multierr v1.7.0 // indirect
golang.org/x/crypto v0.0.0-20220214200702-86341886e292 // indirect
golang.org/x/mod v0.5.1 // indirect
golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/net v0.0.0-20220607020251-c690dde0001d // indirect
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f // indirect
golang.org/x/sys v0.0.0-20220608164250-635b8c9b7f68 // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20220224211638-0e9765cccd65 // indirect
golang.org/x/tools v0.1.9 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/api v0.70.0 // indirect
golang.org/x/time v0.0.0-20220411224347-583f2d630306 // indirect
golang.org/x/tools v0.1.11 // indirect
google.golang.org/api v0.83.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20220303160752-862486edd9cc // indirect
google.golang.org/grpc v1.44.0 // indirect
google.golang.org/protobuf v1.27.1 // indirect
google.golang.org/genproto v0.0.0-20220608133413-ed9918b62aac // indirect
google.golang.org/grpc v1.47.0 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
Loading