-
Notifications
You must be signed in to change notification settings - Fork 1
/
service.go
36 lines (32 loc) · 922 Bytes
/
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
package definition
import (
"fmt"
log "github.com/echocat/slf4g"
v1 "k8s.io/api/core/v1"
"k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
"time"
)
type Service struct {
*Definition
}
func NewService(client kubernetes.Interface, resyncAfter time.Duration, logger log.Logger) (*Service, error) {
informerFactory := informers.NewSharedInformerFactory(client, resyncAfter)
informer := informerFactory.Core().V1().Services().Informer()
if definition, err := newDefinition("service", informer, logger); err != nil {
return nil, err
} else {
return &Service{
Definition: definition,
}, nil
}
}
func (this *Service) Get(key string) (*v1.Service, error) {
if item, exists, err := this.informer.GetStore().GetByKey(key); err != nil {
return nil, fmt.Errorf("cannot get service %s from cache: %v", key, err)
} else if !exists {
return nil, nil
} else {
return item.(*v1.Service), nil
}
}