File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ package monitor
1919import (
2020 "context"
2121 "fmt"
22+ "sync"
2223 "time"
2324
2425 "github.com/containerd/containerd"
@@ -164,19 +165,33 @@ func (m *monitor) reconcile(ctx context.Context) error {
164165 if err != nil {
165166 return err
166167 }
168+ var wgNSLoop sync.WaitGroup
167169 for _ , name := range ns {
168- ctx = namespaces . WithNamespace ( ctx , name )
169- changes , err := m . monitor ( ctx )
170- if err != nil {
171- logrus . WithError ( err ). Error ( "monitor for changes" )
172- continue
173- }
174- for _ , c := range changes {
175- if err := c . apply ( ctx , m . client ); err != nil {
176- logrus . WithError ( err ). Error ( "apply change" )
170+ name := name
171+ wgNSLoop . Add ( 1 )
172+ go func () {
173+ defer wgNSLoop . Done ( )
174+ ctx := namespaces . WithNamespace ( ctx , name )
175+ changes , err := m . monitor ( ctx )
176+ if err != nil {
177+ logrus . WithError ( err ). Error ( "monitor for changes" )
178+ return
177179 }
178- }
180+ var wgChangesLoop sync.WaitGroup
181+ for _ , c := range changes {
182+ c := c
183+ wgChangesLoop .Add (1 )
184+ go func () {
185+ defer wgChangesLoop .Done ()
186+ if err := c .apply (ctx , m .client ); err != nil {
187+ logrus .WithError (err ).Error ("apply change" )
188+ }
189+ }()
190+ }
191+ wgChangesLoop .Wait ()
192+ }()
179193 }
194+ wgNSLoop .Wait ()
180195 return nil
181196}
182197
You can’t perform that action at this time.
0 commit comments