@@ -4,13 +4,13 @@ import (
44 "fmt"
55 "time"
66
7+ "github.com/alitto/pond"
78 "github.com/argoproj/gitops-engine/pkg/cache"
89 "github.com/argoproj/gitops-engine/pkg/engine"
910 "github.com/pluralsh/deployment-operator/pkg/client"
1011 "github.com/pluralsh/deployment-operator/pkg/manifests"
1112 deploysync "github.com/pluralsh/deployment-operator/pkg/sync"
1213 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
13- "k8s.io/apimachinery/pkg/util/wait"
1414 "k8s.io/client-go/discovery"
1515 "k8s.io/client-go/tools/clientcmd"
1616 "k8s.io/client-go/util/workqueue"
@@ -26,7 +26,6 @@ type Agent struct {
2626 discoveryClient * discovery.DiscoveryClient
2727 engine * deploysync.Engine
2828 deathChan chan interface {}
29- svcQueue workqueue.RateLimitingInterface
3029 cleanup engine.StopFunc
3130 refresh time.Duration
3231}
@@ -74,46 +73,44 @@ func New(clientConfig clientcmd.ClientConfig, refresh time.Duration, consoleUrl,
7473 consoleClient : consoleClient ,
7574 engine : engine ,
7675 deathChan : deathChan ,
77- svcQueue : svcQueue ,
7876 cleanup : cleanup ,
7977 refresh : refresh ,
8078 }, nil
8179}
8280
8381func (agent * Agent ) Run () {
8482 defer agent .cleanup ()
85- defer agent .svcQueue .ShutDown ()
8683 defer agent .engine .WipeCache ()
87- go func () {
88- for {
89- go agent .engine .ControlLoop ()
90- failure := <- agent .deathChan
91- fmt .Printf ("recovered from panic %v\n " , failure )
92- }
93- }()
84+ panicHandler := func (p interface {}) {
85+ fmt .Printf ("Task panicked: %v" , p )
86+ }
9487
95- wait . PollInfinite ( agent . refresh , func () ( done bool , err error ) {
88+ for {
9689 log .Info ("fetching services for cluster" )
9790 svcs , err := agent .consoleClient .GetServices ()
9891 if err != nil {
99- log .Error (err , "failed to fetch service list from deployments service" )
100- return false , nil
92+ log .Error (err , "failed to fetch service list from deployments service %v" , err )
93+ time .Sleep (agent .refresh )
94+ continue
10195 }
102-
96+ pool := pond . New ( 20 , 100 , pond . MinWorkers ( 20 ), pond . PanicHandler ( panicHandler ))
10397 for _ , svc := range svcs {
104- log .Info ("sending update for" , "service" , svc .ID )
105- agent .svcQueue .Add (svc .ID )
98+ log .Info ("sending update for" , "service" , svc .ID , "namespace" , svc .Namespace , "name" , svc .Name )
99+ pool .TrySubmit (func () {
100+ if err := agent .engine .ProcessItem (svc .ID ); err != nil {
101+ log .Error (err , "found unprocessable error" )
102+ }
103+ })
106104 }
107-
105+ pool . StopAndWait ()
108106 info , err := agent .discoveryClient .ServerVersion ()
109107 if err != nil {
110108 log .Error (err , "failed to fetch cluster version" )
111- return false , nil
112109 }
113110 v := fmt .Sprintf ("%s.%s" , info .Major , info .Minor )
114111 if err := agent .consoleClient .Ping (v ); err != nil {
115112 log .Error (err , "failed to ping cluster after scheduling syncs" )
116113 }
117- return false , nil
118- })
114+ time . Sleep ( agent . refresh )
115+ }
119116}
0 commit comments