-
Notifications
You must be signed in to change notification settings - Fork 0
/
service.go
39 lines (31 loc) · 1.08 KB
/
service.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
package gateway
import (
"time"
"github.com/kyma-project/kyma/components/console-backend-service/pkg/executor"
"k8s.io/client-go/kubernetes"
)
// Service gives a functionality to provide gateway status. It hides implementation details
// and exports necessary methods.
type Service struct {
provider *provider
statusWatcher *gatewayStatusWatcher
cfg Config
}
func New(k8sCli kubernetes.Interface, reCfg Config, informerResyncPeriod time.Duration) (*Service, error) {
gatewaySvcProvider := newProvider(k8sCli.CoreV1(), reCfg.IntegrationNamespace, informerResyncPeriod)
watcher := newStatusWatcher(gatewaySvcProvider, reCfg.StatusCallTimeout)
return &Service{
provider: gatewaySvcProvider,
statusWatcher: watcher,
cfg: reCfg,
}, nil
}
func (svc *Service) Start(stopCh <-chan struct{}) {
svc.provider.WaitForCacheSync(stopCh)
executor.NewPeriodic(svc.cfg.StatusRefreshPeriod, func(stopCh <-chan struct{}) {
svc.statusWatcher.Refresh(stopCh)
}).Run(stopCh)
}
func (svc *Service) GetStatus(appName string) Status {
return svc.statusWatcher.GetStatus(appName)
}