Skip to content

Commit

Permalink
Switch Event controller to controller-runtime (gardener#6550)
Browse files Browse the repository at this point in the history
* Enhance documentation

* Add integration test

* Switch controller to native controller-runtime controller

* [PR feedback] use clock.Clock in the controller

* Address PR review feedback
  • Loading branch information
ary1992 authored and shafeeqes committed Aug 23, 2022
1 parent 7385212 commit bf14831
Show file tree
Hide file tree
Showing 11 changed files with 491 additions and 395 deletions.
2 changes: 1 addition & 1 deletion docs/concepts/controller-manager.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ Since the other two reconcilers are unable to actively monitor the relevant obje

The `Project Activity Reconciler` is implemented to take care of such cases. An event handler will notify the reconciler for any acitivity and then it will update the `status.lastActivityTimestamp`. This update will also trigger the `Stale Project Reconciler`.

### Event Controller
### [Event Controller](../../pkg/controllermanager/controller/event)

With the Gardener Event Controller you can prolong the lifespan of events related to Shoot clusters.
This is an optional controller which will become active once you provide the below mentioned configuration.
Expand Down
10 changes: 10 additions & 0 deletions pkg/controllermanager/controller/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/gardener/gardener/pkg/controllermanager/controller/bastion"
"github.com/gardener/gardener/pkg/controllermanager/controller/cloudprofile"
"github.com/gardener/gardener/pkg/controllermanager/controller/controllerdeployment"
"github.com/gardener/gardener/pkg/controllermanager/controller/event"
"github.com/gardener/gardener/pkg/controllermanager/controller/exposureclass"
"github.com/gardener/gardener/pkg/controllermanager/controller/quota"

Expand Down Expand Up @@ -64,6 +65,15 @@ func AddControllersToManager(mgr manager.Manager, cfg *config.ControllerManagerC
return fmt.Errorf("failed adding Quota controller: %w", err)
}

if evenControllerConfig := cfg.Controllers.Event; evenControllerConfig != nil {
if err := (&event.Reconciler{
Clock: clock.RealClock{},
Config: *cfg.Controllers.Event,
}).AddToManager(mgr); err != nil {
return fmt.Errorf("failed adding Event controller: %w", err)
}
}

return nil
}

Expand Down
51 changes: 51 additions & 0 deletions pkg/controllermanager/controller/event/add.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (c) 2022 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package event

import (
corev1 "k8s.io/api/core/v1"
"k8s.io/utils/pointer"

"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/predicate"
)

// ControllerName is the name of this controller.
const ControllerName = "event"

// AddToManager adds Reconciler to the given manager.
func (r *Reconciler) AddToManager(mgr manager.Manager) error {
if r.Client == nil {
r.Client = mgr.GetClient()
}

return builder.
ControllerManagedBy(mgr).
Named(ControllerName).
For(&corev1.Event{}, builder.WithPredicates(predicate.Funcs{
CreateFunc: func(e event.CreateEvent) bool { return true },
UpdateFunc: func(e event.UpdateEvent) bool { return false },
DeleteFunc: func(e event.DeleteEvent) bool { return false },
GenericFunc: func(e event.GenericEvent) bool { return false },
})).
WithOptions(controller.Options{
MaxConcurrentReconciles: pointer.IntDeref(r.Config.ConcurrentSyncs, 0),
RecoverPanic: true,
}).
Complete(r)
}
131 changes: 0 additions & 131 deletions pkg/controllermanager/controller/event/event.go

This file was deleted.

Loading

0 comments on commit bf14831

Please sign in to comment.