gxthrj commented on a change in pull request #149:
URL: 
https://github.com/apache/apisix-ingress-controller/pull/149#discussion_r551752081



##########
File path: pkg/seven/state/service_worker.go
##########
@@ -64,114 +67,93 @@ func (w *serviceWorker) trigger(event Event, rwg 
*RouteWorkerGroup) error {
        // add to queue
        services := []*v1.Service{w.Service}
        sqo := &ServiceQueueObj{Services: services, RouteWorkerGroup: *rwg}
-       sqo.AddQueue()
-
-       //op := Update
-       //// padding
-       //currentService, _ := apisix.FindCurrentService(*w.Service.Name)
-       //paddingService(w.Service, currentService)
-       //// diff
-       //hasDiff, err := utils.HasDiff(w.Service, currentService)
-       //// sync
-       //if err != nil {
-       //      return err
-       //}
-       //if hasDiff {
-       //      if *w.Service.ID == strconv.Itoa(0) {
-       //              op = Create
-       //              // 1. sync apisix and get id
-       //              if serviceResponse, err := apisix.AddService(w.Service, 
conf.BaseUrl); err != nil {
-       //                      // todo log error
-       //                      glog.Info(err.Error())
-       //              }else {
-       //                      tmp := 
strings.Split(*serviceResponse.Service.Key, "/")
-       //                      *w.Service.ID = tmp[len(tmp) - 1]
-       //              }
-       //              // 2. sync memDB
-       //              db := &db.ServiceDB{Services: []*v1.Service{w.Service}}
-       //              db.Insert()
-       //              glog.Infof("create service %s, %s", *w.Name, 
*w.UpstreamId)
-       //      }else {
-       //              op = Update
-       //              // 1. sync memDB
-       //              db := db.ServiceDB{Services: []*v1.Service{w.Service}}
-       //              if err := db.UpdateService(); err != nil {
-       //                      // todo log error
-       //              }
-       //              // 2. sync apisix
-       //              apisix.UpdateService(w.Service, conf.BaseUrl)
-       //              glog.Infof("update service %s, %s", *w.Name, 
*w.UpstreamId)
-       //      }
-       //}
-       //// broadcast to route
-       //routeWorkers := (*rwg)[*w.Service.Name]
-       //for _, rw := range routeWorkers{
-       //      event := &Event{Kind: ServiceKind, Op: op, Obj: w.Service}
-       //      glog.Infof("send event %s, %s, %s", event.Kind, event.Op, 
*w.Service.Name)
-       //      rw.Event <- *event
-       //}
+       //sqo.AddQueue()
+
+       SolverService(sqo.Services, sqo.RouteWorkerGroup, w.Wg, w.ErrorChan)
        return nil
 }
 
-func SolverService(services []*v1.Service, rwg RouteWorkerGroup) error {
+func SolverService(services []*v1.Service, rwg RouteWorkerGroup, wg 
*sync.WaitGroup, errorChan chan CRDStatus) {
        for _, svc := range services {
-               op := Update
-               // padding
-               currentService, _ := apisix.FindCurrentService(*svc.Group, 
*svc.Name, *svc.FullName)
-               paddingService(svc, currentService)
-               // diff
-               hasDiff, err := utils.HasDiff(svc, currentService)
-               // sync
-               if err != nil {
-                       return err
+               go SolverSingleService(svc, rwg, wg, errorChan)
+       }
+}
+
+func SolverSingleService(svc *v1.Service, rwg RouteWorkerGroup, wg 
*sync.WaitGroup, errorChan chan CRDStatus) {
+       var errNotify error
+       defer func() {
+               if errNotify != nil {
+                       errorChan <- CRDStatus{Id: "", Status: "failure", Err: 
errNotify}
                }
-               if hasDiff {
-                       if *svc.ID == strconv.Itoa(0) {
-                               op = Create
-                               // 1. sync apisix and get id
-                               if serviceResponse, err := 
apisix.AddService(svc); err != nil {
-                                       // todo log error
-                                       glog.V(2).Info(err.Error())
-                               } else {
-                                       tmp := 
strings.Split(*serviceResponse.Service.Key, "/")
-                                       *svc.ID = tmp[len(tmp)-1]
-                               }
-                               // 2. sync memDB
-                               db := &db.ServiceDB{Services: 
[]*v1.Service{svc}}
-                               db.Insert()
-                               glog.V(2).Infof("create service %s, %s", 
*svc.Name, *svc.UpstreamId)
+               wg.Done()
+       }()
+
+       op := Update
+       // padding
+       currentService, _ := apisix.FindCurrentService(*svc.Group, *svc.Name, 
*svc.FullName)
+       paddingService(svc, currentService)
+       // diff
+       hasDiff, err := utils.HasDiff(svc, currentService)
+       // sync
+       if err != nil {
+               errNotify = err
+               return
+       }
+       if hasDiff {
+               if *svc.ID == strconv.Itoa(0) {

Review comment:
       In the previous implementation, 0 was used as a placeholder to determine 
whether the object existed before.
   
   We can refactor this piece separately in future.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to