forked from rabbitmq/messaging-topology-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
217 lines (201 loc) · 8.76 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/*
RabbitMQ Messaging Topology Kubernetes Operator
Copyright 2021 VMware, Inc.
This product is licensed to you under the Mozilla Public License 2.0 license (the "License"). You may not use this product except in compliance with the Mozilla 2.0 License.
This product may include a number of subcomponents with separate copyright notices and license terms. Your use of these subcomponents is subject to the terms and conditions of the subcomponent's license, as noted in the LICENSE file.
*/
package main
import (
"flag"
"os"
"k8s.io/apimachinery/pkg/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
rabbitmqv1beta1 "github.com/rabbitmq/cluster-operator/api/v1beta1"
topology "github.com/rabbitmq/messaging-topology-operator/api/v1beta1"
"github.com/rabbitmq/messaging-topology-operator/controllers"
"github.com/rabbitmq/messaging-topology-operator/internal"
// +kubebuilder:scaffold:imports
)
var (
scheme = runtime.NewScheme()
log = ctrl.Log.WithName("setup")
)
func init() {
_ = clientgoscheme.AddToScheme(scheme)
_ = rabbitmqv1beta1.AddToScheme(scheme)
_ = topology.AddToScheme(scheme)
// +kubebuilder:scaffold:scheme
}
func main() {
var metricsAddr string
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
flag.Parse()
ctrl.SetLogger(zap.New(zap.UseDevMode(true)))
operatorNamespace := os.Getenv("OPERATOR_NAMESPACE")
if operatorNamespace == "" {
log.Info("unable to find operator namespace")
os.Exit(1)
}
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
MetricsBindAddress: metricsAddr,
LeaderElection: true,
LeaderElectionNamespace: operatorNamespace,
LeaderElectionID: "messaging-topology-operator-leader-election",
})
if err != nil {
log.Error(err, "unable to start manager")
os.Exit(1)
}
if err = (&controllers.QueueReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName(controllers.QueueControllerName),
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor(controllers.QueueControllerName),
RabbitmqClientFactory: internal.RabbitholeClientFactory,
}).SetupWithManager(mgr); err != nil {
log.Error(err, "unable to create controller", "controller", controllers.QueueControllerName)
os.Exit(1)
}
if err = (&controllers.ExchangeReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName(controllers.ExchangeControllerName),
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor(controllers.ExchangeControllerName),
RabbitmqClientFactory: internal.RabbitholeClientFactory,
}).SetupWithManager(mgr); err != nil {
log.Error(err, "unable to create controller", "controller", controllers.ExchangeControllerName)
os.Exit(1)
}
if err = (&controllers.BindingReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName(controllers.BindingControllerName),
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor(controllers.BindingControllerName),
RabbitmqClientFactory: internal.RabbitholeClientFactory,
}).SetupWithManager(mgr); err != nil {
log.Error(err, "unable to create controller", "controller", controllers.BindingControllerName)
os.Exit(1)
}
if err = (&controllers.UserReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName(controllers.UserControllerName),
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor(controllers.UserControllerName),
RabbitmqClientFactory: internal.RabbitholeClientFactory,
}).SetupWithManager(mgr); err != nil {
log.Error(err, "unable to create controller", "controller", controllers.UserControllerName)
os.Exit(1)
}
if err = (&controllers.VhostReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName(controllers.VhostControllerName),
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor(controllers.VhostControllerName),
RabbitmqClientFactory: internal.RabbitholeClientFactory,
}).SetupWithManager(mgr); err != nil {
log.Error(err, "unable to create controller", "controller", controllers.VhostControllerName)
os.Exit(1)
}
if err = (&controllers.PolicyReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName(controllers.PolicyControllerName),
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor(controllers.PolicyControllerName),
RabbitmqClientFactory: internal.RabbitholeClientFactory,
}).SetupWithManager(mgr); err != nil {
log.Error(err, "unable to create controller", "controller", controllers.PolicyControllerName)
os.Exit(1)
}
if err = (&controllers.PermissionReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName(controllers.PermissionControllerName),
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor(controllers.PermissionControllerName),
RabbitmqClientFactory: internal.RabbitholeClientFactory,
}).SetupWithManager(mgr); err != nil {
log.Error(err, "unable to create controller", "controller", controllers.PermissionControllerName)
os.Exit(1)
}
if err = (&controllers.SchemaReplicationReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName(controllers.SchemaReplicationControllerName),
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor(controllers.SchemaReplicationControllerName),
RabbitmqClientFactory: internal.RabbitholeClientFactory,
}).SetupWithManager(mgr); err != nil {
log.Error(err, "unable to create controller", "controller", controllers.SchemaReplicationControllerName)
os.Exit(1)
}
if err = (&controllers.FederationReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName(controllers.FederationControllerName),
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor(controllers.FederationControllerName),
RabbitmqClientFactory: internal.RabbitholeClientFactory,
}).SetupWithManager(mgr); err != nil {
log.Error(err, "unable to create controller", "controller", controllers.FederationControllerName)
os.Exit(1)
}
if err = (&controllers.ShovelReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName(controllers.ShovelControllerName),
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor(controllers.ShovelControllerName),
RabbitmqClientFactory: internal.RabbitholeClientFactory,
}).SetupWithManager(mgr); err != nil {
log.Error(err, "unable to create controller", "controller", controllers.ShovelControllerName)
os.Exit(1)
}
if os.Getenv("ENABLE_WEBHOOKS") != "false" {
if err = (&topology.Binding{}).SetupWebhookWithManager(mgr); err != nil {
log.Error(err, "unable to create webhook", "webhook", "Binding")
os.Exit(1)
}
if err = (&topology.Queue{}).SetupWebhookWithManager(mgr); err != nil {
log.Error(err, "unable to create webhook", "webhook", "Queue")
os.Exit(1)
}
if err = (&topology.Exchange{}).SetupWebhookWithManager(mgr); err != nil {
log.Error(err, "unable to create webhook", "webhook", "Exchange")
os.Exit(1)
}
if err = (&topology.Vhost{}).SetupWebhookWithManager(mgr); err != nil {
log.Error(err, "unable to create webhook", "webhook", "Vhost")
os.Exit(1)
}
if err = (&topology.Policy{}).SetupWebhookWithManager(mgr); err != nil {
log.Error(err, "unable to create webhook", "webhook", "Policy")
os.Exit(1)
}
if err = (&topology.User{}).SetupWebhookWithManager(mgr); err != nil {
log.Error(err, "unable to create webhook", "webhook", "User")
os.Exit(1)
}
if err = (&topology.Permission{}).SetupWebhookWithManager(mgr); err != nil {
log.Error(err, "unable to create webhook", "webhook", "Permission")
os.Exit(1)
}
if err = (&topology.SchemaReplication{}).SetupWebhookWithManager(mgr); err != nil {
log.Error(err, "unable to create webhook", "webhook", "SchemaReplication")
os.Exit(1)
}
if err = (&topology.Federation{}).SetupWebhookWithManager(mgr); err != nil {
log.Error(err, "unable to create webhook", "webhook", "Federation")
os.Exit(1)
}
if err = (&topology.Shovel{}).SetupWebhookWithManager(mgr); err != nil {
log.Error(err, "unable to create webhook", "webhook", "Shovel")
os.Exit(1)
}
}
// +kubebuilder:scaffold:builder
log.Info("starting manager")
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
log.Error(err, "problem running manager")
os.Exit(1)
}
}