Skip to content

Commit 3710ef1

Browse files
refact: move GetSelectedEmployeeNames to ReconcileLifecycleOptions an… (#52)
refact: move GetSelectedEmployeeNames to ReconcileLifecycleOptions and support record status if ReconcileRequeueOptions implemented
1 parent 0373350 commit 3710ef1

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

pkg/frame/controller/consister.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ func (r *Consist) syncEmployees(ctx context.Context, employer client.Object, exp
214214
needRecordEmployees := lifecycleOptionsImplemented && lifecycleOptions.FollowPodOpsLifeCycle() && lifecycleOptions.NeedRecordLifecycleFinalizerCondition()
215215
if needRecordEmployees {
216216
if employer.GetAnnotations()[lifecycleFinalizerRecordedAnnoKey] != "" {
217-
selectedEmployees, err := r.adapter.GetSelectedEmployeeNames(ctx, employer)
217+
selectedEmployees, err := lifecycleOptions.GetSelectedEmployeeNames(ctx, employer)
218218
if err != nil {
219219
return false, false, CUDEmployeeResults{}, fmt.Errorf("GetSelectedEmployeeNames failed, err: %s", err.Error())
220220
}
@@ -297,7 +297,7 @@ func (r *Consist) ensureExpectedFinalizer(ctx context.Context, employer client.O
297297
return true, nil
298298
}
299299

300-
selectedEmployeeNames, err := r.adapter.GetSelectedEmployeeNames(ctx, employer)
300+
selectedEmployeeNames, err := lifecycleOptions.GetSelectedEmployeeNames(ctx, employer)
301301
if err != nil {
302302
return false, fmt.Errorf("get selected employees' names failed, err: %s", err.Error())
303303
}

pkg/frame/controller/resourceconsist_controller.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -254,14 +254,6 @@ func (r *Consist) Reconcile(ctx context.Context, request reconcile.Request) (rec
254254
}
255255
}
256256

257-
if syncEmployerFailedExist || syncEmployeeFailedExist {
258-
requeueOptions, requeueOptionsImplemented := r.adapter.(ReconcileRequeueOptions)
259-
if requeueOptionsImplemented {
260-
return reconcile.Result{RequeueAfter: requeueOptions.EmployeeSyncRequeueInterval()}, nil
261-
}
262-
return reconcile.Result{}, fmt.Errorf("employer or employees synced failed exist")
263-
}
264-
265257
if recordOptions, ok := r.adapter.(StatusRecordOptions); ok {
266258
err = recordOptions.RecordStatuses(ctx, employer, cudEmployerResults, cudEmployeeResults)
267259
if err != nil {
@@ -272,5 +264,13 @@ func (r *Consist) Reconcile(ctx context.Context, request reconcile.Request) (rec
272264
}
273265
}
274266

267+
if syncEmployerFailedExist || syncEmployeeFailedExist {
268+
requeueOptions, requeueOptionsImplemented := r.adapter.(ReconcileRequeueOptions)
269+
if requeueOptionsImplemented {
270+
return reconcile.Result{RequeueAfter: requeueOptions.EmployeeSyncRequeueInterval()}, nil
271+
}
272+
return reconcile.Result{}, fmt.Errorf("employer or employees synced failed exist")
273+
}
274+
275275
return reconcile.Result{}, nil
276276
}

pkg/frame/controller/types.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ type ReconcileLifecycleOptions interface {
8888
// NeedRecordLifecycleFinalizerCondition only needed for those adapters that follow PodOpsLifecycle,
8989
// in the case of employment relationship might change and resources in backend provider might be changed by others.
9090
NeedRecordLifecycleFinalizerCondition() bool
91+
92+
// GetSelectedEmployeeNames returns employees' names selected by employer
93+
// note: in multi cluster case, if adapters deployed in fed and employees are under local, the format of employeeName
94+
// should be "employeeName" + "#" + "clusterName"
95+
GetSelectedEmployeeNames(ctx context.Context, employer client.Object) ([]string, error)
9196
}
9297

9398
type ReconcileRequeueOptions interface {
@@ -99,11 +104,6 @@ type ReconcileRequeueOptions interface {
99104
type ReconcileAdapter interface {
100105
GetControllerName() string
101106

102-
// GetSelectedEmployeeNames returns employees' names selected by employer
103-
// note: in multi cluster case, if adapters deployed in fed and employees are under local, the format of employeeName
104-
// should be "employeeName" + "#" + "clusterName"
105-
GetSelectedEmployeeNames(ctx context.Context, employer client.Object) ([]string, error)
106-
107107
// GetExpectedEmployer and GetCurrentEmployer return expect/current status of employer from related backend provider
108108
GetExpectedEmployer(ctx context.Context, employer client.Object) ([]IEmployer, error)
109109
GetCurrentEmployer(ctx context.Context, employer client.Object) ([]IEmployer, error)
@@ -134,6 +134,7 @@ type IEmployee interface {
134134
// GetEmployeeName returns employee's name
135135
// note: in multi cluster case, if adapters deployed in fed and employees are under local, the format of employeeName
136136
// should be "employeeName" + "#" + "clusterName"
137+
// GetEmployeeName need to be implemented if follow Lifecycle
137138
GetEmployeeName() string
138139
GetEmployeeStatuses() interface{}
139140
EmployeeEqual(employee IEmployee) (bool, error)

0 commit comments

Comments
 (0)