/
types.go
468 lines (381 loc) · 16.3 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Cilium
package v2
import (
"sort"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/cilium/cilium/api/v1/models"
alibabaCloudTypes "github.com/cilium/cilium/pkg/alibabacloud/eni/types"
eniTypes "github.com/cilium/cilium/pkg/aws/eni/types"
azureTypes "github.com/cilium/cilium/pkg/azure/types"
ipamTypes "github.com/cilium/cilium/pkg/ipam/types"
"github.com/cilium/cilium/pkg/node/addressing"
)
// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +k8s:openapi-gen=false
// +kubebuilder:resource:categories={cilium},singular="ciliumendpoint",path="ciliumendpoints",scope="Namespaced",shortName={cep,ciliumep}
// +kubebuilder:printcolumn:JSONPath=".status.id",description="Cilium endpoint id",name="Endpoint ID",type=integer
// +kubebuilder:printcolumn:JSONPath=".status.identity.id",description="Cilium identity id",name="Identity ID",type=integer
// +kubebuilder:printcolumn:JSONPath=".status.policy.ingress.state",description="Ingress enforcement in the endpoint",name="Ingress Enforcement",type=string
// +kubebuilder:printcolumn:JSONPath=".status.policy.egress.state",description="Egress enforcement in the endpoint",name="Egress Enforcement",type=string
// +kubebuilder:printcolumn:JSONPath=".status.visibility-policy-status",description="Status of visibility policy in the endpoint",name="Visibility Policy",type=string
// +kubebuilder:printcolumn:JSONPath=".status.state",description="Endpoint current state",name="Endpoint State",type=string
// +kubebuilder:printcolumn:JSONPath=".status.networking.addressing[0].ipv4",description="Endpoint IPv4 address",name="IPv4",type=string
// +kubebuilder:printcolumn:JSONPath=".status.networking.addressing[0].ipv6",description="Endpoint IPv6 address",name="IPv6",type=string
// +kubebuilder:storageversion
// CiliumEndpoint is the status of a Cilium policy rule.
type CiliumEndpoint struct {
// +deepequal-gen=false
metav1.TypeMeta `json:",inline"`
// +deepequal-gen=false
metav1.ObjectMeta `json:"metadata"`
// +kubebuilder:validation:Optional
Status EndpointStatus `json:"status"`
}
// EndpointPolicyState defines the state of the Policy mode: "enforcing", "non-enforcing", "disabled"
type EndpointPolicyState string
// EndpointStatus is the status of a Cilium endpoint.
type EndpointStatus struct {
// ID is the cilium-agent-local ID of the endpoint.
ID int64 `json:"id,omitempty"`
// Controllers is the list of failing controllers for this endpoint.
Controllers ControllerList `json:"controllers,omitempty"`
// ExternalIdentifiers is a set of identifiers to identify the endpoint
// apart from the pod name. This includes container runtime IDs.
ExternalIdentifiers *models.EndpointIdentifiers `json:"external-identifiers,omitempty"`
// Health is the overall endpoint & subcomponent health.
Health *models.EndpointHealth `json:"health,omitempty"`
// Identity is the security identity associated with the endpoint
Identity *EndpointIdentity `json:"identity,omitempty"`
// Log is the list of the last few warning and error log entries
Log []*models.EndpointStatusChange `json:"log,omitempty"`
// Networking is the networking properties of the endpoint.
//
// +kubebuilder:validation:Optional
Networking *EndpointNetworking `json:"networking,omitempty"`
// Encryption is the encryption configuration of the node
//
// +kubebuilder:validation:Optional
Encryption EncryptionSpec `json:"encryption,omitempty"`
Policy *EndpointPolicy `json:"policy,omitempty"`
VisibilityPolicyStatus *string `json:"visibility-policy-status,omitempty"`
// State is the state of the endpoint.
//
// +kubebuilder:validation:Enum=creating;waiting-for-identity;not-ready;waiting-to-regenerate;regenerating;restoring;ready;disconnecting;disconnected;invalid
State string `json:"state,omitempty"`
NamedPorts models.NamedPorts `json:"named-ports,omitempty"`
}
// EndpointStatusLogEntries is the maximum number of log entries in
// EndpointStatus.Log.
const EndpointStatusLogEntries = 5
// +k8s:deepcopy-gen=false
// ControllerList is a list of ControllerStatus.
type ControllerList []ControllerStatus
// Sort sorts the ControllerList by controller name
func (c ControllerList) Sort() {
sort.Slice(c, func(i, j int) bool { return c[i].Name < c[j].Name })
}
// ControllerStatus is the status of a failing controller.
type ControllerStatus struct {
// Name is the name of the controller
Name string `json:"name,omitempty"`
// Configuration is the controller configuration
Configuration *models.ControllerStatusConfiguration `json:"configuration,omitempty"`
// Status is the status of the controller
Status ControllerStatusStatus `json:"status,omitempty"`
// UUID is the UUID of the controller
UUID string `json:"uuid,omitempty"`
}
// +k8s:deepcopy-gen=false
// ControllerStatusStatus is the detailed status section of a controller.
type ControllerStatusStatus struct {
ConsecutiveFailureCount int64 `json:"consecutive-failure-count,omitempty"`
FailureCount int64 `json:"failure-count,omitempty"`
LastFailureMsg string `json:"last-failure-msg,omitempty"`
LastFailureTimestamp string `json:"last-failure-timestamp,omitempty"`
LastSuccessTimestamp string `json:"last-success-timestamp,omitempty"`
SuccessCount int64 `json:"success-count,omitempty"`
}
// EndpointPolicy represents the endpoint's policy by listing all allowed
// ingress and egress identities in combination with L4 port and protocol.
type EndpointPolicy struct {
Ingress *EndpointPolicyDirection `json:"ingress,omitempty"`
Egress *EndpointPolicyDirection `json:"egress,omitempty"`
}
// EndpointPolicyDirection is the list of allowed identities per direction.
type EndpointPolicyDirection struct {
Enforcing bool `json:"enforcing"`
Allowed AllowedIdentityList `json:"allowed,omitempty"`
Denied DenyIdentityList `json:"denied,omitempty"`
// Deprecated
Removing AllowedIdentityList `json:"removing,omitempty"`
// Deprecated
Adding AllowedIdentityList `json:"adding,omitempty"`
State EndpointPolicyState `json:"state,omitempty"`
}
// IdentityTuple specifies a peer by identity, destination port and protocol.
type IdentityTuple struct {
Identity uint64 `json:"identity,omitempty"`
IdentityLabels map[string]string `json:"identity-labels,omitempty"`
DestPort uint16 `json:"dest-port,omitempty"`
Protocol uint8 `json:"protocol,omitempty"`
}
// +k8s:deepcopy-gen=false
// IdentityList is a list of IdentityTuple.
type IdentityList []IdentityTuple
// Sort sorts a list IdentityList by numeric identity, port and protocol.
func (a IdentityList) Sort() {
sort.Slice(a, func(i, j int) bool {
if a[i].Identity < a[j].Identity {
return true
} else if a[i].Identity == a[j].Identity {
if a[i].DestPort < a[j].DestPort {
return true
} else if a[i].DestPort == a[j].DestPort {
return a[i].Protocol < a[j].Protocol
}
}
return false
})
}
// +k8s:deepcopy-gen=false
// AllowedIdentityList is a list of IdentityTuples that species peers that are
// allowed.
type AllowedIdentityList IdentityList
// Sort sorts a list IdentityList by numeric identity, port and protocol.
func (a AllowedIdentityList) Sort() {
IdentityList(a).Sort()
}
// +k8s:deepcopy-gen=false
// DenyIdentityList is a list of IdentityTuples that species peers that are
// denied.
type DenyIdentityList IdentityList
// Sort sorts a list IdentityList by numeric identity, port and protocol.
func (d DenyIdentityList) Sort() {
IdentityList(d).Sort()
}
// EndpointIdentity is the identity information of an endpoint.
type EndpointIdentity struct {
// ID is the numeric identity of the endpoint
ID int64 `json:"id,omitempty"`
// Labels is the list of labels associated with the identity
Labels []string `json:"labels,omitempty"`
}
// +genclient
// +genclient:nonNamespaced
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:resource:categories={cilium},singular="ciliumidentity",path="ciliumidentities",scope="Cluster",shortName={ciliumid}
// +kubebuilder:printcolumn:JSONPath=".metadata.labels.io\\.kubernetes\\.pod\\.namespace",description="The namespace of the entity",name="Namespace",type=string
// +kubebuilder:printcolumn:JSONPath=".metadata.creationTimestamp",description="The age of the identity",name="Age",type=date
// +kubebuilder:subresource:status
// +kubebuilder:storageversion
// CiliumIdentity is a CRD that represents an identity managed by Cilium.
// It is intended as a backing store for identity allocation, acting as the
// global coordination backend, and can be used in place of a KVStore (such as
// etcd).
// The name of the CRD is the numeric identity and the labels on the CRD object
// are the the kubernetes sourced labels seen by cilium. This is currently the
// only label source possible when running under kubernetes. Non-kubernetes
// labels are filtered but all labels, from all sources, are places in the
// SecurityLabels field. These also include the source and are used to define
// the identity.
// The labels under metav1.ObjectMeta can be used when searching for
// CiliumIdentity instances that include particular labels. This can be done
// with invocations such as:
// kubectl get ciliumid -l 'foo=bar'
// Each node using a ciliumidentity updates the status field with it's name and
// a timestamp when it first allocates or uses an identity, and periodically
// after that. It deletes its entry when no longer using this identity.
// cilium-operator uses the list of nodes in status to reference count
// users of this identity, and to expire stale usage.
type CiliumIdentity struct {
// +deepequal-gen=false
metav1.TypeMeta `json:",inline"`
// +deepequal-gen=false
metav1.ObjectMeta `json:"metadata"`
// SecurityLabels is the source-of-truth set of labels for this identity.
SecurityLabels map[string]string `json:"security-labels"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +deepequal-gen=false
// CiliumIdentityList is a list of CiliumIdentity objects.
type CiliumIdentityList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
// Items is a list of CiliumIdentity
Items []CiliumIdentity `json:"items"`
}
// +k8s:deepcopy-gen=false
// AddressPair is is a par of IPv4 and/or IPv6 address.
type AddressPair struct {
IPV4 string `json:"ipv4,omitempty"`
IPV6 string `json:"ipv6,omitempty"`
}
// +k8s:deepcopy-gen=false
// AddressPairList is a list of address pairs.
type AddressPairList []*AddressPair
// Sort sorts an AddressPairList by IPv4 and IPv6 address.
func (a AddressPairList) Sort() {
sort.Slice(a, func(i, j int) bool {
if a[i].IPV4 < a[j].IPV4 {
return true
} else if a[i].IPV4 == a[j].IPV4 {
return a[i].IPV6 < a[j].IPV6
}
return false
})
}
// EndpointNetworking is the addressing information of an endpoint.
type EndpointNetworking struct {
// IP4/6 addresses assigned to this Endpoint
Addressing AddressPairList `json:"addressing"`
// NodeIP is the IP of the node the endpoint is running on. The IP must
// be reachable between nodes.
NodeIP string `json:"node,omitempty"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +k8s:openapi-gen=false
// +deepequal-gen=false
// CiliumEndpointList is a list of CiliumEndpoint objects.
type CiliumEndpointList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
// Items is a list of CiliumEndpoint
Items []CiliumEndpoint `json:"items"`
}
// +genclient
// +genclient:nonNamespaced
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:resource:categories={cilium},singular="ciliumnode",path="ciliumnodes",scope="Cluster",shortName={cn,ciliumn}
// +kubebuilder:storageversion
// +kubebuilder:subresource:status
// CiliumNode represents a node managed by Cilium. It contains a specification
// to control various node specific configuration aspects and a status section
// to represent the status of the node.
type CiliumNode struct {
// +deepequal-gen=false
metav1.TypeMeta `json:",inline"`
// +deepequal-gen=false
metav1.ObjectMeta `json:"metadata"`
// Spec defines the desired specification/configuration of the node.
Spec NodeSpec `json:"spec"`
// Status defines the realized specification/configuration and status
// of the node.
//
// +kubebuilder:validation:Optional
Status NodeStatus `json:"status,omitempty"`
}
// NodeAddress is a node address.
type NodeAddress struct {
// Type is the type of the node address
Type addressing.AddressType `json:"type,omitempty"`
// IP is an IP of a node
IP string `json:"ip,omitempty"`
}
// NodeSpec is the configuration specific to a node.
type NodeSpec struct {
// InstanceID is the identifier of the node. This is different from the
// node name which is typically the FQDN of the node. The InstanceID
// typically refers to the identifier used by the cloud provider or
// some other means of identification.
InstanceID string `json:"instance-id,omitempty"`
// Addresses is the list of all node addresses.
//
// +kubebuilder:validation:Optional
Addresses []NodeAddress `json:"addresses,omitempty"`
// HealthAddressing is the addressing information for health connectivity
// checking.
//
// +kubebuilder:validation:Optional
HealthAddressing HealthAddressingSpec `json:"health,omitempty"`
// IngressAddressing is the addressing information for Ingress listener.
//
// +kubebuilder:validation:Optional
IngressAddressing AddressPair `json:"ingress,omitempty"`
// Encryption is the encryption configuration of the node.
//
// +kubebuilder:validation:Optional
Encryption EncryptionSpec `json:"encryption,omitempty"`
// ENI is the AWS ENI specific configuration.
//
// +kubebuilder:validation:Optional
ENI eniTypes.ENISpec `json:"eni,omitempty"`
// Azure is the Azure IPAM specific configuration.
//
// +kubebuilder:validation:Optional
Azure azureTypes.AzureSpec `json:"azure,omitempty"`
// AlibabaCloud is the AlibabaCloud IPAM specific configuration.
//
// +kubebuilder:validation:Optional
AlibabaCloud alibabaCloudTypes.Spec `json:"alibaba-cloud,omitempty"`
// IPAM is the address management specification. This section can be
// populated by a user or it can be automatically populated by an IPAM
// operator.
//
// +kubebuilder:validation:Optional
IPAM ipamTypes.IPAMSpec `json:"ipam,omitempty"`
// NodeIdentity is the Cilium numeric identity allocated for the node, if any.
//
// +kubebuilder:validation:Optional
NodeIdentity uint64 `json:"nodeidentity,omitempty"`
}
// HealthAddressingSpec is the addressing information required to do
// connectivity health checking.
type HealthAddressingSpec struct {
// IPv4 is the IPv4 address of the IPv4 health endpoint.
//
// +kubebuilder:validation:Optional
IPv4 string `json:"ipv4,omitempty"`
// IPv6 is the IPv6 address of the IPv4 health endpoint.
//
// +kubebuilder:validation:Optional
IPv6 string `json:"ipv6,omitempty"`
}
// EncryptionSpec defines the encryption relevant configuration of a node.
type EncryptionSpec struct {
// Key is the index to the key to use for encryption or 0 if encryption is
// disabled.
//
// +kubebuilder:validation:Optional
Key int `json:"key,omitempty"`
}
// NodeStatus is the status of a node.
type NodeStatus struct {
// ENI is the AWS ENI specific status of the node.
//
// +kubebuilder:validation:Optional
ENI eniTypes.ENIStatus `json:"eni,omitempty"`
// Azure is the Azure specific status of the node.
//
// +kubebuilder:validation:Optional
Azure azureTypes.AzureStatus `json:"azure,omitempty"`
// IPAM is the IPAM status of the node.
//
// +kubebuilder:validation:Optional
IPAM ipamTypes.IPAMStatus `json:"ipam,omitempty"`
// AlibabaCloud is the AlibabaCloud specific status of the node.
//
// +kubebuilder:validation:Optional
AlibabaCloud alibabaCloudTypes.ENIStatus `json:"alibaba-cloud,omitempty"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +deepequal-gen=false
// CiliumNodeList is a list of CiliumNode objects.
type CiliumNodeList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
// Items is a list of CiliumNode
Items []CiliumNode `json:"items"`
}
// InstanceID returns the InstanceID of a CiliumNode.
func (n *CiliumNode) InstanceID() (instanceID string) {
if n != nil {
instanceID = n.Spec.InstanceID
// OBSOLETE: This fallback can be removed in Cilium 1.9
if instanceID == "" {
instanceID = n.Spec.ENI.InstanceID
}
}
return
}