Skip to content

Commit

Permalink
Initial controller code.
Browse files Browse the repository at this point in the history
This stands up a controller using ko. The controller does nothing
right now, other than register watchers on TaskRuns and log
reconciliation events.
  • Loading branch information
dlorenc authored and tekton-robot committed Jun 17, 2020
1 parent 58f88ac commit 880b894
Show file tree
Hide file tree
Showing 3,345 changed files with 999,690 additions and 6 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
7 changes: 7 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file is documented at https://git-scm.com/docs/gitattributes.
# Linguist-specific attributes are documented at
# https://github.com/github/linguist.

**/zz_generated.*.go linguist-generated=true
/vendor/** linguist-generated=true

33 changes: 32 additions & 1 deletion DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,35 @@ modules](https://github.com/golang/go/wiki/Modules#quick-start).

## Iterating

Coming soon!
## Install Chains

You can stand up a version of this controller on-cluster (to your `kubectl
config current-context`):

```shell
ko apply -f config/
```

### Redeploy controller

As you make changes to the code, you can redeploy your controller with:

```shell
ko apply -f config/deployment.yaml
```

### Tear it down

You can clean up everything with:

```shell
ko delete -f config/
```

## Accessing logs

To look at the controller logs, run:

```shell
kubectl -n tekton-pipelines logs deployment/tekton-chains-controller
```
71 changes: 71 additions & 0 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
Copyright 2020 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 (
"context"
"flag"

taskruninformer "github.com/tektoncd/pipeline/pkg/client/injection/informers/pipeline/v1beta1/taskrun"
"github.com/tektoncd/pipeline/pkg/reconciler"
"go.uber.org/zap"
"k8s.io/client-go/tools/cache"
"knative.dev/pkg/configmap"
"knative.dev/pkg/controller"
"knative.dev/pkg/injection"
"knative.dev/pkg/injection/sharedmain"
"knative.dev/pkg/logging"
"knative.dev/pkg/signals"
)

var (
namespace = flag.String("namespace", "", "Namespace to restrict informer to. Optional, defaults to all namespaces.")
)

const (
controllerName = "chains"
)

func main() {
flag.Parse()

sharedmain.MainWithContext(injection.WithNamespaceScope(signals.NewContext(), *namespace), "watcher",
func(ctx context.Context, cmw configmap.Watcher) *controller.Impl {
// TODO: store and use the cmw
logger := logging.FromContext(ctx)
taskRunInformer := taskruninformer.Get(ctx)

c := &rec{
logger: logger,
}
impl := controller.NewImpl(c, c.logger, controllerName)

taskRunInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: impl.Enqueue,
UpdateFunc: controller.PassNew(impl.Enqueue),
})

return impl
})
}

type rec struct {
*reconciler.Base
logger *zap.SugaredLogger
}

func (r *rec) Reconcile(ctx context.Context, key string) error {
r.logger.Infof("reconciling resource key: %s", key)
return nil
}
46 changes: 46 additions & 0 deletions config/100-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

apiVersion: apps/v1
kind: Deployment
metadata:
name: tekton-chains-controller
namespace: tekton-pipelines
labels:
app.kubernetes.io/name: tekton-pipelines
app.kubernetes.io/component: chains
pipeline.tekton.dev/release: "devel"
version: "devel"
spec:
replicas: 1
selector:
matchLabels:
app: tekton-chains-controller
template:
metadata:
annotations:
cluster-autoscaler.kubernetes.io/safe-to-evict: "false"
labels:
app: tekton-chains-controller
app.kubernetes.io/name: tekton-pipelines
app.kubernetes.io/component: controller
# # tekton.dev/release value replaced with inputs.params.versionTag in pipeline/tekton/publish.yaml
# pipeline.tekton.dev/release: "devel"
version: "devel"
spec:
serviceAccountName: tekton-pipelines-controller
containers:
- name: tekton-chains-controller
image: ko://github.com/tektoncd/chains/cmd/controller
volumeMounts:
- name: config-logging
mountPath: /etc/config-logging
env:
- name: SYSTEM_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: METRICS_DOMAIN
value: tekton.dev/chains
volumes:
- name: config-logging
configMap:
name: config-logging
27 changes: 26 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,29 @@ module github.com/tektoncd/chains

go 1.14

require github.com/tektoncd/plumbing v0.0.0-20200615101855-f56d60092af6
require (
contrib.go.opencensus.io/exporter/ocagent v0.7.0 // indirect
contrib.go.opencensus.io/exporter/prometheus v0.2.0 // indirect
github.com/tektoncd/pipeline v0.13.2
github.com/tektoncd/plumbing v0.0.0-20200615101855-f56d60092af6
go.uber.org/zap v1.15.0
k8s.io/client-go v11.0.1-0.20190805182717-6502b5e7b1b5+incompatible
knative.dev/pkg v0.0.0-20200616145124-d289d2eef6cb
)

// Knative deps (release-0.15)
replace (
contrib.go.opencensus.io/exporter/stackdriver => contrib.go.opencensus.io/exporter/stackdriver v0.12.9-0.20191108183826-59d068f8d8ff
github.com/Azure/azure-sdk-for-go => github.com/Azure/azure-sdk-for-go v38.2.0+incompatible
github.com/Azure/go-autorest => github.com/Azure/go-autorest v13.4.0+incompatible
knative.dev/caching => knative.dev/caching v0.0.0-20200521155757-e78d17bc250e
knative.dev/pkg => knative.dev/pkg v0.0.0-20200528142800-1c6815d7e4c9
)

// Pin k8s deps to 1.16.5
replace (
k8s.io/api => k8s.io/api v0.16.5
k8s.io/apimachinery => k8s.io/apimachinery v0.16.5
k8s.io/client-go => k8s.io/client-go v0.16.5
k8s.io/code-generator => k8s.io/code-generator v0.16.5
)
Loading

0 comments on commit 880b894

Please sign in to comment.