Skip to content

Commit

Permalink
Fix#106 (#71)
Browse files Browse the repository at this point in the history
* fix namespaceconfig #106

Signed-off-by: raffaelespazzoli <[email protected]>

* removed comments

Signed-off-by: raffaelespazzoli <[email protected]>
  • Loading branch information
raffaelespazzoli authored Jun 23, 2021
1 parent 2eaf121 commit b2bd132
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ in main.go change like this

```go
if err = (&controllers.MyReconciler{
ReconcilerBase: util.NewReconcilerBase(mgr.GetClient(), mgr.GetScheme(), mgr.GetConfig(), mgr.GetEventRecorderFor("My_controller")),
ReconcilerBase: util.NewReconcilerBase(mgr.GetClient(), mgr.GetScheme(), mgr.GetConfig(), mgr.GetEventRecorderFor("My_controller"), mgr.GetAPIReader()),
Log: ctrl.Log.WithName("controllers").WithName("My"),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "My")
Expand Down
21 changes: 8 additions & 13 deletions pkg/util/lockedresourcecontroller/resource-reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type LockedResourceReconciler struct {
statusChange chan<- event.GenericEvent
statusLock sync.Mutex
parentObject client.Object
creationFailed chan event.GenericEvent
firstReconcile chan event.GenericEvent
log logr.Logger
}

Expand All @@ -57,7 +57,7 @@ func NewLockedObjectReconciler(mgr manager.Manager, object unstructured.Unstruct
statusChange: statusChange,
parentObject: parentObject,
statusLock: sync.Mutex{},
creationFailed: make(chan event.GenericEvent),
firstReconcile: make(chan event.GenericEvent),
status: []metav1.Condition([]metav1.Condition{{
Type: "Initializing",
LastTransitionTime: metav1.Now(),
Expand All @@ -67,16 +67,11 @@ func NewLockedObjectReconciler(mgr manager.Manager, object unstructured.Unstruct
}}),
}

err := reconciler.CreateOrUpdateResource(context.TODO(), nil, "", object.DeepCopy())
if err != nil {
reconciler.log.Error(err, "unable to create or update", "resource", object)
reconciler.manageErrorNoInstance(err)
go func() {
reconciler.creationFailed <- event.GenericEvent{
Object: &object,
}
}()
}
go func() {
reconciler.firstReconcile <- event.GenericEvent{
Object: &object,
}
}()

controller, err := controller.New("controller_locked_object_"+apis.GetKeyLong(&object), mgr, controller.Options{Reconciler: reconciler})
if err != nil {
Expand All @@ -100,7 +95,7 @@ func NewLockedObjectReconciler(mgr manager.Manager, object unstructured.Unstruct
}

err = controller.Watch(
&source.Channel{Source: reconciler.creationFailed},
&source.Channel{Source: reconciler.firstReconcile},
&handler.EnqueueRequestForObject{},
)
if err != nil {
Expand Down

0 comments on commit b2bd132

Please sign in to comment.