-
Notifications
You must be signed in to change notification settings - Fork 1
/
runtime.go
42 lines (34 loc) · 830 Bytes
/
runtime.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright (c) Saswata Mukherjee (@saswatamcode)
// Licensed under the Apache License 2.0.
package runtime
import (
"context"
"sync"
"github.com/saswatamcode/configmap-operator/pkg/subscription"
"k8s.io/apimachinery/pkg/watch"
)
func RunLoop(ctx context.Context, subscriptions []subscription.Subscription) error {
var wg sync.WaitGroup
for i := range subscriptions {
wg.Add(1)
go func(subscription subscription.Subscription) error {
watchInterface, err := subscription.Subscribe()
if err != nil {
return err
}
for {
select {
case e, ok := <-watchInterface.ResultChan():
if ok && e.Type != watch.Error {
subscription.Reconcile(e.Object, e.Type)
}
case <-ctx.Done():
wg.Done()
return nil
}
}
}(subscriptions[i]) //nolint
}
wg.Wait()
return nil
}