This repository has been archived by the owner on Jul 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 277
/
types.go
106 lines (81 loc) · 3.38 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Package kubernetes implements the Kubernetes Controller interface to monitor and retrieve information regarding
// Kubernetes resources such as Namespaces, Services, Pods, Endpoints, and ServiceAccounts.
package kubernetes
import (
"time"
corev1 "k8s.io/api/core/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/cache"
"github.com/openservicemesh/osm/pkg/identity"
"github.com/openservicemesh/osm/pkg/logger"
"github.com/openservicemesh/osm/pkg/service"
)
var (
log = logger.New("kube-controller")
)
// EventType is the type of event we have received from Kubernetes
type EventType string
func (et EventType) String() string {
return string(et)
}
const (
// AddEvent is a type of a Kubernetes API event.
AddEvent EventType = "ADD"
// UpdateEvent is a type of a Kubernetes API event.
UpdateEvent EventType = "UPDATE"
// DeleteEvent is a type of a Kubernetes API event.
DeleteEvent EventType = "DELETE"
)
const (
// DefaultKubeEventResyncInterval is the default resync interval for k8s events
DefaultKubeEventResyncInterval = 5 * time.Minute
// providerName is the name of the Kubernetes event provider
providerName = "Kubernetes"
)
// InformerKey stores the different Informers we keep for K8s resources
type InformerKey string
const (
// Namespaces lookup identifier
Namespaces InformerKey = "Namespaces"
// Services lookup identifier
Services InformerKey = "Services"
// Pods lookup identifier
Pods InformerKey = "Pods"
// Endpoints lookup identifier
Endpoints InformerKey = "Endpoints"
// ServiceAccounts lookup identifier
ServiceAccounts InformerKey = "ServiceAccounts"
)
// informerCollection is the type holding the collection of informers we keep
type informerCollection map[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
kubeClient kubernetes.Interface
informers informerCollection
cacheSynced chan interface{}
}
// Controller is the controller interface for K8s services
type Controller interface {
// ListServices returns a list of all (monitored-namespace filtered) services in the mesh
ListServices() []*corev1.Service
// ListServiceAccounts returns a list of all (monitored-namespace filtered) service accounts in the mesh
ListServiceAccounts() []*corev1.ServiceAccount
// GetService returns a corev1 Service representation if the MeshService exists in cache, otherwise nil
GetService(svc service.MeshService) *corev1.Service
// IsMonitoredNamespace returns whether a namespace with the given name is being monitored
// by the mesh
IsMonitoredNamespace(string) bool
// ListMonitoredNamespaces returns the namespaces monitored by the mesh
ListMonitoredNamespaces() ([]string, error)
// GetNamespace returns k8s namespace present in cache
GetNamespace(ns string) *corev1.Namespace
// ListPods returns a list of pods part of the mesh
ListPods() []*corev1.Pod
// ListServiceIdentitiesForService lists ServiceAccounts associated with the given service
ListServiceIdentitiesForService(svc service.MeshService) ([]identity.K8sServiceAccount, error)
// GetEndpoints returns the endpoints for a given service, if found
GetEndpoints(svc service.MeshService) (*corev1.Endpoints, error)
// IsMetricsEnabled returns true if the pod in the mesh is correctly annotated for prometheus scrapping
IsMetricsEnabled(*corev1.Pod) bool
}