Skip to content

Commit

Permalink
Run events controller as separate binary
Browse files Browse the repository at this point in the history
This is the first step towards moving the whole cloudevents logic
to a dedicated controller.

The `Run` controller is already separated from the other controllers,
but it's compiled and deployed in the shared binary.
In this change we move that controller to a dedicated binary, with
its own deployment, service account, roles and bindings.

This new binary shares the config maps from the pipeline binary, so
that existing configuration options and docs continue to apply with
no change.

Because of injection, all the informers are setup for this binary,
which means that the service account requires read access to the
various tekton resources. This is fine however considering that
eventually this controller will handle events for all tekton
pipeline resources.

The publish task is amended to expect the new events image by
default as well.

Partially-fixes: #2944

Signed-off-by: Andrea Frittoli <andrea.frittoli@uk.ibm.com>
  • Loading branch information
afrittoli authored and tekton-robot committed Apr 27, 2023
1 parent 0d8abac commit 626669e
Show file tree
Hide file tree
Showing 8 changed files with 297 additions and 1 deletion.
1 change: 1 addition & 0 deletions cmd/events/kodata/LICENSE
55 changes: 55 additions & 0 deletions cmd/events/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
Copyright 2023 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 (
"log"
"net/http"
"os"

"github.com/tektoncd/pipeline/pkg/reconciler/customrun"
"knative.dev/pkg/injection/sharedmain"
)

const eventsControllerName = "events-controller"

func main() {
// sets up liveness and readiness probes.
mux := http.NewServeMux()

mux.HandleFunc("/", handler)
mux.HandleFunc("/health", handler)
mux.HandleFunc("/readiness", handler)

port := os.Getenv("PROBES_PORT")
if port == "" {
port = "8080"
}

go func() {
// start the web server on port and accept requests
log.Printf("Readiness and health check server listening on port %s", port)
log.Fatal(http.ListenAndServe(":"+port, mux)) // #nosec G114 -- see https://github.com/securego/gosec#available-rules
}()

// start the events controller
sharedmain.Main(eventsControllerName, customrun.NewController())
}

func handler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
}
13 changes: 13 additions & 0 deletions config/200-clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,16 @@ rules:
# The webhook configured the namespace as the OwnerRef on various cluster-scoped resources,
# which requires we can update the system namespace finalizers.
resourceNames: ["tekton-pipelines"]
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: tekton-events-controller-cluster-access
labels:
app.kubernetes.io/component: events
app.kubernetes.io/instance: default
app.kubernetes.io/part-of: tekton-pipelines
rules:
- apiGroups: ["tekton.dev"]
resources: ["tasks", "clustertasks", "taskruns", "pipelines", "pipelineruns", "customruns"]
verbs: ["get", "list", "watch"]
10 changes: 10 additions & 0 deletions config/200-serviceaccount.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,13 @@ metadata:
app.kubernetes.io/component: webhook
app.kubernetes.io/instance: default
app.kubernetes.io/part-of: tekton-pipelines
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: tekton-events-controller
namespace: tekton-pipelines
labels:
app.kubernetes.io/component: events
app.kubernetes.io/instance: default
app.kubernetes.io/part-of: tekton-pipelines
17 changes: 17 additions & 0 deletions config/201-clusterrolebinding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,20 @@ roleRef:
kind: ClusterRole
name: tekton-pipelines-webhook-cluster-access
apiGroup: rbac.authorization.k8s.io
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: tekton-events-controller-cluster-access
labels:
app.kubernetes.io/component: events
app.kubernetes.io/instance: default
app.kubernetes.io/part-of: tekton-pipelines
subjects:
- kind: ServiceAccount
name: tekton-events-controller
namespace: tekton-pipelines
roleRef:
kind: ClusterRole
name: tekton-events-controller-cluster-access
apiGroup: rbac.authorization.k8s.io
36 changes: 36 additions & 0 deletions config/201-rolebinding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,39 @@ roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: tekton-pipelines-info
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: tekton-events-controller
namespace: tekton-pipelines
labels:
app.kubernetes.io/component: events
app.kubernetes.io/instance: default
app.kubernetes.io/part-of: tekton-pipelines
subjects:
- kind: ServiceAccount
name: tekton-events-controller
namespace: tekton-pipelines
roleRef:
kind: Role
name: tekton-pipelines-controller
apiGroup: rbac.authorization.k8s.io
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: tekton-events-controller-leaderelection
namespace: tekton-pipelines
labels:
app.kubernetes.io/component: events
app.kubernetes.io/instance: default
app.kubernetes.io/part-of: tekton-pipelines
subjects:
- kind: ServiceAccount
name: tekton-events-controller
namespace: tekton-pipelines
roleRef:
kind: Role
name: tekton-pipelines-leader-election
apiGroup: rbac.authorization.k8s.io
164 changes: 164 additions & 0 deletions config/events.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
# Copyright 2023 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.

apiVersion: apps/v1
kind: Deployment
metadata:
name: tekton-events-controller
namespace: tekton-pipelines
labels:
app.kubernetes.io/name: events
app.kubernetes.io/component: events
app.kubernetes.io/instance: default
app.kubernetes.io/version: "devel"
app.kubernetes.io/part-of: tekton-pipelines
# 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
version: "devel"
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: events
app.kubernetes.io/component: events
app.kubernetes.io/instance: default
app.kubernetes.io/part-of: tekton-pipelines
template:
metadata:
labels:
app.kubernetes.io/name: events
app.kubernetes.io/component: events
app.kubernetes.io/instance: default
app.kubernetes.io/version: "devel"
app.kubernetes.io/part-of: tekton-pipelines
# 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: tekton-events-controller
version: "devel"
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/os
operator: NotIn
values:
- windows
serviceAccountName: tekton-events-controller
containers:
- name: tekton-events-controller
image: ko://github.com/tektoncd/pipeline/cmd/events
args: []
volumeMounts:
- name: config-logging
mountPath: /etc/config-logging
- name: config-registry-cert
mountPath: /etc/config-registry-cert
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_DEFAULTS_NAME
value: config-defaults
- name: CONFIG_LOGGING_NAME
value: config-logging
- name: CONFIG_OBSERVABILITY_NAME
value: config-observability
- name: CONFIG_LEADERELECTION_NAME
value: config-leader-election
- name: SSL_CERT_FILE
value: /etc/config-registry-cert/cert
- name: SSL_CERT_DIR
value: /etc/ssl/certs
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- "ALL"
# User 65532 is the nonroot user ID
runAsUser: 65532
runAsGroup: 65532
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
ports:
- name: metrics
containerPort: 9090
- name: profiling
containerPort: 8008
- name: probes
containerPort: 8080
livenessProbe:
httpGet:
path: /health
port: probes
scheme: HTTP
initialDelaySeconds: 5
periodSeconds: 10
timeoutSeconds: 5
readinessProbe:
httpGet:
path: /readiness
port: probes
scheme: HTTP
initialDelaySeconds: 5
periodSeconds: 10
timeoutSeconds: 5
volumes:
- name: config-logging
configMap:
name: config-logging
- name: config-registry-cert
configMap:
name: config-registry-cert
---
apiVersion: v1
kind: Service
metadata:
labels:
app.kubernetes.io/name: events
app.kubernetes.io/component: events
app.kubernetes.io/instance: default
app.kubernetes.io/version: "devel"
app.kubernetes.io/part-of: tekton-pipelines
# 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: tekton-events-controller
version: "devel"
name: tekton-events-controller
namespace: tekton-pipelines
spec:
ports:
- name: http-metrics
port: 9090
protocol: TCP
targetPort: 9090
- name: http-profiling
port: 8008
targetPort: 8008
- name: probes
port: 8080
selector:
app.kubernetes.io/name: events
app.kubernetes.io/component: events
app.kubernetes.io/instance: default
app.kubernetes.io/part-of: tekton-pipelines
2 changes: 1 addition & 1 deletion tekton/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ spec:
default: github.com/tektoncd/pipeline
- name: images
description: List of cmd/* paths to be published as images
default: "controller webhook entrypoint nop workingdirinit resolvers sidecarlogresults"
default: "controller webhook entrypoint nop workingdirinit resolvers sidecarlogresults events"
- name: versionTag
description: The vX.Y.Z version that the artifacts should be tagged with (including `v`)
- name: imageRegistry
Expand Down

0 comments on commit 626669e

Please sign in to comment.