Skip to content

Commit

Permalink
Making CRDAppFactory an interface
Browse files Browse the repository at this point in the history
Signed-off-by: Yash Sethiya <[email protected]>
  • Loading branch information
sethiyash committed Feb 26, 2024
1 parent 8d2a1c9 commit d46919f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cmd/controller/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func Run(opts Options, runLog logr.Logger) error {
CacheFolder: cacheFolderApps,
}
reconciler := app.NewReconciler(kcClient, runLog.WithName("app"),
appFactory, refTracker, updateStatusTracker, compInfo)
&appFactory, refTracker, updateStatusTracker, compInfo)

ctrl, err := controller.New("app", mgr, controller.Options{
Reconciler: NewUniqueReconciler(&ErrReconciler{
Expand Down
5 changes: 5 additions & 0 deletions pkg/app/app_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ import (
"k8s.io/client-go/kubernetes"
)

// ICRDAppFactory interface for CRDAppFactory
type ICRDAppFactory interface {
NewCRDApp(*kcv1alpha1.App, logr.Logger) *CRDApp
}

// CRDAppFactory allows to create CRDApps.
type CRDAppFactory struct {
CoreClient kubernetes.Interface
Expand Down
4 changes: 2 additions & 2 deletions pkg/app/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ import (
type Reconciler struct {
appClient kcclient.Interface
log logr.Logger
crdAppFactory CRDAppFactory
crdAppFactory ICRDAppFactory
appRefTracker *reftracker.AppRefTracker
appUpdateStatus *reftracker.AppUpdateStatus
componentInfo ComponentInfo
}

// NewReconciler constructs new Reconciler.
func NewReconciler(appClient kcclient.Interface, log logr.Logger, crdAppFactory CRDAppFactory,
func NewReconciler(appClient kcclient.Interface, log logr.Logger, crdAppFactory ICRDAppFactory,
appRefTracker *reftracker.AppRefTracker, appUpdateStatus *reftracker.AppUpdateStatus, componentInfo ComponentInfo) *Reconciler {
return &Reconciler{appClient: appClient,
log: log,
Expand Down
4 changes: 2 additions & 2 deletions pkg/app/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func Test_AppRefTracker_HasAppRemovedForSecrets_ThatAreNoLongerUsedByApp(t *test
appKey := reftracker.NewAppKey(app.Name, app.Namespace)
appRefTracker.ReconcileRefs(refKeyMap, appKey)

ar := apppkg.NewReconciler(nil, testr.New(t), apppkg.CRDAppFactory{}, appRefTracker, nil, FakeComponentInfo{})
ar := apppkg.NewReconciler(nil, testr.New(t), &apppkg.CRDAppFactory{}, appRefTracker, nil, FakeComponentInfo{})

// This map represents the secrets the App has on its spec
refMap := map[reftracker.RefKey]struct{}{
Expand Down Expand Up @@ -90,7 +90,7 @@ func Test_AppRefTracker_HasNoAppsRemoved_WhenRefsRemainSame(t *testing.T) {
appKey := reftracker.NewAppKey(app.Name, app.Namespace)
appRefTracker.ReconcileRefs(refKeyMap, appKey)

ar := apppkg.NewReconciler(nil, testr.New(t), apppkg.CRDAppFactory{}, appRefTracker, nil, FakeComponentInfo{})
ar := apppkg.NewReconciler(nil, testr.New(t), &apppkg.CRDAppFactory{}, appRefTracker, nil, FakeComponentInfo{})

// This map represents the secrets the App has
// on its spec
Expand Down

0 comments on commit d46919f

Please sign in to comment.