Skip to content

Commit

Permalink
Remove pointer for config
Browse files Browse the repository at this point in the history
Specifying a nil config is not a valid thing to do.
Otherwise, `AddToManager` would panic.
Hence, rather take a zero value config and take care of correctly handling unset fields.
This is semantically better, as we can't be sure that the given config struct is a real
(i.e. defaulted) object, e.g. in integration tests we don't do defaulting for the config.
  • Loading branch information
timebertt committed Jul 21, 2022
1 parent ceec51b commit a173f8a
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/controllermanager/controller/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
// AddControllersToManager adds all controller-manager controllers to the given manager.
func AddControllersToManager(mgr manager.Manager, cfg *config.ControllerManagerConfiguration) error {
if err := (&cloudprofile.Reconciler{
Config: cfg.Controllers.CloudProfile,
Config: *cfg.Controllers.CloudProfile,
}).AddToManager(mgr); err != nil {
return fmt.Errorf("failed adding CloudProfile controller: %w", err)
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/controllermanager/controller/cloudprofile/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package cloudprofile

import (
"k8s.io/utils/pointer"

gardencorev1beta1 "github.com/gardener/gardener/pkg/apis/core/v1beta1"

"sigs.k8s.io/controller-runtime/pkg/builder"
Expand All @@ -39,7 +41,7 @@ func (r *Reconciler) AddToManager(mgr manager.Manager) error {
Named(ControllerName).
For(&gardencorev1beta1.CloudProfile{}).
WithOptions(controller.Options{
MaxConcurrentReconciles: *r.Config.ConcurrentSyncs,
MaxConcurrentReconciles: pointer.IntDeref(r.Config.ConcurrentSyncs, 0),
RecoverPanic: true,
}).
Complete(r)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
// Reconciler reconciles CloudProfiles.
type Reconciler struct {
Client client.Client
Config *config.CloudProfileControllerConfiguration
Config config.CloudProfileControllerConfiguration
Recorder record.EventRecorder
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ var _ = BeforeSuite(func() {

By("registering controller")
Expect((&cloudprofilecontroller.Reconciler{
Config: &config.CloudProfileControllerConfiguration{
Config: config.CloudProfileControllerConfiguration{
ConcurrentSyncs: pointer.Int(5),
},
}).AddToManager(mgr)).To(Succeed())
Expand Down

0 comments on commit a173f8a

Please sign in to comment.