in main.go [103:239]
func main() {
namespace = os.Getenv(EnvOperatorPodNamespace)
if len(namespace) == 0 {
//log.Fatalf("must set env (%s)", constants.EnvOperatorPodNamespace)
}
name = os.Getenv(EnvOperatorPodName)
if len(name) == 0 {
//log.Fatalf("must set env (%s)", constants.EnvOperatorPodName)
}
var metricsAddr string
var enableLeaderElection bool
var probeAddr string
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flag.BoolVar(&enableLeaderElection, "leader-elect", true,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
opts := zap.Options{
Development: true,
}
opts.BindFlags(flag.CommandLine)
flag.Parse()
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))
fullVersion := version.Version
if version.VersionSuffix != "" {
fullVersion += "-" + version.VersionSuffix
}
setupLog.Info(fmt.Sprintf("solr-operator Version: %v", fullVersion))
setupLog.Info(fmt.Sprintf("solr-operator Git SHA: %s", version.GitSHA))
setupLog.Info(fmt.Sprintf("solr-operator Build Time: %s", version.BuildTime))
setupLog.Info(fmt.Sprintf("Go Version: %v", runtime.Version()))
setupLog.Info(fmt.Sprintf("Go OS/Arch: %s / %s", runtime.GOOS, runtime.GOARCH))
operatorOptions := ctrl.Options{
Scheme: scheme,
Metrics: metricsserver.Options{BindAddress: metricsAddr},
HealthProbeBindAddress: probeAddr,
LeaderElection: enableLeaderElection,
LeaderElectionNamespace: namespace,
LeaderElectionID: "88488bdc.solr.apache.org",
}
/*
When the operator is started to watch resources in a specific set of namespaces, we use DefaultNamespaces, which will build us a MultiNamespacedCache.
In this scenario, it is also suggested to restrict the provided authorization to this namespace by replacing the default
ClusterRole and ClusterRoleBinding to Role and RoleBinding respectively
For further information see the kubernetes documentation about
Using [RBAC Authorization](https://kubernetes.io/docs/reference/access-authn-authz/rbac/).
When watching multiple namespaces with leader election enabled, the leader election will use the lowest-sorted namespace.
It is likely safer to run individual solr operators per-namespace, to ensure leader election is working as expected no matter what.
*/
if watchNamespaces != "" {
setupLog.Info(fmt.Sprintf("Managing for Namespaces: %s", watchNamespaces))
nsList := strings.Split(watchNamespaces, ",")
nsMap := make(map[string]cache.Config, len(nsList))
leaderElectionNamespace := ""
for i, ns := range nsList {
ns = strings.TrimSpace(ns)
if i == 0 {
leaderElectionNamespace = ns
}
// nil will have the namespace use the default settings
nsMap[ns] = cache.Config{}
}
operatorOptions.Cache.DefaultNamespaces = nsMap
operatorOptions.LeaderElectionNamespace = leaderElectionNamespace
}
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), operatorOptions)
if err != nil {
setupLog.Error(err, "unable to start solr operator")
os.Exit(1)
}
controllers.UseZkCRD(useZookeeperCRD)
// watch TLS files for update
if clientCertPath != "" {
var watcher *fsnotify.Watcher
if clientCertWatch {
watcher, err = fsnotify.NewWatcher()
if err != nil {
setupLog.Error(err, "Create new file watcher failed")
os.Exit(1)
}
defer watcher.Close()
}
if err = initMTLSConfig(watcher); err != nil {
os.Exit(1)
}
}
if err = (&controllers.SolrCloudReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "SolrCloud")
os.Exit(1)
}
if err = (&controllers.SolrPrometheusExporterReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "SolrPrometheusExporter")
os.Exit(1)
}
if err = (&controllers.SolrBackupReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Config: mgr.GetConfig(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "SolrBackup")
os.Exit(1)
}
//+kubebuilder:scaffold:builder
if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
setupLog.Error(err, "unable to set up health check")
os.Exit(1)
}
if err := mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil {
setupLog.Error(err, "unable to set up ready check")
os.Exit(1)
}
setupLog.Info("starting manager")
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
setupLog.Error(err, "problem running manager")
os.Exit(1)
}
}