Skip to content

Commit

Permalink
Add custom task that runs a Pipeline as a TaskRun 🍙
Browse files Browse the repository at this point in the history
This commit adds a custom task that allows user to run simple sequential
Pipelines as one TaskRun - which means the Pipeline can refer to
multiple Tasks but run on only one pod.

It only supports a subset of Pipeline functionality (more detail on what
and why in the README) but is enough that folks can do a lot of what
they would have previously used PipelineResources for, e.g. doing a git
clone and then doing something with the data, in the same pod, and emit
results such as the exact commit sha used.

Next steps will be to expand the functionality supported, get feedback,
and if the feedback is good, promote this to a top level Pipeline API
feature.

Experimental project proposal: tektoncd/community#447
  • Loading branch information
bobcatfish committed Sep 2, 2021
1 parent bed8bb7 commit 4133db4
Show file tree
Hide file tree
Showing 38 changed files with 6,048 additions and 1 deletion.
444 changes: 443 additions & 1 deletion pipeline-to-taskrun/README.md

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions pipeline-to-taskrun/cmd/controller/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
Copyright 2021 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 main

import (
"github.com/tektoncd/experimental/pipeline-to-taskrun/pkg/reconciler/pipelinetotaskrun"
//"github.com/tektoncd/experimental/pipeline-in-a-pod/pkg/reconciler/pipelinetotaskrun"
"knative.dev/pkg/injection/sharedmain"
)

func main() {
sharedmain.Main(pipelinetotaskrun.ControllerName, pipelinetotaskrun.NewController)
}
21 changes: 21 additions & 0 deletions pipeline-to-taskrun/config/100-namespace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2021 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: v1
kind: Namespace
metadata:
name: tekton-pipeline-to-taskrun
labels:
app.kubernetes.io/instance: default
app.kubernetes.io/part-of: tekton-pipeline-to-taskrun
23 changes: 23 additions & 0 deletions pipeline-to-taskrun/config/200-serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2021 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: v1
kind: ServiceAccount
metadata:
name: pipeline-to-taskrun-controller
namespace: tekton-pipeline-to-taskrun
labels:
app.kubernetes.io/component: pipeline-to-taskrun-controller
app.kubernetes.io/instance: default
app.kubernetes.io/part-of: tekton-pipeline-to-taskrun
46 changes: 46 additions & 0 deletions pipeline-to-taskrun/config/201-clusterrole.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright 2021 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.

kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: pipeline-to-taskrun-controller-cluster-access
labels:
app.kubernetes.io/component: pipeline-to-taskrun-controller
app.kubernetes.io/instance: default
app.kubernetes.io/part-of: tekton-pipeline-to-taskrun
rules:
# Controller needs cluster access to all Run CRs.
- apiGroups: ["tekton.dev"]
resources: ["runs", "taskruns"]
verbs: ["get", "list", "create", "update", "delete", "patch", "watch"]
- apiGroups: ["tekton.dev"]
resources: ["pipelines", "tasks"]
verbs: ["get", "list"]
- apiGroups: ["tekton.dev"]
resources: ["runs/finalizers"]
verbs: ["get", "list", "create", "update", "delete", "patch", "watch"]
- apiGroups: ["tekton.dev"]
resources: ["runs/status", "pipelineruns/status"]
verbs: ["get", "list", "create", "update", "delete", "patch", "watch"]

# Controller needs cluster access to leases for leader election.
- apiGroups: ["coordination.k8s.io"]
resources: ["leases"]
verbs: ["get", "list", "create", "update", "delete", "patch", "watch"]

# Controller needs permission to emit events associated with Run CRs.
- apiGroups: [""]
resources: ["events"]
verbs: ["get", "list", "create", "update", "delete", "patch", "watch"]
33 changes: 33 additions & 0 deletions pipeline-to-taskrun/config/201-role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2021 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.

kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: pipeline-to-taskrun-controller
namespace: tekton-pipeline-to-taskrun
labels:
app.kubernetes.io/component: pipeline-to-taskrun-controller
app.kubernetes.io/instance: default
app.kubernetes.io/part-of: tekton-pipeline-to-taskrun
rules:
- apiGroups: [""]
resources: ["configmaps"]
verbs: ["list", "watch"]

# The controller needs access to these configmaps for logging information and runtime configuration.
- apiGroups: [""]
resources: ["configmaps"]
verbs: ["get"]
resourceNames: ["config-logging", "config-observability", "config-leader-election"]
31 changes: 31 additions & 0 deletions pipeline-to-taskrun/config/201-rolebinding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright 2021 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: rbac.authorization.k8s.io/v1beta1
kind: RoleBinding
metadata:
name: pipeline-to-taskrun-controller
namespace: tekton-pipeline-to-taskrun
labels:
app.kubernetes.io/component: pipeline-to-taskrun-controller
app.kubernetes.io/instance: default
app.kubernetes.io/part-of: tekton-pipeline-to-taskrun
subjects:
- kind: ServiceAccount
name: pipeline-to-taskrun-controller
namespace: tekton-pipeline-to-taskrun
roleRef:
kind: Role
name: pipeline-to-taskrun-controller
apiGroup: rbac.authorization.k8s.io
30 changes: 30 additions & 0 deletions pipeline-to-taskrun/config/202-clusterrolebinding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright 2021 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: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: pipeline-to-taskrun-controller-cluster-access
labels:
app.kubernetes.io/component: pipeline-to-taskrun-controller
app.kubernetes.io/instance: default
app.kubernetes.io/part-of: tekton-pipeline-to-taskrun
subjects:
- kind: ServiceAccount
name: pipeline-to-taskrun-controller
namespace: tekton-pipeline-to-taskrun
roleRef:
kind: ClusterRole
name: pipeline-to-taskrun-controller-cluster-access
apiGroup: rbac.authorization.k8s.io
41 changes: 41 additions & 0 deletions pipeline-to-taskrun/config/400-controller-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright 2021 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: v1
kind: Service
metadata:
labels:
app.kubernetes.io/name: pipeline-to-taskrun-controller
app.kubernetes.io/component: pipeline-to-taskrun-controller
app.kubernetes.io/instance: default
app.kubernetes.io/version: devel
app.kubernetes.io/part-of: tekton-pipeline-to-taskrun
# tekton.dev/release value replaced with inputs.params.versionTag in pipeline/tekton/publish.yaml
pipeline.tekton.dev/release: "devel"
# labels below are related to istio and should not be used for resource lookup
app: pipeline-to-taskrun-controller
version: "devel"
name: pipeline-to-taskrun-controller
namespace: tekton-pipeline-to-taskrun
spec:
ports:
- name: http-metrics
port: 9090
protocol: TCP
targetPort: 9090
selector:
app.kubernetes.io/name: pipeline-to-taskrun-controller
app.kubernetes.io/component: pipeline-to-taskrun-controller
app.kubernetes.io/instance: default
app.kubernetes.io/part-of: tekton-pipeline-to-taskrun
66 changes: 66 additions & 0 deletions pipeline-to-taskrun/config/500-controller.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Copyright 2021 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: apps/v1
kind: Deployment
metadata:
name: pipeline-to-taskrun-controller
namespace: tekton-pipeline-to-taskrun
labels:
app.kubernetes.io/name: pipeline-to-taskrun-controller
app.kubernetes.io/component: pipeline-to-taskrun-controller
app.kubernetes.io/instance: default
app.kubernetes.io/version: devel
app.kubernetes.io/part-of: tekton-pipeline-to-taskrun
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: pipeline-to-taskrun-controller
app.kubernetes.io/component: pipeline-to-taskrun-controller
app.kubernetes.io/instance: default
app.kubernetes.io/part-of: tekton-pipeline-to-taskrun
template:
metadata:
annotations:
cluster-autoscaler.kubernetes.io/safe-to-evict: "false"
labels:
app.kubernetes.io/name: pipeline-to-taskrun-controller
app.kubernetes.io/component: pipeline-to-taskrun-controller
app.kubernetes.io/instance: default
app.kubernetes.io/version: devel
app.kubernetes.io/part-of: tekton-pipeline-to-taskrun
app: pipeline-to-taskrun-controller
spec:
serviceAccountName: pipeline-to-taskrun-controller
containers:
- name: pipeline-to-taskrun-controller
image: ko://github.com/tektoncd/experimental/pipeline-to-taskrun/cmd/controller
volumeMounts:
- name: config-logging
mountPath: /etc/config-logging
env:
- name: SYSTEM_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
# If you are changing these names, you will also need to update
# the controller's Role in 200-role.yaml to include the new
# values in the "configmaps" "get" rule.
- name: CONFIG_LOGGING_NAME
value: config-logging
volumes:
- name: config-logging
configMap:
name: config-logging
53 changes: 53 additions & 0 deletions pipeline-to-taskrun/config/config-logging.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Copyright 2021 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: v1
kind: ConfigMap
metadata:
name: config-logging
namespace: tekton-pipeline-to-taskrun
labels:
app.kubernetes.io/instance: default
app.kubernetes.io/part-of: tekton-pipeline-to-taskrun
data:
# Common configuration for all knative codebase
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": "",
"durationEncoder": "",
"callerEncoder": ""
}
}
# Log level overrides
loglevel.controller: "info"
loglevel.webhook: "info"
Loading

0 comments on commit 4133db4

Please sign in to comment.