Skip to content

Commit

Permalink
feat: add group in the controller logs for multi-group
Browse files Browse the repository at this point in the history
  • Loading branch information
Camila Macedo committed Jun 19, 2020
1 parent 7ae3d94 commit 39bfdb1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
7 changes: 5 additions & 2 deletions pkg/plugin/v3/scaffolds/internal/templates/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ const (
`
controllerImportCodeFragment = `"%s/controllers"
`
multiGroupControllerImportCodeFragment = `%scontrollers "%s/controllers/%s"
// TODO(v3): `&%scontrollers` should be used instead of `&%scontroller` as there may be multiple
// controller for different Kinds in the same group. However, this is a backwards incompatible
// change, and thus should be done for next project version.
multiGroupControllerImportCodeFragment = `%scontroller "%s/controllers/%s"
`
addschemeCodeFragment = `utilruntime.Must(%s.AddToScheme(scheme))
`
Expand All @@ -121,7 +124,7 @@ const (
os.Exit(1)
}
`
multiGroupReconcilerSetupCodeFragment = `if err = (&%scontrollers.%sReconciler{
multiGroupReconcilerSetupCodeFragment = `if err = (&%scontroller.%sReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("%s").WithName("%s"),
Scheme: mgr.GetScheme(),
Expand Down
22 changes: 11 additions & 11 deletions testdata/project-v3-multigroup/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ import (
shipv1 "sigs.k8s.io/kubebuilder/testdata/project-v3-multigroup/apis/ship/v1"
shipv1beta1 "sigs.k8s.io/kubebuilder/testdata/project-v3-multigroup/apis/ship/v1beta1"
shipv2alpha1 "sigs.k8s.io/kubebuilder/testdata/project-v3-multigroup/apis/ship/v2alpha1"
crewcontrollers "sigs.k8s.io/kubebuilder/testdata/project-v3-multigroup/controllers/crew"
foopolicycontrollers "sigs.k8s.io/kubebuilder/testdata/project-v3-multigroup/controllers/foo.policy"
seacreaturescontrollers "sigs.k8s.io/kubebuilder/testdata/project-v3-multigroup/controllers/sea-creatures"
shipcontrollers "sigs.k8s.io/kubebuilder/testdata/project-v3-multigroup/controllers/ship"
crewcontroller "sigs.k8s.io/kubebuilder/testdata/project-v3-multigroup/controllers/crew"
foopolicycontroller "sigs.k8s.io/kubebuilder/testdata/project-v3-multigroup/controllers/foo.policy"
seacreaturescontroller "sigs.k8s.io/kubebuilder/testdata/project-v3-multigroup/controllers/sea-creatures"
shipcontroller "sigs.k8s.io/kubebuilder/testdata/project-v3-multigroup/controllers/ship"
// +kubebuilder:scaffold:imports
)

Expand Down Expand Up @@ -82,7 +82,7 @@ func main() {
os.Exit(1)
}

if err = (&crewcontrollers.CaptainReconciler{
if err = (&crewcontroller.CaptainReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("crew").WithName("Captain"),
Scheme: mgr.GetScheme(),
Expand All @@ -94,7 +94,7 @@ func main() {
setupLog.Error(err, "unable to create webhook", "webhook", "Captain")
os.Exit(1)
}
if err = (&shipcontrollers.FrigateReconciler{
if err = (&shipcontroller.FrigateReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("ship").WithName("Frigate"),
Scheme: mgr.GetScheme(),
Expand All @@ -106,39 +106,39 @@ func main() {
setupLog.Error(err, "unable to create webhook", "webhook", "Frigate")
os.Exit(1)
}
if err = (&shipcontrollers.DestroyerReconciler{
if err = (&shipcontroller.DestroyerReconciler{
Client: mgr.GetClient(),
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{
if err = (&shipcontroller.CruiserReconciler{
Client: mgr.GetClient(),
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{
if err = (&seacreaturescontroller.KrakenReconciler{
Client: mgr.GetClient(),
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{
if err = (&seacreaturescontroller.LeviathanReconciler{
Client: mgr.GetClient(),
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{
if err = (&foopolicycontroller.HealthCheckPolicyReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("foo.policy").WithName("HealthCheckPolicy"),
Scheme: mgr.GetScheme(),
Expand Down

0 comments on commit 39bfdb1

Please sign in to comment.