forked from k-orc/openstack-resource-controller
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
109 lines (92 loc) · 4.21 KB
/
Copy pathmain.go
File metadata and controls
109 lines (92 loc) · 4.21 KB
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
/*
Copyright 2024.
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"
"os"
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
// to ensure that exec-entrypoint and run can make use of them.
_ "k8s.io/client-go/plugin/pkg/client/auth"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
"github.com/k-orc/openstack-resource-controller/internal/controllers/export"
"github.com/k-orc/openstack-resource-controller/internal/controllers/flavor"
"github.com/k-orc/openstack-resource-controller/internal/controllers/image"
"github.com/k-orc/openstack-resource-controller/internal/controllers/network"
"github.com/k-orc/openstack-resource-controller/internal/controllers/port"
"github.com/k-orc/openstack-resource-controller/internal/controllers/router"
"github.com/k-orc/openstack-resource-controller/internal/controllers/routerinterface"
"github.com/k-orc/openstack-resource-controller/internal/controllers/securitygroup"
"github.com/k-orc/openstack-resource-controller/internal/controllers/server"
"github.com/k-orc/openstack-resource-controller/internal/controllers/subnet"
internalmanager "github.com/k-orc/openstack-resource-controller/internal/manager"
"github.com/k-orc/openstack-resource-controller/internal/scheme"
"github.com/k-orc/openstack-resource-controller/internal/scope"
// +kubebuilder:scaffold:imports
)
var defaultCACertsPath string
func main() {
setupLog := ctrl.Log.WithName("setup")
orcOpts := internalmanager.Options{}
flag.StringVar(&orcOpts.MetricsAddr, "metrics-bind-address", "0", "The address the metrics endpoint binds to. "+
"Use :8443 for HTTPS or :8080 for HTTP, or leave as 0 to disable the metrics service.")
flag.StringVar(&orcOpts.ProbeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flag.BoolVar(&orcOpts.EnableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
flag.BoolVar(&orcOpts.SecureMetrics, "metrics-secure", true,
"If set, the metrics endpoint is served securely via HTTPS. Use --metrics-secure=false to use HTTP instead.")
flag.BoolVar(&orcOpts.EnableHTTP2, "enable-http2", false,
"If set, HTTP/2 will be enabled for the metrics and webhook servers")
flag.IntVar(&orcOpts.ScopeCacheMaxSize, "scope-cache-max-size", 10,
"The maximum credentials count the operator should keep in cache. "+
"Setting this value to 0 means no cache.")
flag.StringVar(&defaultCACertsPath, "default-ca-certs", "",
"The path to a PEM-encoded CA Certificate file to supply as default for OpenStack API requests.")
zapOpts := zap.Options{
Development: true,
}
zapOpts.BindFlags(flag.CommandLine)
flag.Parse()
log := zap.New(zap.UseFlagOptions(&zapOpts))
ctrl.SetLogger(log)
// Setup the context that's going to be used in controllers and for the manager.
ctx := ctrl.SetupSignalHandler()
var caCerts []byte
if defaultCACertsPath != "" {
var err error
caCerts, err = os.ReadFile(defaultCACertsPath)
if err != nil {
setupLog.Error(err, "unable to read provided ca certificates file")
os.Exit(1)
}
}
scopeFactory := scope.NewFactory(orcOpts.ScopeCacheMaxSize, caCerts)
controllers := []export.Controller{
image.New(scopeFactory),
network.New(scopeFactory),
subnet.New(scopeFactory),
router.New(scopeFactory),
routerinterface.New(scopeFactory),
port.New(scopeFactory),
flavor.New(scopeFactory),
securitygroup.New(scopeFactory),
server.New(scopeFactory),
}
restConfig := ctrl.GetConfigOrDie()
err := internalmanager.Run(ctx, &orcOpts, restConfig, scheme.New(), setupLog, log, controllers)
if err != nil {
setupLog.Error(err, "Error starting manager")
os.Exit(1)
}
}