From 9f6100868d2b4cb7282cf1bee2ede1995db3c9b2 Mon Sep 17 00:00:00 2001 From: WeichengWang Date: Fri, 15 Sep 2023 15:46:08 +0800 Subject: [PATCH] mock a backend provider for demo controller --- go.mod | 1 + go.sum | 1 + .../alibabacloudslb_controller.go | 22 +- pkg/controllers/resourceconsist/consister.go | 12 +- .../resourceconsist_controller.go | 4 +- .../resourceconsist_controller_suite_test.go | 477 ++++++++---------- .../resourceconsist_controller_test.go | 142 ++---- pkg/controllers/resourceconsist/types.go | 24 +- pkg/controllers/resourceconsist/utils.go | 2 +- 9 files changed, 300 insertions(+), 385 deletions(-) diff --git a/go.mod b/go.mod index 917b2214..65a6840f 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 897a20ab..159a31bd 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/pkg/controllers/alibabacloudslb/alibabacloudslb_controller.go b/pkg/controllers/alibabacloudslb/alibabacloudslb_controller.go index b03b93fb..15376969 100644 --- a/pkg/controllers/alibabacloudslb/alibabacloudslb_controller.go +++ b/pkg/controllers/alibabacloudslb/alibabacloudslb_controller.go @@ -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 } @@ -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") @@ -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 } diff --git a/pkg/controllers/resourceconsist/consister.go b/pkg/controllers/resourceconsist/consister.go index f2cab867..530ef090 100644 --- a/pkg/controllers/resourceconsist/consister.go +++ b/pkg/controllers/resourceconsist/consister.go @@ -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()) } @@ -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()) } diff --git a/pkg/controllers/resourceconsist/resourceconsist_controller.go b/pkg/controllers/resourceconsist/resourceconsist_controller.go index 28790202..be6cb0db 100644 --- a/pkg/controllers/resourceconsist/resourceconsist_controller.go +++ b/pkg/controllers/resourceconsist/resourceconsist_controller.go @@ -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", @@ -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", diff --git a/pkg/controllers/resourceconsist/resourceconsist_controller_suite_test.go b/pkg/controllers/resourceconsist/resourceconsist_controller_suite_test.go index be41f6fc..ccdc7887 100644 --- a/pkg/controllers/resourceconsist/resourceconsist_controller_suite_test.go +++ b/pkg/controllers/resourceconsist/resourceconsist_controller_suite_test.go @@ -18,28 +18,27 @@ package resourceconsist import ( "context" - "encoding/json" "fmt" "reflect" - "strconv" - "strings" + "sync" + "github.com/stretchr/testify/mock" corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" ) type DemoReconcile struct { client.Client + resourceProviderClient *DemoResourceProviderClient } var _ ReconcileAdapter = &DemoReconcile{} -func NewDemoReconcileAdapter(c client.Client) *DemoReconcile { +func NewDemoReconcileAdapter(c client.Client, rc *DemoResourceProviderClient) *DemoReconcile { return &DemoReconcile{ - Client: c, + Client: c, + resourceProviderClient: rc, } } @@ -71,7 +70,7 @@ func (r *DemoReconcile) NotFollowPodOpsLifeCycle() bool { return false } -func (r *DemoReconcile) GetExpectEmployer(ctx context.Context, employer client.Object) ([]IEmployer, error) { +func (r *DemoReconcile) GetExpectedEmployer(ctx context.Context, employer client.Object) ([]IEmployer, error) { if !employer.GetDeletionTimestamp().IsZero() { return nil, nil } @@ -88,170 +87,81 @@ func (r *DemoReconcile) GetExpectEmployer(ctx context.Context, employer client.O func (r *DemoReconcile) GetCurrentEmployer(ctx context.Context, employer client.Object) ([]IEmployer, error) { var current []IEmployer - if employer.GetAnnotations()["demo-current-employer"] == "" { - return current, nil - } - var currentDemoServiceStatus []DemoServiceStatus - err := json.Unmarshal([]byte(employer.GetAnnotations()["demo-current-employer"]), ¤tDemoServiceStatus) + + req := &DemoResourceVipOps{} + resp, err := r.resourceProviderClient.QueryVip(req) if err != nil { return current, err } - for _, employerStatus := range currentDemoServiceStatus { + if resp == nil { + return current, fmt.Errorf("demo resource vip query resp is nil") + } + + for _, employerStatus := range resp.VipStatuses { current = append(current, employerStatus) } return current, nil } -func (r *DemoReconcile) CreateEmployer(employer client.Object, toCreate []IEmployer) ([]IEmployer, []IEmployer, error) { - var currentDemoServiceStatus []DemoServiceStatus - if employer.GetAnnotations()["demo-current-employer"] != "" { - err := json.Unmarshal([]byte(employer.GetAnnotations()["demo-current-employer"]), ¤tDemoServiceStatus) - if err != nil { - return nil, toCreate, err - } - } - for _, create := range toCreate { +func (r *DemoReconcile) CreateEmployer(ctx context.Context, employer client.Object, toCreates []IEmployer) ([]IEmployer, []IEmployer, error) { + toCreateDemoServiceStatus := make([]DemoServiceStatus, len(toCreates)) + for idx, create := range toCreates { createDemoServiceStatus, ok := create.(DemoServiceStatus) if !ok { - return nil, toCreate, fmt.Errorf("toCreate employer is not DemoServiceStatus") + return nil, toCreates, fmt.Errorf("toCreates employer is not DemoServiceStatus") } - currentDemoServiceStatus = append(currentDemoServiceStatus, createDemoServiceStatus) + toCreateDemoServiceStatus[idx] = createDemoServiceStatus } - patch := client.MergeFrom(employer.DeepCopyObject().(client.Object)) - annos := employer.GetAnnotations() - if annos == nil { - annos = make(map[string]string) - } - annos["demo-current-employer"] = "" - if currentDemoServiceStatus != nil { - b, err := json.Marshal(currentDemoServiceStatus) - if err != nil { - return nil, toCreate, err - } - annos["demo-current-employer"] = string(b) - } - employer.SetAnnotations(annos) - err := r.Patch(context.Background(), employer, patch) + _, err := r.resourceProviderClient.CreateVip(&DemoResourceVipOps{ + VipStatuses: toCreateDemoServiceStatus, + }) if err != nil { - return nil, toCreate, err + return nil, toCreates, err } - - return toCreate, nil, nil + return toCreates, nil, nil } -func (r *DemoReconcile) UpdateEmployer(employer client.Object, toUpdate []IEmployer) ([]IEmployer, []IEmployer, error) { - var currentDemoServiceStatus []DemoServiceStatus - if employer.GetAnnotations()["demo-current-employer"] != "" { - err := json.Unmarshal([]byte(employer.GetAnnotations()["demo-current-employer"]), ¤tDemoServiceStatus) - if err != nil { - return nil, toUpdate, err - } - } - - toUpdateEmployerMap := make(map[string]IEmployer) - updated := make(map[string]bool) - for _, update := range toUpdate { - toUpdateEmployerMap[update.GetEmployerId()] = update - } - - for idx, cur := range currentDemoServiceStatus { - if toUpdateEmployerStatus, ok := toUpdateEmployerMap[cur.EmployerId]; ok { - currentDemoServiceStatus[idx] = toUpdateEmployerStatus.(DemoServiceStatus) - updated[cur.EmployerId] = true +func (r *DemoReconcile) UpdateEmployer(ctx context.Context, employer client.Object, toUpdates []IEmployer) ([]IEmployer, []IEmployer, error) { + toUpdateDemoServiceStatus := make([]DemoServiceStatus, len(toUpdates)) + for idx, update := range toUpdates { + updateDemoServiceStatus, ok := update.(DemoServiceStatus) + if !ok { + return nil, toUpdates, fmt.Errorf("toUpdates employer is not DemoServiceStatus") } + toUpdateDemoServiceStatus[idx] = updateDemoServiceStatus } - patch := client.MergeFrom(employer.DeepCopyObject().(client.Object)) - annos := employer.GetAnnotations() - annos["demo-current-employer"] = "" - if currentDemoServiceStatus != nil { - b, err := json.Marshal(currentDemoServiceStatus) - if err != nil { - return nil, toUpdate, err - } - annos["demo-current-employer"] = string(b) - } - employer.SetAnnotations(annos) - err := r.Patch(context.Background(), employer, patch) + _, err := r.resourceProviderClient.UpdateVip(&DemoResourceVipOps{ + VipStatuses: toUpdateDemoServiceStatus, + }) if err != nil { - return nil, toUpdate, err - } - - var succ []IEmployer - var fail []IEmployer - for employerId, updatedSucc := range updated { - if updatedSucc { - succ = append(succ, toUpdateEmployerMap[employerId]) - } else { - fail = append(fail, toUpdateEmployerMap[employerId]) - } + return nil, toUpdates, err } - - return succ, fail, nil + return toUpdates, nil, nil } -func (r *DemoReconcile) DeleteEmployer(employer client.Object, toDelete []IEmployer) ([]IEmployer, []IEmployer, error) { - var currentDemoServiceStatus []DemoServiceStatus - if employer.GetAnnotations()["demo-current-employer"] == "" { - return toDelete, nil, nil - } - - err := json.Unmarshal([]byte(employer.GetAnnotations()["demo-current-employer"]), ¤tDemoServiceStatus) - if err != nil { - return nil, toDelete, err - } - - toDeleteEmployerMap := make(map[string]IEmployer) - deleted := make(map[string]bool) - for _, del := range toDelete { - toDeleteEmployerMap[del.GetEmployerId()] = del - } - - var afterDeletedDemoServiceStatus []DemoServiceStatus - for _, cur := range currentDemoServiceStatus { - if _, ok := toDeleteEmployerMap[cur.EmployerId]; ok { - deleted[cur.EmployerId] = true - continue - } - afterDeletedDemoServiceStatus = append(afterDeletedDemoServiceStatus, cur) - } - - patch := client.MergeFrom(employer.DeepCopyObject().(client.Object)) - annos := employer.GetAnnotations() - if annos == nil { - return toDelete, nil, nil - } - annos["demo-current-employer"] = "" - if afterDeletedDemoServiceStatus != nil { - b, err := json.Marshal(afterDeletedDemoServiceStatus) - if err != nil { - return nil, toDelete, err +func (r *DemoReconcile) DeleteEmployer(ctx context.Context, employer client.Object, toDeletes []IEmployer) ([]IEmployer, []IEmployer, error) { + toDeleteDemoServiceStatus := make([]DemoServiceStatus, len(toDeletes)) + for idx, update := range toDeletes { + deleteDemoServiceStatus, ok := update.(DemoServiceStatus) + if !ok { + return nil, toDeletes, fmt.Errorf("toDeletes employer is not DemoServiceStatus") } - annos["demo-current-employer"] = string(b) + toDeleteDemoServiceStatus[idx] = deleteDemoServiceStatus } - employer.SetAnnotations(annos) - err = r.Patch(context.Background(), employer, patch) + _, err := r.resourceProviderClient.DeleteVip(&DemoResourceVipOps{ + VipStatuses: toDeleteDemoServiceStatus, + }) if err != nil { - return nil, toDelete, err - } - - var succ []IEmployer - var fail []IEmployer - for employerId, delSucc := range deleted { - if delSucc { - succ = append(succ, toDeleteEmployerMap[employerId]) - } else { - fail = append(fail, toDeleteEmployerMap[employerId]) - } + return nil, toDeletes, err } - - return succ, fail, nil + return toDeletes, nil, nil } // GetExpectEmployeeStatus return expect employee status -func (r *DemoReconcile) GetExpectEmployee(ctx context.Context, employer client.Object) ([]IEmployee, error) { +func (r *DemoReconcile) GetExpectedEmployee(ctx context.Context, employer client.Object) ([]IEmployee, error) { if !employer.GetDeletionTimestamp().IsZero() { return []IEmployee{}, nil } @@ -300,152 +210,83 @@ func (r *DemoReconcile) GetExpectEmployee(ctx context.Context, employer client.O } func (r *DemoReconcile) GetCurrentEmployee(ctx context.Context, employer client.Object) ([]IEmployee, error) { - svc, ok := employer.(*corev1.Service) - if !ok { - return nil, fmt.Errorf("expect employer kind is Service") + var current []IEmployee + req := &DemoResourceRsOps{} + resp, err := r.resourceProviderClient.QueryRealServer(req) + if err != nil { + return current, err + } + if resp == nil { + return current, fmt.Errorf("demo resource rs query resp is nil") } - if svc.GetAnnotations()["demo-added-pods"] == "" { - return nil, nil + for _, rsStatus := range resp.RsStatuses { + current = append(current, rsStatus) } + return current, nil +} - addedPodNames := strings.Split(svc.GetAnnotations()["demo-added-pods"], ",") - current := make([]IEmployee, len(addedPodNames)) - currentIdx := 0 +func (r *DemoReconcile) CreateEmployees(ctx context.Context, employer client.Object, toCreates []IEmployee) ([]IEmployee, []IEmployee, error) { + toCreateDemoPodStatuses := make([]DemoPodStatus, len(toCreates)) - for _, podName := range addedPodNames { - pod := &corev1.Pod{} - err := r.Get(ctx, types.NamespacedName{ - Namespace: employer.GetNamespace(), - Name: podName, - }, pod) - if err != nil { - if errors.IsNotFound(err) { - continue - } - return nil, err - } - status := DemoPodStatus{ - EmployeeId: podName, - EmployeeName: podName, - } - employeeStatus, err := GetCommonPodEmployeeStatus(pod) - if err != nil { - return nil, err - } - extraStatus := PodExtraStatus{} - if pod.GetLabels()["demo-traffic-on"] == "true" { - extraStatus.TrafficOn = true - } - if pod.GetLabels()["demo-traffic-weight"] != "" { - extraStatus.TrafficWeight, _ = strconv.Atoi(pod.GetLabels()["demo-traffic-weight"]) + for idx, toCreate := range toCreates { + podStatus, ok := toCreate.(DemoPodStatus) + if !ok { + return nil, toCreates, fmt.Errorf("toCreate is not DemoPodStatus") } - employeeStatus.ExtraStatus = extraStatus - status.EmployeeStatuses = employeeStatus - current[currentIdx] = status - currentIdx++ + toCreateDemoPodStatuses[idx] = podStatus } - return current[:currentIdx], nil -} -func (r *DemoReconcile) CreateEmployees(employer client.Object, toCreate []IEmployee) ([]IEmployee, []IEmployee, error) { - if employer == nil { - return nil, nil, fmt.Errorf("employer is nil") - } - if len(toCreate) == 0 { - return toCreate, nil, nil - } - toAddNames := make([]string, len(toCreate)) - toAddIdx := 0 - for _, employee := range toCreate { - toAddNames[toAddIdx] = employee.GetEmployeeName() - toAddIdx++ - } - toAddNames = toAddNames[:toAddIdx] - anno := employer.GetAnnotations() - if anno["demo-added-pods"] == "" { - anno["demo-added-pods"] = strings.Join(toAddNames, ",") - } else { - anno["demo-added-pods"] = anno["demo-added-pods"] + "," + strings.Join(toAddNames, ",") - } - employer.SetAnnotations(anno) - err := r.Client.Update(context.Background(), employer) + _, err := r.resourceProviderClient.CreateRealServer(&DemoResourceRsOps{ + RsStatuses: toCreateDemoPodStatuses, + }) if err != nil { - return nil, nil, err + return nil, toCreates, err } - return toCreate, nil, nil + + return toCreates, nil, nil } -func (r *DemoReconcile) UpdateEmployees(employer client.Object, toUpdate []IEmployee) ([]IEmployee, []IEmployee, error) { - if employer == nil { - return nil, nil, fmt.Errorf("employer is nil") - } - if len(toUpdate) == 0 { - return toUpdate, nil, nil - } - succUpdate := make([]IEmployee, len(toUpdate)) - failUpdate := make([]IEmployee, len(toUpdate)) - succUpdateIdx, failUpdateIdx := 0, 0 - for _, employee := range toUpdate { - pod := &corev1.Pod{} - err := r.Get(context.Background(), types.NamespacedName{ - Namespace: employer.GetNamespace(), - Name: employee.GetEmployeeName(), - }, pod) - podEmployeeStatus := employee.GetEmployeeStatuses().(PodEmployeeStatuses) - if err != nil { - return succUpdate, failUpdate, err - } - extraStatus := podEmployeeStatus.ExtraStatus.(PodExtraStatus) - if extraStatus.TrafficOn { - pod.GetLabels()["demo-traffic-on"] = "true" - } else { - pod.GetLabels()["demo-traffic-on"] = "false" - } - pod.GetLabels()["demo-traffic-weight"] = strconv.Itoa(extraStatus.TrafficWeight) - err = r.Client.Update(context.Background(), pod) - if err != nil { - failUpdate[failUpdateIdx] = employee - failUpdateIdx++ - continue +func (r *DemoReconcile) UpdateEmployees(ctx context.Context, employer client.Object, toUpdates []IEmployee) ([]IEmployee, []IEmployee, error) { + toUpdateDemoPodStatuses := make([]DemoPodStatus, len(toUpdates)) + + for idx, toUpdate := range toUpdates { + podStatus, ok := toUpdate.(DemoPodStatus) + if !ok { + return nil, toUpdates, fmt.Errorf("toUpdate is not DemoPodStatus") } - succUpdate[succUpdateIdx] = employee - succUpdateIdx++ + toUpdateDemoPodStatuses[idx] = podStatus } - return succUpdate[:succUpdateIdx], failUpdate[:failUpdateIdx], nil -} -func (r *DemoReconcile) DeleteEmployees(employer client.Object, toDelete []IEmployee) ([]IEmployee, []IEmployee, error) { - if employer == nil { - return nil, nil, fmt.Errorf("employer is nil") - } - if len(toDelete) == 0 { - return toDelete, nil, nil + _, err := r.resourceProviderClient.UpdateRealServer(&DemoResourceRsOps{ + RsStatuses: toUpdateDemoPodStatuses, + }) + if err != nil { + return nil, toUpdates, err } - toDeleteMap := make(map[string]bool) - for _, employee := range toDelete { - toDeleteMap[employee.GetEmployeeName()] = true - } + return toUpdates, nil, nil +} - addedPodNames := strings.Split(employer.GetAnnotations()["demo-added-pods"], ",") +func (r *DemoReconcile) DeleteEmployees(ctx context.Context, employer client.Object, toDeletes []IEmployee) ([]IEmployee, []IEmployee, error) { + toDeleteDemoPodStatuses := make([]DemoPodStatus, len(toDeletes)) - afterDeleteIdx := 0 - for _, added := range addedPodNames { - if !toDeleteMap[added] { - addedPodNames[afterDeleteIdx] = added - afterDeleteIdx++ + for idx, toDelete := range toDeletes { + podStatus, ok := toDelete.(DemoPodStatus) + if !ok { + return nil, toDeletes, fmt.Errorf("toDelete is not DemoPodStatus") } + toDeleteDemoPodStatuses[idx] = podStatus } - addedPodNames = addedPodNames[:afterDeleteIdx] - anno := employer.GetAnnotations() - anno["demo-added-pods"] = strings.Join(addedPodNames, ",") - employer.SetAnnotations(anno) - err := r.Client.Update(context.Background(), employer) + + _, err := r.resourceProviderClient.DeleteRealServer(&DemoResourceRsOps{ + RsStatuses: toDeleteDemoPodStatuses, + }) if err != nil { - return nil, nil, err + return nil, toDeletes, err } - return toDelete, nil, nil + + return toDeletes, nil, nil } var _ IEmployer = DemoServiceStatus{} @@ -520,3 +361,113 @@ type PodExtraStatus struct { TrafficOn bool TrafficWeight int } + +var demoResourceVipStatusInProvider sync.Map +var demoResourceRsStatusInProvider sync.Map + +type DemoResourceProviderClient struct { + mock.Mock +} + +type DemoResourceVipOps struct { + VipStatuses []DemoServiceStatus `json:"vipStatuses,omitempty"` + MockData bool `json:"mockData,omitempty"` +} + +type DemoResourceRsOps struct { + RsStatuses []DemoPodStatus `json:"rsStatuses,omitempty"` + MockData bool `json:"mockData,omitempty"` +} + +func (d *DemoResourceProviderClient) CreateVip(req *DemoResourceVipOps) (*DemoResourceVipOps, error) { + args := d.Called(req) + if !args.Get(0).(*DemoResourceVipOps).MockData { + for _, vipStatus := range req.VipStatuses { + demoResourceVipStatusInProvider.Store(vipStatus.EmployerId, vipStatus.EmployerStatuses) + } + } + return args.Get(0).(*DemoResourceVipOps), args.Error(1) +} + +func (d *DemoResourceProviderClient) UpdateVip(req *DemoResourceVipOps) (*DemoResourceVipOps, error) { + args := d.Called(req) + if !args.Get(0).(*DemoResourceVipOps).MockData { + for _, vipStatus := range req.VipStatuses { + demoResourceVipStatusInProvider.Store(vipStatus.EmployerId, vipStatus.EmployerStatuses) + } + } + return args.Get(0).(*DemoResourceVipOps), args.Error(1) +} + +func (d *DemoResourceProviderClient) DeleteVip(req *DemoResourceVipOps) (*DemoResourceVipOps, error) { + args := d.Called(req) + if !args.Get(0).(*DemoResourceVipOps).MockData { + for _, vipStatus := range req.VipStatuses { + demoResourceVipStatusInProvider.Delete(vipStatus.EmployerId) + } + } + return args.Get(0).(*DemoResourceVipOps), args.Error(1) +} + +func (d *DemoResourceProviderClient) QueryVip(req *DemoResourceVipOps) (*DemoResourceVipOps, error) { + args := d.Called(req) + if !args.Get(0).(*DemoResourceVipOps).MockData { + vipStatuses := make([]DemoServiceStatus, 0) + demoResourceVipStatusInProvider.Range(func(key, value any) bool { + vipStatuses = append(vipStatuses, DemoServiceStatus{ + EmployerId: key.(string), + EmployerStatuses: value.(DemoServiceDetails), + }) + return true + }) + return &DemoResourceVipOps{ + VipStatuses: vipStatuses, + }, args.Error(1) + } + return args.Get(0).(*DemoResourceVipOps), args.Error(1) +} + +func (d *DemoResourceProviderClient) CreateRealServer(req *DemoResourceRsOps) (*DemoResourceRsOps, error) { + args := d.Called(req) + if !args.Get(0).(*DemoResourceRsOps).MockData { + for _, employeeStatus := range req.RsStatuses { + demoResourceRsStatusInProvider.Store(employeeStatus.GetEmployeeId(), employeeStatus) + } + } + return args.Get(0).(*DemoResourceRsOps), args.Error(1) +} + +func (d *DemoResourceProviderClient) UpdateRealServer(req *DemoResourceRsOps) (*DemoResourceRsOps, error) { + args := d.Called(req) + if !args.Get(0).(*DemoResourceRsOps).MockData { + for _, employeeStatus := range req.RsStatuses { + demoResourceRsStatusInProvider.Store(employeeStatus.GetEmployeeId(), employeeStatus) + } + } + return args.Get(0).(*DemoResourceRsOps), args.Error(1) +} + +func (d *DemoResourceProviderClient) DeleteRealServer(req *DemoResourceRsOps) (*DemoResourceRsOps, error) { + args := d.Called(req) + if !args.Get(0).(*DemoResourceRsOps).MockData { + for _, employeeStatus := range req.RsStatuses { + demoResourceRsStatusInProvider.Delete(employeeStatus.GetEmployeeId()) + } + } + return args.Get(0).(*DemoResourceRsOps), args.Error(1) +} + +func (d *DemoResourceProviderClient) QueryRealServer(req *DemoResourceRsOps) (*DemoResourceRsOps, error) { + args := d.Called(req) + if !args.Get(0).(*DemoResourceRsOps).MockData { + rsStatuses := make([]DemoPodStatus, 0) + demoResourceRsStatusInProvider.Range(func(key, value any) bool { + rsStatuses = append(rsStatuses, value.(DemoPodStatus)) + return true + }) + return &DemoResourceRsOps{ + RsStatuses: rsStatuses, + }, args.Error(1) + } + return args.Get(0).(*DemoResourceRsOps), args.Error(1) +} diff --git a/pkg/controllers/resourceconsist/resourceconsist_controller_test.go b/pkg/controllers/resourceconsist/resourceconsist_controller_test.go index 8fccc2f7..48de2fa5 100644 --- a/pkg/controllers/resourceconsist/resourceconsist_controller_test.go +++ b/pkg/controllers/resourceconsist/resourceconsist_controller_test.go @@ -18,28 +18,28 @@ package resourceconsist import ( "context" + "fmt" "os" "path/filepath" - "strings" "testing" "time" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "github.com/stretchr/testify/mock" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" - "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/envtest" logf "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/log/zap" "sigs.k8s.io/controller-runtime/pkg/manager" - "kusionstack.io/kafed/apis" - "kusionstack.io/kafed/apis/apps/v1alpha1" - "kusionstack.io/kafed/pkg/utils/inject" + "kusionstack.io/operating/apis" + "kusionstack.io/operating/apis/apps/v1alpha1" + "kusionstack.io/operating/pkg/utils/inject" ) var ( @@ -48,6 +48,8 @@ var ( ctx context.Context cancel context.CancelFunc + + rc = &DemoResourceProviderClient{} ) var _ = Describe("resource-consist-controller", func() { @@ -94,38 +96,38 @@ var _ = Describe("resource-consist-controller", func() { }) Context("employer synced", func() { + rc.On("QueryVip", mock.Anything).Return(&DemoResourceVipOps{}, nil) + rc.On("CreateVip", mock.Anything).Return(&DemoResourceVipOps{}, nil) + rc.On("UpdateVip", mock.Anything).Return(&DemoResourceVipOps{}, nil) + rc.On("DeleteVip", mock.Anything).Return(&DemoResourceVipOps{}, nil) It("employer created", func() { Eventually(func() bool { - service1 := corev1.Service{} - Expect(mgr.GetClient().Get(context.TODO(), types.NamespacedName{ - Name: service.Name, - Namespace: service.Namespace, - }, &service1)).Should(BeNil()) - return service1.GetAnnotations()["demo-current-employer"] == "[{\"EmployerId\":\"demo-expect-employer-id\",\"EmployerStatuses\":{\"RemoteVIP\":\"demo-remote-VIP\",\"RemoteVIPQPS\":100}}]" + details, exist := demoResourceVipStatusInProvider.Load("demo-expect-employer-id") + return exist && details.(DemoServiceDetails).RemoteVIP == "demo-remote-VIP" && details.(DemoServiceDetails).RemoteVIPQPS == 100 }, 3*time.Second, 100*time.Millisecond).Should(BeTrue()) }) It("employer updated", func() { + demoResourceVipStatusInProvider.Store("demo-expect-employer-id", DemoServiceDetails{ + RemoteVIP: "demo-remote-VIP", + RemoteVIPQPS: 200, + }) + + // trigger reconcile service1 := corev1.Service{} Expect(mgr.GetClient().Get(context.TODO(), types.NamespacedName{ Name: service.Name, Namespace: service.Namespace, }, &service1)).Should(BeNil()) - patch := client.MergeFrom(service1.DeepCopy()) - annos := service1.GetAnnotations() - if annos == nil { - annos = make(map[string]string) + if service1.Labels == nil { + service1.Labels = make(map[string]string) } - annos["demo-current-employer"] = "[{\"EmployerId\":\"demo-expect-employer-id\",\"EmployerStatuses\":{\"RemoteVIP\":\"demo-remote-VIP\",\"RemoteVIPQPS\":200}}]" - service1.SetAnnotations(annos) - Expect(mgr.GetClient().Patch(context.Background(), &service1, patch)).Should(BeNil()) + service1.Labels["demo-controller-trigger-reconcile"] = fmt.Sprintf("%d", time.Now().Unix()) + Expect(mgr.GetClient().Update(context.TODO(), &service1)).Should(BeNil()) + Eventually(func() bool { - service1 := corev1.Service{} - Expect(mgr.GetClient().Get(context.TODO(), types.NamespacedName{ - Name: service.Name, - Namespace: service.Namespace, - }, &service1)).Should(BeNil()) - return service1.GetAnnotations()["demo-current-employer"] == "[{\"EmployerId\":\"demo-expect-employer-id\",\"EmployerStatuses\":{\"RemoteVIP\":\"demo-remote-VIP\",\"RemoteVIPQPS\":100}}]" + details, exist := demoResourceVipStatusInProvider.Load("demo-expect-employer-id") + return exist && details.(DemoServiceDetails).RemoteVIP == "demo-remote-VIP" && details.(DemoServiceDetails).RemoteVIPQPS == 100 }, 3*time.Second, 100*time.Millisecond).Should(BeTrue()) }) @@ -152,12 +154,8 @@ var _ = Describe("resource-consist-controller", func() { return !service1.GetDeletionTimestamp().IsZero() }, 3*time.Second, 100*time.Millisecond).Should(BeTrue()) Eventually(func() bool { - service1 := corev1.Service{} - Expect(mgr.GetClient().Get(context.TODO(), types.NamespacedName{ - Name: service.Name, - Namespace: service.Namespace, - }, &service1)).Should(BeNil()) - return service1.GetAnnotations()["demo-current-employer"] == "" + _, exist := demoResourceVipStatusInProvider.Load("demo-expect-employer-id") + return !exist }, 3*time.Second, 100*time.Millisecond).Should(BeTrue()) Eventually(func() bool { @@ -189,6 +187,11 @@ var _ = Describe("resource-consist-controller", func() { }) Context("employee synced", func() { + rc.On("QueryRealServer", mock.Anything).Return(&DemoResourceRsOps{}, nil) + rc.On("CreateRealServer", mock.Anything).Return(&DemoResourceRsOps{}, nil) + rc.On("UpdateRealServer", mock.Anything).Return(&DemoResourceRsOps{}, nil) + rc.On("DeleteRealServer", mock.Anything).Return(&DemoResourceRsOps{}, nil) + svc := corev1.Service{ ObjectMeta: v1.ObjectMeta{ Name: "resource-consist-ut-svc-1", @@ -238,15 +241,8 @@ var _ = Describe("resource-consist-controller", func() { It("employee synced, employer created", func() { Expect(mgr.GetClient().Create(context.Background(), &svc)).Should(BeNil()) Eventually(func() bool { - service1 := corev1.Service{} - err := mgr.GetClient().Get(context.TODO(), types.NamespacedName{ - Name: svc.Name, - Namespace: svc.Namespace, - }, &service1) - if err != nil { - return false - } - return service1.GetAnnotations()["demo-current-employer"] == "[{\"EmployerId\":\"demo-expect-employer-id\",\"EmployerStatuses\":{\"RemoteVIP\":\"demo-remote-VIP\",\"RemoteVIPQPS\":100}}]" + details, exist := demoResourceVipStatusInProvider.Load("demo-expect-employer-id") + return exist && details.(DemoServiceDetails).RemoteVIP == "demo-remote-VIP" && details.(DemoServiceDetails).RemoteVIPQPS == 100 }, 3*time.Second, 100*time.Millisecond).Should(BeTrue()) }) @@ -278,12 +274,10 @@ var _ = Describe("resource-consist-controller", func() { }, 3*time.Second, 100*time.Millisecond).Should(BeTrue()) Eventually(func() bool { - service1 := corev1.Service{} - Expect(mgr.GetClient().Get(context.TODO(), types.NamespacedName{ - Name: svc.Name, - Namespace: svc.Namespace, - }, &service1)).Should(BeNil()) - return service1.GetAnnotations()["demo-added-pods"] == pod.Name + details, exist := demoResourceRsStatusInProvider.Load(pod.Name) + return exist && details.(DemoPodStatus).GetEmployeeName() == pod.Name && + details.(DemoPodStatus).GetEmployeeStatuses().(PodEmployeeStatuses).ExtraStatus.(PodExtraStatus).TrafficWeight == 100 && + details.(DemoPodStatus).GetEmployeeStatuses().(PodEmployeeStatuses).ExtraStatus.(PodExtraStatus).TrafficOn == true }, 3*time.Second, 100*time.Millisecond).Should(BeTrue()) Eventually(func() bool { @@ -299,8 +293,7 @@ var _ = Describe("resource-consist-controller", func() { break } } - return containsLifecycleFlz && pod1.GetLabels()["demo-traffic-on"] == "true" && - pod1.GetLabels()["demo-traffic-weight"] == "100" + return containsLifecycleFlz }, 3*time.Second, 100*time.Millisecond).Should(BeTrue()) Eventually(func() bool { @@ -340,32 +333,10 @@ var _ = Describe("resource-consist-controller", func() { }, 3*time.Second, 100*time.Millisecond).Should(BeTrue()) Eventually(func() bool { - pod1 := corev1.Pod{} - err := mgr.GetClient().Get(context.TODO(), types.NamespacedName{ - Name: pod.Name, - Namespace: pod.Namespace, - }, &pod1) - if err != nil { - return false - } - containsLifecycleFlz := false - for _, flz := range pod1.GetFinalizers() { - if flz == GenerateLifecycleFinalizer(svc.Name) { - containsLifecycleFlz = true - break - } - } - return !containsLifecycleFlz && pod1.GetLabels()["demo-traffic-on"] == "false" && - pod1.GetLabels()["demo-traffic-weight"] == "0" - }, 3*time.Second, 100*time.Millisecond).Should(BeTrue()) - - Eventually(func() bool { - service1 := corev1.Service{} - Expect(mgr.GetClient().Get(context.TODO(), types.NamespacedName{ - Name: svc.Name, - Namespace: svc.Namespace, - }, &service1)).Should(BeNil()) - return service1.GetAnnotations()["demo-added-pods"] == pod.Name + details, exist := demoResourceRsStatusInProvider.Load(pod.Name) + return exist && details.(DemoPodStatus).GetEmployeeName() == pod.Name && + details.(DemoPodStatus).GetEmployeeStatuses().(PodEmployeeStatuses).ExtraStatus.(PodExtraStatus).TrafficWeight == 0 && + details.(DemoPodStatus).GetEmployeeStatuses().(PodEmployeeStatuses).ExtraStatus.(PodExtraStatus).TrafficOn == false }, 3*time.Second, 100*time.Millisecond).Should(BeTrue()) Eventually(func() bool { @@ -391,15 +362,10 @@ var _ = Describe("resource-consist-controller", func() { }, 3*time.Second, 100*time.Millisecond).Should(BeTrue()) Eventually(func() bool { - pod1 := corev1.Pod{} - err := mgr.GetClient().Get(context.TODO(), types.NamespacedName{ - Name: pod.Name, - Namespace: pod.Namespace, - }, &pod1) - if err != nil { - return false - } - return pod1.GetLabels()["demo-traffic-on"] == "true" && pod1.GetLabels()["demo-traffic-weight"] == "100" + details, exist := demoResourceRsStatusInProvider.Load(pod.Name) + return exist && details.(DemoPodStatus).GetEmployeeName() == pod.Name && + details.(DemoPodStatus).GetEmployeeStatuses().(PodEmployeeStatuses).ExtraStatus.(PodExtraStatus).TrafficWeight == 100 && + details.(DemoPodStatus).GetEmployeeStatuses().(PodEmployeeStatuses).ExtraStatus.(PodExtraStatus).TrafficOn == true }, 3*time.Second, 100*time.Millisecond).Should(BeTrue()) }) @@ -422,15 +388,11 @@ var _ = Describe("resource-consist-controller", func() { }, 3*time.Second, 100*time.Millisecond).Should(BeTrue()) Eventually(func() bool { - service1 := corev1.Service{} - Expect(mgr.GetClient().Get(context.TODO(), types.NamespacedName{ - Name: svc.Name, - Namespace: svc.Namespace, - }, &service1)).Should(BeNil()) - return !strings.Contains(service1.GetAnnotations()["demo-added-pods"], pod.Name) && - !strings.Contains(service1.GetAnnotations()[expectedFinalizerAddedAnnoKey], pod.Name) + _, exist := demoResourceRsStatusInProvider.Load(pod.Name) + return !exist }, 3*time.Second, 100*time.Millisecond).Should(BeTrue()) }) + }) }) @@ -460,7 +422,7 @@ var _ = BeforeSuite(func() { err = apis.AddToScheme(scheme) Expect(err).NotTo(HaveOccurred()) - err = AddToMgr(mgr, NewDemoReconcileAdapter(mgr.GetClient())) + err = AddToMgr(mgr, NewDemoReconcileAdapter(mgr.GetClient(), rc)) Expect(err).NotTo(HaveOccurred()) go func() { diff --git a/pkg/controllers/resourceconsist/types.go b/pkg/controllers/resourceconsist/types.go index d3ef0542..e5923dc3 100644 --- a/pkg/controllers/resourceconsist/types.go +++ b/pkg/controllers/resourceconsist/types.go @@ -50,23 +50,23 @@ type ReconcileAdapter interface { GetSelectedEmployeeNames(ctx context.Context, employer client.Object) ([]string, error) - // GetExpectEmployer and GetCurrentEmployer return expect/current status of employer from related backend provider - GetExpectEmployer(ctx context.Context, employer client.Object) ([]IEmployer, error) + // GetExpectedEmployer and GetCurrentEmployer return expect/current status of employer from related backend provider + GetExpectedEmployer(ctx context.Context, employer client.Object) ([]IEmployer, error) GetCurrentEmployer(ctx context.Context, employer client.Object) ([]IEmployer, error) - // todo, ctx as an input - CreateEmployer(employer client.Object, toCreate []IEmployer) ([]IEmployer, []IEmployer, error) - UpdateEmployer(employer client.Object, toUpdate []IEmployer) ([]IEmployer, []IEmployer, error) - DeleteEmployer(employer client.Object, toDelete []IEmployer) ([]IEmployer, []IEmployer, error) + // CreateEmployer/UpdateEmployer/DeleteEmployer handles creation/update/deletion of resources related to employer on related backend provider + CreateEmployer(ctx context.Context, employer client.Object, toCreates []IEmployer) ([]IEmployer, []IEmployer, error) + UpdateEmployer(ctx context.Context, employer client.Object, toUpdates []IEmployer) ([]IEmployer, []IEmployer, error) + DeleteEmployer(ctx context.Context, employer client.Object, toDeletes []IEmployer) ([]IEmployer, []IEmployer, error) - // GetExpectEmployee and GetCurrentEmployee return expect/current status of employees from related backend provider - GetExpectEmployee(ctx context.Context, employer client.Object) ([]IEmployee, error) + // GetExpectedEmployee and GetCurrentEmployee return expect/current status of employees from related backend provider + GetExpectedEmployee(ctx context.Context, employer client.Object) ([]IEmployee, error) GetCurrentEmployee(ctx context.Context, employer client.Object) ([]IEmployee, error) - // todo, ctx as an input - CreateEmployees(employer client.Object, toCreate []IEmployee) ([]IEmployee, []IEmployee, error) - UpdateEmployees(employer client.Object, toUpdate []IEmployee) ([]IEmployee, []IEmployee, error) - DeleteEmployees(employer client.Object, toDelete []IEmployee) ([]IEmployee, []IEmployee, error) + // CreateEmployees/UpdateEmployees/DeleteEmployees handles creation/update/deletion of resources related to employee on related backend provider + CreateEmployees(ctx context.Context, employer client.Object, toCreates []IEmployee) ([]IEmployee, []IEmployee, error) + UpdateEmployees(ctx context.Context, employer client.Object, toUpdates []IEmployee) ([]IEmployee, []IEmployee, error) + DeleteEmployees(ctx context.Context, employer client.Object, toDeletes []IEmployee) ([]IEmployee, []IEmployee, error) } type IEmployer interface { diff --git a/pkg/controllers/resourceconsist/utils.go b/pkg/controllers/resourceconsist/utils.go index 6d1c57df..132df5fc 100644 --- a/pkg/controllers/resourceconsist/utils.go +++ b/pkg/controllers/resourceconsist/utils.go @@ -80,7 +80,7 @@ func getPodIpv6Address(pod *corev1.Pod) string { return "" } -// GetCommonPodEmployeeStatus called by ReconcileAdapter's GetExpectEmployee/GetCurrentEmployee +// GetCommonPodEmployeeStatus called by ReconcileAdapter's GetExpectedEmployee/GetCurrentEmployee func GetCommonPodEmployeeStatus(pod *corev1.Pod) (PodEmployeeStatuses, error) { if pod == nil { return PodEmployeeStatuses{}, errors.New("SetCommonPodEmployeeStatus failed, pod is nil")