/
main.go
101 lines (79 loc) · 2.82 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
package main
import (
"flag"
"fmt"
"net/http"
"os"
"strings"
"time"
"github.com/prometheus/client_golang/prometheus/promhttp"
log "github.com/sirupsen/logrus"
v1 "k8s.io/api/core/v1"
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/catalog"
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/signals"
"github.com/operator-framework/operator-lifecycle-manager/pkg/metrics"
olmversion "github.com/operator-framework/operator-lifecycle-manager/pkg/version"
)
const (
defaultWakeupInterval = 15 * time.Minute
defaultCatalogNamespace = "openshift-operator-lifecycle-manager"
defaultConfigMapServerImage = "quay.io/operatorframework/configmap-operator-registry:latest"
)
// config flags defined globally so that they appear on the test binary as well
var (
kubeConfigPath = flag.String(
"kubeconfig", "", "absolute path to the kubeconfig file")
wakeupInterval = flag.Duration(
"interval", defaultWakeupInterval, "wakeup interval")
watchedNamespaces = flag.String(
"watchedNamespaces", "", "comma separated list of namespaces that catalog watches, leave empty to watch all namespaces")
catalogNamespace = flag.String(
"namespace", defaultCatalogNamespace, "namespace where catalog will run and install catalog resources")
configmapServerImage = flag.String(
"configmapServerImage", defaultConfigMapServerImage, "the image to use for serving the operator registry api for a configmap")
debug = flag.Bool(
"debug", false, "use debug log level")
version = flag.Bool("version", false, "displays olm version")
)
func init() {
metrics.RegisterCatalog()
}
func main() {
stopCh := signals.SetupSignalHandler()
// Parse the command-line flags.
flag.Parse()
// Check if version flag was set
if *version {
fmt.Print(olmversion.String())
// Exit early
os.Exit(0)
}
// `namespaces` will always contain at least one entry: if `*watchedNamespaces` is
// the empty string, the resulting array will be `[]string{""}`.
namespaces := strings.Split(*watchedNamespaces, ",")
for _, ns := range namespaces {
if ns == v1.NamespaceAll {
namespaces = []string{v1.NamespaceAll}
break
}
}
// Serve a health check.
http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
})
go http.ListenAndServe(":8080", nil)
logger := log.New()
if *debug {
logger.SetLevel(log.DebugLevel)
}
logger.Infof("log level %s", logger.Level)
// Create a new instance of the operator.
catalogOperator, err := catalog.NewOperator(*kubeConfigPath, logger, *wakeupInterval, *configmapServerImage, *catalogNamespace, namespaces...)
if err != nil {
log.Panicf("error configuring operator: %s", err.Error())
}
http.Handle("/metrics", promhttp.Handler())
go http.ListenAndServe(":8081", nil)
_, done := catalogOperator.Run(stopCh)
<-done
}