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

feat: add group in the controller logs for multi-group #1568

Merged
Merged
Show file tree
Hide file tree
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
7 changes: 2 additions & 5 deletions pkg/plugin/v3/scaffolds/internal/templates/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,9 @@ const (
os.Exit(1)
}
`
// TODO(v3): loggers for the same Kind controllers from different groups use the same logger.
// `.WithName("controllers").WithName(GROUP).WithName(KIND)` should be used instead. However,
// this is a backwards incompatible change, and thus should be done for next project version.
multiGroupReconcilerSetupCodeFragment = `if err = (&%scontrollers.%sReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("%s"),
Log: ctrl.Log.WithName("controllers").WithName("%s").WithName("%s"),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "%s")
Expand Down Expand Up @@ -173,7 +170,7 @@ func (f *MainUpdater) GetCodeFragments() file.CodeFragmentsMap {
f.Resource.Kind, f.Resource.Kind, f.Resource.Kind))
} else {
setup = append(setup, fmt.Sprintf(multiGroupReconcilerSetupCodeFragment,
f.Resource.GroupPackageName, f.Resource.Kind, f.Resource.Kind, f.Resource.Kind))
f.Resource.GroupPackageName, f.Resource.Kind, f.Resource.Group, f.Resource.Kind, f.Resource.Kind))
}
}
if f.WireWebhook {
Expand Down
14 changes: 7 additions & 7 deletions testdata/project-v3-multigroup/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func main() {

if err = (&crewcontrollers.CaptainReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("Captain"),
Log: ctrl.Log.WithName("controllers").WithName("crew").WithName("Captain"),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Captain")
Expand All @@ -96,7 +96,7 @@ func main() {
}
if err = (&shipcontrollers.FrigateReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("Frigate"),
Log: ctrl.Log.WithName("controllers").WithName("ship").WithName("Frigate"),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Frigate")
Expand All @@ -108,39 +108,39 @@ func main() {
}
if err = (&shipcontrollers.DestroyerReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("Destroyer"),
Log: ctrl.Log.WithName("controllers").WithName("ship").WithName("Destroyer"),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Destroyer")
os.Exit(1)
}
if err = (&shipcontrollers.CruiserReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("Cruiser"),
Log: ctrl.Log.WithName("controllers").WithName("ship").WithName("Cruiser"),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Cruiser")
os.Exit(1)
}
if err = (&seacreaturescontrollers.KrakenReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("Kraken"),
Log: ctrl.Log.WithName("controllers").WithName("sea-creatures").WithName("Kraken"),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Kraken")
os.Exit(1)
}
if err = (&seacreaturescontrollers.LeviathanReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("Leviathan"),
Log: ctrl.Log.WithName("controllers").WithName("sea-creatures").WithName("Leviathan"),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Leviathan")
os.Exit(1)
}
if err = (&foopolicycontrollers.HealthCheckPolicyReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("HealthCheckPolicy"),
Log: ctrl.Log.WithName("controllers").WithName("foo.policy").WithName("HealthCheckPolicy"),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "HealthCheckPolicy")
Expand Down