-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
types.go
154 lines (113 loc) 路 4.15 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package client
import (
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/version"
"k8s.io/client-go/discovery/cached/disk"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/kubernetes"
restclient "k8s.io/client-go/rest"
mv1beta1 "k8s.io/metrics/pkg/apis/metrics/v1beta1"
versioned "k8s.io/metrics/pkg/client/clientset/versioned"
)
const (
// NA Not available
NA = "n/a"
// NamespaceAll designates the fictional all namespace.
NamespaceAll = "all"
// AllNamespaces designates all namespaces.
AllNamespaces = ""
// ClusterScope designates a resource is not namespaced.
ClusterScope = "-"
// NotNamespaced designates a non resource namespace.
NotNamespaced = "*"
// CreateVerb represents create access on a resource.
CreateVerb = "create"
// UpdateVerb represents an update access on a resource.
UpdateVerb = "update"
// PatchVerb represents a patch access on a resource.
PatchVerb = "patch"
// DeleteVerb represents a delete access on a resource.
DeleteVerb = "delete"
// GetVerb represents a get access on a resource.
GetVerb = "get"
// ListVerb represents a list access on a resource.
ListVerb = "list"
// WatchVerb represents a watch access on a resource.
WatchVerb = "watch"
)
var (
// GetAccess reads a resource.
GetAccess = []string{GetVerb}
// ListAccess list resources.
ListAccess = []string{ListVerb}
// MonitorAccess monitors a collection of resources.
MonitorAccess = []string{ListVerb, WatchVerb}
// ReadAllAccess represents an all read access to a resource.
ReadAllAccess = []string{GetVerb, ListVerb, WatchVerb}
)
// ContainersMetrics tracks containers metrics.
type ContainersMetrics map[string]*mv1beta1.ContainerMetrics
// NodesMetricsMap tracks node metrics.
type NodesMetricsMap map[string]*mv1beta1.NodeMetrics
// PodsMetricsMap tracks pod metrics.
type PodsMetricsMap map[string]*mv1beta1.PodMetrics
// Authorizer checks what a user can or cannot do to a resource.
type Authorizer interface {
// CanI returns true if the user can use these actions for a given resource.
CanI(ns, gvr string, verbs []string) (bool, error)
}
// Connection represents a Kubenetes apiserver connection.
type Connection interface {
Authorizer
// Config returns current config.
Config() *Config
// ConnectionOK checks api server connection status.
ConnectionOK() bool
// DialOrDie connects to api server.
Dial() (kubernetes.Interface, error)
// SwitchContext switches cluster based on context.
SwitchContext(ctx string) error
// CachedDiscovery connects to discovery client.
CachedDiscovery() (*disk.CachedDiscoveryClient, error)
// RestConfig connects to rest client.
RestConfig() (*restclient.Config, error)
// MXDial connects to metrics server.
MXDial() (*versioned.Clientset, error)
// DynDial connects to dynamic client.
DynDial() (dynamic.Interface, error)
// HasMetrics checks if metrics server is available.
HasMetrics() bool
// ValidNamespaces returns all available namespaces.
ValidNamespaces() ([]v1.Namespace, error)
// ServerVersion returns current server version.
ServerVersion() (*version.Info, error)
// CheckConnectivity checks if api server connection is happy or not.
CheckConnectivity() bool
// ActiveCluster returns the current cluster name.
ActiveCluster() string
// ActiveNamespace returns the current namespace.
ActiveNamespace() string
// IsActiveNamespace checks if given ns is active.
IsActiveNamespace(string) bool
}
// CurrentMetrics tracks current cpu/mem.
type CurrentMetrics struct {
CurrentCPU, CurrentMEM, CurrentEphemeral int64
}
// PodMetrics represent an aggregation of all pod containers metrics.
type PodMetrics CurrentMetrics
// NodeMetrics describes raw node metrics.
type NodeMetrics struct {
CurrentMetrics
AllocatableCPU, AllocatableMEM, AllocatableEphemeral int64
AvailableCPU, AvailableMEM, AvailableEphemeral int64
TotalCPU, TotalMEM, TotalEphemeral int64
}
// ClusterMetrics summarizes total node metrics as percentages.
type ClusterMetrics struct {
PercCPU, PercMEM, PercEphemeral int
}
// NodesMetrics tracks usage metrics per nodes.
type NodesMetrics map[string]NodeMetrics
// PodsMetrics tracks usage metrics per pods.
type PodsMetrics map[string]PodMetrics