-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
main.go
120 lines (104 loc) · 4.51 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
Copyright 2019 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 (
"flag"
"log"
"net/http"
"os"
"github.com/tektoncd/pipeline/pkg/apis/pipeline"
"github.com/tektoncd/pipeline/pkg/reconciler/pipelinerun"
"github.com/tektoncd/pipeline/pkg/reconciler/taskrun"
"github.com/tektoncd/pipeline/pkg/version"
corev1 "k8s.io/api/core/v1"
"k8s.io/client-go/rest"
"knative.dev/pkg/controller"
"knative.dev/pkg/injection"
"knative.dev/pkg/injection/sharedmain"
"knative.dev/pkg/signals"
)
const (
// ControllerLogKey is the name of the logger for the controller cmd
ControllerLogKey = "tekton"
)
var (
entrypointImage = flag.String("entrypoint-image", "", "The container image containing our entrypoint binary.")
nopImage = flag.String("nop-image", "", "The container image used to stop sidecars")
gitImage = flag.String("git-image", "", "The container image containing our Git binary.")
kubeconfigWriterImage = flag.String("kubeconfig-writer-image", "", "The container image containing our kubeconfig writer binary.")
shellImage = flag.String("shell-image", "", "The container image containing a shell")
gsutilImage = flag.String("gsutil-image", "", "The container image containing gsutil")
buildGCSFetcherImage = flag.String("build-gcs-fetcher-image", "", "The container image containing our GCS fetcher binary.")
prImage = flag.String("pr-image", "", "The container image containing our PR binary.")
imageDigestExporterImage = flag.String("imagedigest-exporter-image", "", "The container image containing our image digest exporter binary.")
namespace = flag.String("namespace", corev1.NamespaceAll, "Namespace to restrict informer to. Optional, defaults to all namespaces.")
versionGiven = flag.String("version", "devel", "Version of Tekton running")
threadsPerController = flag.Int("threads-per-controller", controller.DefaultThreadsPerController, "Threads (goroutines) to create per controller")
disableHighAvailability = flag.Bool("disable-ha", false, "Whether to disable high-availability functionality for this component. This flag will be deprecated "+
"and removed when we have promoted this feature to stable, so do not pass it without filing an "+
"issue upstream!")
)
func main() {
cfg := sharedmain.ParseAndGetConfigOrDie()
controller.DefaultThreadsPerController = *threadsPerController
version.SetVersion(*versionGiven)
images := pipeline.Images{
EntrypointImage: *entrypointImage,
NopImage: *nopImage,
GitImage: *gitImage,
KubeconfigWriterImage: *kubeconfigWriterImage,
ShellImage: *shellImage,
GsutilImage: *gsutilImage,
BuildGCSFetcherImage: *buildGCSFetcherImage,
PRImage: *prImage,
ImageDigestExporterImage: *imageDigestExporterImage,
}
if err := images.Validate(); err != nil {
log.Fatal(err)
}
if cfg.QPS == 0 {
cfg.QPS = 2 * rest.DefaultQPS
}
if cfg.Burst == 0 {
cfg.Burst = rest.DefaultBurst
}
// FIXME(vdemeester): this is here to not break current behavior
// multiply by 2, no of controllers being created
cfg.QPS = 2 * cfg.QPS
cfg.Burst = 2 * cfg.Burst
ctx := injection.WithNamespaceScope(signals.NewContext(), *namespace)
if *disableHighAvailability {
ctx = sharedmain.WithHADisabled(ctx)
}
// 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))
}()
sharedmain.MainWithConfig(ctx, ControllerLogKey, cfg,
taskrun.NewController(*namespace, images),
pipelinerun.NewController(*namespace, images),
)
}
func handler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
}