/
types.go
50 lines (39 loc) · 1.54 KB
/
types.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
43
44
45
46
47
48
49
50
package reconciler
import (
"fmt"
clientset "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/cache"
"github.com/flomesh-io/fsm/pkg/k8s"
"github.com/flomesh-io/fsm/pkg/logger"
)
var log = logger.New("reconciler")
const (
// CrdInformerKey lookup identifier
CrdInformerKey k8s.InformerKey = "CRDInformerKey"
// MutatingWebhookInformerKey lookup identifier
MutatingWebhookInformerKey k8s.InformerKey = "MutatingWebhookConfigInformerKey"
// ValidatingWebhookInformerKey lookup identifier
ValidatingWebhookInformerKey k8s.InformerKey = "ValidatingWebhookConfigInformerKey"
// nameIndex is the lookup name for the most comment index function, which is to index by the name field
nameIndex string = "name"
)
// informerCollection is the type holding the collection of informers we keep
type informerCollection map[k8s.InformerKey]cache.SharedIndexInformer
// client is a struct for all components necessary to connect to and maintain state of a Kubernetes cluster
type client struct {
meshName string
fsmVersion string
kubeClient kubernetes.Interface
apiServerClient clientset.Interface
informers informerCollection
}
// metaNameIndexFunc is a default index function that indexes based on an object's name
func metaNameIndexFunc(obj interface{}) ([]string, error) {
meta, err := meta.Accessor(obj)
if err != nil {
return []string{""}, fmt.Errorf("object has no meta: %w", err)
}
return []string{meta.GetName()}, nil
}