1
- package controller
2
-
3
- // An observer polls the Kubernetes api-server to discover all supported
1
+ // Package observer polls the Kubernetes api-server to discover all supported
4
2
// API groups/object kinds, and launch a new controller for each of them.
5
3
// Due to CRD/TPR, new API groups / object kinds may appear at any time,
6
4
// that's why we keep polling the API server.
5
+ package observer
7
6
8
7
import (
9
8
"fmt"
10
9
"strings"
11
10
"time"
12
11
13
12
"github.com/bpineau/katafygio/config"
13
+ "github.com/bpineau/katafygio/pkg/controller"
14
14
15
15
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
16
16
"k8s.io/apimachinery/pkg/runtime"
@@ -27,10 +27,10 @@ const discoveryInterval = 60 * time.Second
27
27
type Observer struct {
28
28
stop chan struct {}
29
29
done chan struct {}
30
- evch chan Event
30
+ evch chan controller. Event
31
31
disc * discovery.DiscoveryClient
32
32
cpool dynamic.ClientPool
33
- ctrls map [string ]* Controller
33
+ ctrls map [string ]* controller. Controller
34
34
config * config.KfConfig
35
35
}
36
36
@@ -44,15 +44,15 @@ type gvk struct {
44
44
45
45
type resources map [string ]* gvk
46
46
47
- // NewObserver returns a new observer, that will watch for api resource kinds
47
+ // New returns a new observer, that will watch for api resource kinds
48
48
// and create new controllers for each one.
49
- func NewObserver (config * config.KfConfig , evch chan Event ) * Observer {
49
+ func New (config * config.KfConfig , evch chan controller. Event ) * Observer {
50
50
return & Observer {
51
51
config : config ,
52
52
evch : evch ,
53
53
disc : discovery .NewDiscoveryClientForConfigOrDie (config .Client ),
54
54
cpool : dynamic .NewDynamicClientPool (config .Client ),
55
- ctrls : make (map [string ]* Controller ),
55
+ ctrls : make (map [string ]* controller. Controller ),
56
56
}
57
57
}
58
58
@@ -126,7 +126,7 @@ func (c *Observer) refresh() error {
126
126
},
127
127
}
128
128
129
- c .ctrls [name ] = NewController (lw , c .evch , strings .ToLower (res .ar .Kind ), c .config )
129
+ c .ctrls [name ] = controller . New (lw , c .evch , strings .ToLower (res .ar .Kind ), c .config )
130
130
go c .ctrls [name ].Start ()
131
131
}
132
132
@@ -146,9 +146,13 @@ func (c *Observer) expandAndFilterAPIResources(groups []*metav1.APIResourceList)
146
146
resources := make (map [string ]* gvk )
147
147
148
148
for _ , group := range groups {
149
- gv , _ := schema .ParseGroupVersion (group .GroupVersion )
150
- for _ , ar := range group .APIResources {
149
+ gv , err := schema .ParseGroupVersion (group .GroupVersion )
150
+ if err != nil {
151
+ c .config .Logger .Errorf ("api-server sent an unparsable group version: %v" , err )
152
+ continue
153
+ }
151
154
155
+ for _ , ar := range group .APIResources {
152
156
// remove subresources (like job/status or deployments/scale)
153
157
if strings .ContainsRune (ar .Name , '/' ) {
154
158
continue
0 commit comments