Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Organise code blocks in main.go file #884

Merged
merged 1 commit into from
Sep 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
209 changes: 111 additions & 98 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,106 +118,11 @@ func main() {
// Initialize event recorder.
record.InitFromRecorder(mgr.GetEventRecorderFor("ibmcloud-controller"))

if err = (&controllers.IBMVPCClusterReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("IBMVPCCluster"),
Recorder: mgr.GetEventRecorderFor("ibmvpccluster-controller"),
ServiceEndpoint: serviceEndpoint,
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "IBMVPCCluster")
os.Exit(1)
}
if err = (&controllers.IBMVPCMachineReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("IBMVPCMachine"),
Recorder: mgr.GetEventRecorderFor("ibmvpcmachine-controller"),
ServiceEndpoint: serviceEndpoint,
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "IBMVPCMachine")
os.Exit(1)
}
if err = (&controllers.IBMPowerVSClusterReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("IBMPowerVSCluster"),
Recorder: mgr.GetEventRecorderFor("ibmpowervscluster-controller"),
ServiceEndpoint: serviceEndpoint,
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "IBMPowerVSCluster")
os.Exit(1)
}
if err = (&controllers.IBMPowerVSMachineReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("IBMPowerVSMachine"),
Recorder: mgr.GetEventRecorderFor("ibmpowervsmachine-controller"),
ServiceEndpoint: serviceEndpoint,
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "IBMPowerVSMachine")
os.Exit(1)
}
if err = (&infrav1beta1.IBMPowerVSCluster{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "IBMPowerVSCluster")
os.Exit(1)
}
if err = (&infrav1beta1.IBMPowerVSMachine{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "IBMPowerVSMachine")
os.Exit(1)
}
if err = (&infrav1beta1.IBMPowerVSMachineTemplate{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "IBMPowerVSMachineTemplate")
os.Exit(1)
}
if err = (&infrav1beta1.IBMVPCMachine{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "IBMVPCMachine")
os.Exit(1)
}
if err = (&infrav1beta1.IBMVPCMachineTemplate{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "IBMVPCMachineTemplate")
os.Exit(1)
}
if err = (&infrav1beta1.IBMVPCCluster{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "IBMVPCCluster")
os.Exit(1)
}
if err = (&controllers.IBMPowerVSImageReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("IBMPowerVSImage"),
Recorder: mgr.GetEventRecorderFor("ibmpowervsimage-controller"),
ServiceEndpoint: serviceEndpoint,
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "IBMPowerVSImage")
os.Exit(1)
}
if err = (&infrav1beta1.IBMPowerVSImage{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "IBMPowerVSImage")
os.Exit(1)
}

if err = (&controllers.IBMPowerVSMachineTemplateReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("ibmpowervsmachinetemplate"),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "ibmpowervsmachinetemplate")
os.Exit(1)
}
setupReconcilers(mgr, serviceEndpoint)
setupWebhooks(mgr)
setupChecks(mgr)

// +kubebuilder:scaffold:builder

if err := mgr.AddReadyzCheck("webhook", mgr.GetWebhookServer().StartedChecker()); err != nil {
setupLog.Error(err, "unable to create ready check")
os.Exit(1)
}

if err := mgr.AddHealthzCheck("webhook", mgr.GetWebhookServer().StartedChecker()); err != nil {
setupLog.Error(err, "unable to create health check")
os.Exit(1)
}

setupLog.Info("starting manager")
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
setupLog.Error(err, "problem running manager")
Expand Down Expand Up @@ -289,3 +194,111 @@ func validateFlags() error {
}
return nil
}

func setupReconcilers(mgr ctrl.Manager, serviceEndpoint []endpoints.ServiceEndpoint) {
if err := (&controllers.IBMVPCClusterReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("IBMVPCCluster"),
Recorder: mgr.GetEventRecorderFor("ibmvpccluster-controller"),
ServiceEndpoint: serviceEndpoint,
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "IBMVPCCluster")
os.Exit(1)
}

if err := (&controllers.IBMVPCMachineReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("IBMVPCMachine"),
Recorder: mgr.GetEventRecorderFor("ibmvpcmachine-controller"),
ServiceEndpoint: serviceEndpoint,
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "IBMVPCMachine")
os.Exit(1)
}

if err := (&controllers.IBMPowerVSClusterReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("IBMPowerVSCluster"),
Recorder: mgr.GetEventRecorderFor("ibmpowervscluster-controller"),
ServiceEndpoint: serviceEndpoint,
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "IBMPowerVSCluster")
os.Exit(1)
}

if err := (&controllers.IBMPowerVSMachineReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("IBMPowerVSMachine"),
Recorder: mgr.GetEventRecorderFor("ibmpowervsmachine-controller"),
ServiceEndpoint: serviceEndpoint,
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "IBMPowerVSMachine")
os.Exit(1)
}

if err := (&controllers.IBMPowerVSImageReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("IBMPowerVSImage"),
Recorder: mgr.GetEventRecorderFor("ibmpowervsimage-controller"),
ServiceEndpoint: serviceEndpoint,
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "IBMPowerVSImage")
os.Exit(1)
}

if err := (&controllers.IBMPowerVSMachineTemplateReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("ibmpowervsmachinetemplate"),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "ibmpowervsmachinetemplate")
os.Exit(1)
}
}

func setupWebhooks(mgr ctrl.Manager) {
if err := (&infrav1beta1.IBMVPCCluster{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "IBMVPCCluster")
os.Exit(1)
}
if err := (&infrav1beta1.IBMVPCMachine{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "IBMVPCMachine")
os.Exit(1)
}
if err := (&infrav1beta1.IBMVPCMachineTemplate{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "IBMVPCMachineTemplate")
os.Exit(1)
}
if err := (&infrav1beta1.IBMPowerVSCluster{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "IBMPowerVSCluster")
os.Exit(1)
}
if err := (&infrav1beta1.IBMPowerVSMachine{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "IBMPowerVSMachine")
os.Exit(1)
}
if err := (&infrav1beta1.IBMPowerVSMachineTemplate{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "IBMPowerVSMachineTemplate")
os.Exit(1)
}
if err := (&infrav1beta1.IBMPowerVSImage{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "IBMPowerVSImage")
os.Exit(1)
}
}

func setupChecks(mgr ctrl.Manager) {
if err := mgr.AddReadyzCheck("webhook", mgr.GetWebhookServer().StartedChecker()); err != nil {
setupLog.Error(err, "unable to create ready check")
os.Exit(1)
}
if err := mgr.AddHealthzCheck("webhook", mgr.GetWebhookServer().StartedChecker()); err != nil {
setupLog.Error(err, "unable to create health check")
os.Exit(1)
}
}