Skip to content

Commit

Permalink
Feat: Adding integration function for fleet (#99)
Browse files Browse the repository at this point in the history
* initial commit

* changed all controllers to use unmanaged

* removed unmanaged

* comment fix

Co-authored-by: Youn Jae Kim <[email protected]>
  • Loading branch information
aagusuab and aagusuab authored Aug 4, 2022
1 parent 6adc723 commit 7d4503e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 17 deletions.
11 changes: 11 additions & 0 deletions pkg/controllers/apply_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ type ApplyWorkReconciler struct {
concurrency int
}

func NewApplyWorkReconciler(hubClient client.Client, spokeDynamicClient dynamic.Interface, spokeClient client.Client, restMapper meta.RESTMapper, recorder record.EventRecorder, concurrency int) *ApplyWorkReconciler {
return &ApplyWorkReconciler{
client: hubClient,
spokeDynamicClient: spokeDynamicClient,
spokeClient: spokeClient,
restMapper: restMapper,
recorder: recorder,
concurrency: concurrency,
}
}

// applyResult contains the result of a manifest being applied.
type applyResult struct {
identifier workv1alpha1.ResourceIdentifier
Expand Down
8 changes: 8 additions & 0 deletions pkg/controllers/finalize_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ type FinalizeWorkReconciler struct {
recorder record.EventRecorder
}

func NewFinalizeWorkReconciler(hubClient client.Client, spokeClient client.Client, recorder record.EventRecorder) *FinalizeWorkReconciler {
return &FinalizeWorkReconciler{
client: hubClient,
spokeClient: spokeClient,
recorder: recorder,
}
}

// Reconcile implement the control loop logic for finalizing Work object.
func (r *FinalizeWorkReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
klog.InfoS("Work finalize controller reconcile loop triggered.", "item", req.NamespacedName)
Expand Down
30 changes: 15 additions & 15 deletions pkg/controllers/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ func Start(ctx context.Context, hubCfg, spokeCfg *rest.Config, setupLog logr.Log
os.Exit(1)
}

if err = newWorkStatusReconciler(
if err = NewWorkStatusReconciler(
hubMgr.GetClient(),
spokeClient,
spokeDynamicClient,
spokeClient,
restMapper,
hubMgr.GetEventRecorderFor("work_status_controller"),
maxWorkConcurrency,
Expand All @@ -81,23 +81,23 @@ func Start(ctx context.Context, hubCfg, spokeCfg *rest.Config, setupLog logr.Log
return err
}

if err = (&ApplyWorkReconciler{
client: hubMgr.GetClient(),
spokeDynamicClient: spokeDynamicClient,
spokeClient: spokeClient,
restMapper: restMapper,
recorder: hubMgr.GetEventRecorderFor("work_controller"),
concurrency: maxWorkConcurrency,
}).SetupWithManager(hubMgr); err != nil {
if err = NewApplyWorkReconciler(
hubMgr.GetClient(),
spokeDynamicClient,
spokeClient,
restMapper,
hubMgr.GetEventRecorderFor("work_controller"),
maxWorkConcurrency,
).SetupWithManager(hubMgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Work")
return err
}

if err = (&FinalizeWorkReconciler{
client: hubMgr.GetClient(),
recorder: hubMgr.GetEventRecorderFor("WorkFinalizer_controller"),
spokeClient: spokeClient,
}).SetupWithManager(hubMgr); err != nil {
if err = NewFinalizeWorkReconciler(
hubMgr.GetClient(),
spokeClient,
hubMgr.GetEventRecorderFor("WorkFinalizer_controller"),
).SetupWithManager(hubMgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "WorkFinalize")
return err
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/controllers/work_status_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package controllers

import (
"context"

"github.com/pkg/errors"
v1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -47,7 +46,7 @@ type WorkStatusReconciler struct {
concurrency int
}

func newWorkStatusReconciler(hubClient client.Client, spokeClient client.Client, spokeDynamicClient dynamic.Interface, restMapper meta.RESTMapper, recorder record.EventRecorder, concurrency int) *WorkStatusReconciler {
func NewWorkStatusReconciler(hubClient client.Client, spokeDynamicClient dynamic.Interface, spokeClient client.Client, restMapper meta.RESTMapper, recorder record.EventRecorder, concurrency int) *WorkStatusReconciler {
return &WorkStatusReconciler{
appliedResourceTracker: appliedResourceTracker{
hubClient: hubClient,
Expand Down

0 comments on commit 7d4503e

Please sign in to comment.