Skip to content

Commit

Permalink
mock a backend provider for demo controller
Browse files Browse the repository at this point in the history
  • Loading branch information
WeichengWang1 committed Sep 20, 2023
1 parent a2e0925 commit 9f61008
Show file tree
Hide file tree
Showing 9 changed files with 300 additions and 385 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ require (
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/tjfoc/gmsm v1.3.2 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
Expand Down
22 changes: 11 additions & 11 deletions pkg/controllers/alibabacloudslb/alibabacloudslb_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (r *ReconcileAdapter) NotFollowPodOpsLifeCycle() bool {
return false
}

func (r *ReconcileAdapter) GetExpectEmployer(ctx context.Context, employer client.Object) ([]resourceconsist.IEmployer, error) {
func (r *ReconcileAdapter) GetExpectedEmployer(ctx context.Context, employer client.Object) ([]resourceconsist.IEmployer, error) {
return nil, nil
}

Expand Down Expand Up @@ -85,19 +85,19 @@ func (r *ReconcileAdapter) GetCurrentEmployer(ctx context.Context, employer clie
return nil, nil
}

func (r *ReconcileAdapter) CreateEmployer(employer client.Object, toCreate []resourceconsist.IEmployer) ([]resourceconsist.IEmployer, []resourceconsist.IEmployer, error) {
func (r *ReconcileAdapter) CreateEmployer(ctx context.Context, employer client.Object, toCreates []resourceconsist.IEmployer) ([]resourceconsist.IEmployer, []resourceconsist.IEmployer, error) {
return nil, nil, nil
}

func (r *ReconcileAdapter) UpdateEmployer(employer client.Object, toUpdate []resourceconsist.IEmployer) ([]resourceconsist.IEmployer, []resourceconsist.IEmployer, error) {
func (r *ReconcileAdapter) UpdateEmployer(ctx context.Context, employer client.Object, toUpdates []resourceconsist.IEmployer) ([]resourceconsist.IEmployer, []resourceconsist.IEmployer, error) {
return nil, nil, nil
}

func (r *ReconcileAdapter) DeleteEmployer(employer client.Object, toDelete []resourceconsist.IEmployer) ([]resourceconsist.IEmployer, []resourceconsist.IEmployer, error) {
func (r *ReconcileAdapter) DeleteEmployer(ctx context.Context, employer client.Object, toDeletes []resourceconsist.IEmployer) ([]resourceconsist.IEmployer, []resourceconsist.IEmployer, error) {
return nil, nil, nil
}

func (r *ReconcileAdapter) GetExpectEmployee(ctx context.Context, employer client.Object) ([]resourceconsist.IEmployee, error) {
func (r *ReconcileAdapter) GetExpectedEmployee(ctx context.Context, employer client.Object) ([]resourceconsist.IEmployee, error) {
svc, ok := employer.(*corev1.Service)
if !ok {
return nil, fmt.Errorf("expect employer kind is Service")
Expand Down Expand Up @@ -182,16 +182,16 @@ func (r *ReconcileAdapter) GetCurrentEmployee(ctx context.Context, employer clie
}

// CreateEmployees returns (nil, toCreate, nil) since CCM of ACK will sync bs of slb
func (r *ReconcileAdapter) CreateEmployees(employer client.Object, toCreate []resourceconsist.IEmployee) ([]resourceconsist.IEmployee, []resourceconsist.IEmployee, error) {
return nil, toCreate, nil
func (r *ReconcileAdapter) CreateEmployees(ctx context.Context, employer client.Object, toCreates []resourceconsist.IEmployee) ([]resourceconsist.IEmployee, []resourceconsist.IEmployee, error) {
return nil, toCreates, nil
}

// UpdateEmployees returns (nil, toUpdate, nil) since CCM of ACK will sync bs of slb
func (r *ReconcileAdapter) UpdateEmployees(employer client.Object, toUpdate []resourceconsist.IEmployee) ([]resourceconsist.IEmployee, []resourceconsist.IEmployee, error) {
return nil, toUpdate, nil
func (r *ReconcileAdapter) UpdateEmployees(ctx context.Context, employer client.Object, toUpdates []resourceconsist.IEmployee) ([]resourceconsist.IEmployee, []resourceconsist.IEmployee, error) {
return nil, toUpdates, nil
}

// DeleteEmployees returns (nil, toDelete, nil) since CCM of ACK will sync bs of slb
func (r *ReconcileAdapter) DeleteEmployees(employer client.Object, toDelete []resourceconsist.IEmployee) ([]resourceconsist.IEmployee, []resourceconsist.IEmployee, error) {
return nil, toDelete, nil
func (r *ReconcileAdapter) DeleteEmployees(ctx context.Context, employer client.Object, toDeletes []resourceconsist.IEmployee) ([]resourceconsist.IEmployee, []resourceconsist.IEmployee, error) {
return nil, toDeletes, nil
}
12 changes: 6 additions & 6 deletions pkg/controllers/resourceconsist/consister.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ func (r *Consist) syncEmployer(ctx context.Context, employer client.Object, expe
if err != nil {
return false, false, fmt.Errorf("diff employer failed, err: %s", err.Error())
}
_, failCreate, err := r.adapter.CreateEmployer(employer, toCudEmployer.ToCreate)
_, failCreate, err := r.adapter.CreateEmployer(ctx, employer, toCudEmployer.ToCreate)
if err != nil {
return false, false, fmt.Errorf("syncCreate failed, err: %s", err.Error())
}
_, failUpdate, err := r.adapter.UpdateEmployer(employer, toCudEmployer.ToUpdate)
_, failUpdate, err := r.adapter.UpdateEmployer(ctx, employer, toCudEmployer.ToUpdate)
if err != nil {
return false, false, fmt.Errorf("syncUpdate failed, err: %s", err.Error())
}
_, failDelete, err := r.adapter.DeleteEmployer(employer, toCudEmployer.ToDelete)
_, failDelete, err := r.adapter.DeleteEmployer(ctx, employer, toCudEmployer.ToDelete)
if err != nil {
return false, false, fmt.Errorf("syncDelete failed, err: %s", err.Error())
}
Expand Down Expand Up @@ -185,15 +185,15 @@ func (r *Consist) syncEmployees(ctx context.Context, employer client.Object, exp
return false, false, err
}

succCreate, failCreate, err := r.adapter.CreateEmployees(employer, toCudEmployees.ToCreate)
succCreate, failCreate, err := r.adapter.CreateEmployees(ctx, employer, toCudEmployees.ToCreate)
if err != nil {
return false, false, fmt.Errorf("syncCreate failed, err: %s", err.Error())
}
succUpdate, failUpdate, err := r.adapter.UpdateEmployees(employer, toCudEmployees.ToUpdate)
succUpdate, failUpdate, err := r.adapter.UpdateEmployees(ctx, employer, toCudEmployees.ToUpdate)
if err != nil {
return false, false, fmt.Errorf("syncUpdate failed, err: %s", err.Error())
}
succDelete, failDelete, err := r.adapter.DeleteEmployees(employer, toCudEmployees.ToDelete)
succDelete, failDelete, err := r.adapter.DeleteEmployees(ctx, employer, toCudEmployees.ToDelete)
if err != nil {
return false, false, fmt.Errorf("syncDelete failed, err: %s", err.Error())
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/controllers/resourceconsist/resourceconsist_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (r *Consist) Reconcile(ctx context.Context, request reconcile.Request) (rec
return reconcile.Result{}, err
}

expectEmployer, err := r.adapter.GetExpectEmployer(ctx, employer)
expectEmployer, err := r.adapter.GetExpectedEmployer(ctx, employer)
if err != nil {
r.Logger.Error(err, "get expect employer failed")
r.Recorder.Eventf(employer, corev1.EventTypeWarning, "GetExpectEmployerFailed",
Expand All @@ -184,7 +184,7 @@ func (r *Consist) Reconcile(ctx context.Context, request reconcile.Request) (rec
return reconcile.Result{}, err
}

expectEmployees, err := r.adapter.GetExpectEmployee(ctx, employer)
expectEmployees, err := r.adapter.GetExpectedEmployee(ctx, employer)
if err != nil {
r.Logger.Error(err, "get expect employees failed")
r.Recorder.Eventf(employer, corev1.EventTypeWarning, "GetExpectEmployeeFailed",
Expand Down
Loading

0 comments on commit 9f61008

Please sign in to comment.