-
Notifications
You must be signed in to change notification settings - Fork 353
/
types.go
524 lines (441 loc) · 18 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
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
// Copyright 2021 Antrea Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package v1alpha2
import (
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"antrea.io/antrea/pkg/apis/crd/v1alpha1"
)
// +genclient
// +genclient:noStatus
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type ExternalEntity struct {
metav1.TypeMeta `json:",inline"`
// Standard metadata of the object.
metav1.ObjectMeta `json:"metadata,omitempty"`
// Desired state of the external entity.
Spec ExternalEntitySpec `json:"spec,omitempty"`
}
// ExternalEntitySpec defines the desired state for ExternalEntity.
type ExternalEntitySpec struct {
// Endpoints is a list of external endpoints associated with this entity.
Endpoints []Endpoint `json:"endpoints,omitempty"`
// Ports maintain the list of named ports.
Ports []NamedPort `json:"ports,omitempty"`
// ExternalNode is the opaque identifier of the agent/controller responsible
// for additional processing or handling of this external entity.
ExternalNode string `json:"externalNode,omitempty"`
}
// Endpoint refers to an endpoint associated with the ExternalEntity.
type Endpoint struct {
// IP associated with this endpoint.
IP string `json:"ip,omitempty"`
// Name identifies this endpoint. Could be the network interface name in case of VMs.
// +optional
Name string `json:"name,omitempty"`
}
// NamedPort describes the port and protocol to match in a rule.
type NamedPort struct {
// The protocol (TCP, UDP, or SCTP) which traffic must match.
// If not specified, this field defaults to TCP.
// +optional
Protocol v1.Protocol `json:"protocol,omitempty"`
// The port on the given protocol.
// +optional
Port int32 `json:"port,omitempty"`
// Name associated with the Port.
// +optional
Name string `json:"name,omitempty"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type ExternalEntityList struct {
metav1.TypeMeta `json:",inline"`
// +optional
metav1.ListMeta `json:"metadata,omitempty"`
Items []ExternalEntity `json:"items,omitempty"`
}
// ClusterGroupReference represent reference to a ClusterGroup.
type ClusterGroupReference string
// +genclient
// +genclient:nonNamespaced
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type ClusterGroup struct {
metav1.TypeMeta `json:",inline"`
// Standard metadata of the object.
metav1.ObjectMeta `json:"metadata,omitempty"`
// Desired state of the group.
Spec GroupSpec `json:"spec"`
// Most recently observed status of the group.
Status GroupStatus `json:"status"`
}
type GroupSpec struct {
// Select Pods matching the labels set in the PodSelector in
// AppliedTo/To/From fields. If set with NamespaceSelector, Pods are
// matched from Namespaces matched by the NamespaceSelector.
// Cannot be set with any other selector except NamespaceSelector.
// +optional
PodSelector *metav1.LabelSelector `json:"podSelector,omitempty"`
// Select all Pods from Namespaces matched by this selector, as
// workloads in AppliedTo/To/From fields. If set with PodSelector,
// Pods are matched from Namespaces matched by the NamespaceSelector.
// Cannot be set with any other selector except PodSelector.
// +optional
NamespaceSelector *metav1.LabelSelector `json:"namespaceSelector,omitempty"`
// IPBlock describes the IPAddresses/IPBlocks that is matched in to/from.
// IPBlock cannot be set as part of the AppliedTo field.
// Cannot be set with any other selector or ServiceReference.
// Cannot be set with IPBlocks.
// +optional
IPBlock *v1alpha1.IPBlock `json:"ipBlock,omitempty"`
// IPBlocks is a list of IPAddresses/IPBlocks that is matched in to/from.
// IPBlock cannot be set as part of the AppliedTo field.
// Cannot be set with any other selector or ServiceReference.
// Cannot be set with IPBlock.
// +optional
IPBlocks []v1alpha1.IPBlock `json:"ipBlocks,omitempty"`
// Select backend Pods of the referred Service.
// Cannot be set with any other selector or ipBlock.
// +optional
ServiceReference *v1alpha1.NamespacedName `json:"serviceReference,omitempty"`
// Select ExternalEntities from all Namespaces as workloads
// in AppliedTo/To/From fields. If set with NamespaceSelector,
// ExternalEntities are matched from Namespaces matched by the
// NamespaceSelector.
// Cannot be set with any other selector except NamespaceSelector.
// +optional
ExternalEntitySelector *metav1.LabelSelector `json:"externalEntitySelector,omitempty"`
// Select other ClusterGroups by name. The ClusterGroups must already
// exist and must not contain ChildGroups themselves.
// Cannot be set with any selector/IPBlock/ServiceReference.
// +optional
ChildGroups []ClusterGroupReference `json:"childGroups,omitempty"`
}
type GroupConditionType string
const GroupMembersComputed GroupConditionType = "GroupMembersComputed"
type GroupCondition struct {
Type GroupConditionType `json:"type"`
Status v1.ConditionStatus `json:"status"`
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
}
// GroupStatus represents information about the status of a Group.
type GroupStatus struct {
Conditions []GroupCondition `json:"conditions,omitempty"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type ClusterGroupList struct {
metav1.TypeMeta `json:",inline"`
// +optional
metav1.ListMeta `json:"metadata,omitempty"`
Items []ClusterGroup `json:"items,omitempty"`
}
// AppliedTo selects the entities to which a policy is applied.
type AppliedTo struct {
// Select Pods matched by this selector. If set with NamespaceSelector,
// Pods are matched from Namespaces matched by the NamespaceSelector;
// otherwise, Pods are matched from all Namespaces.
// +optional
PodSelector *metav1.LabelSelector `json:"podSelector,omitempty"`
// Select all Pods from Namespaces matched by this selector. If set with
// PodSelector, Pods are matched from Namespaces matched by the
// NamespaceSelector.
// +optional
NamespaceSelector *metav1.LabelSelector `json:"namespaceSelector,omitempty"`
// Groups is the set of ClusterGroup names.
// +optional
Groups []string `json:"groups,omitempty"`
}
// +genclient
// +genclient:nonNamespaced
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// Egress defines which egress (SNAT) IP the traffic from the selected Pods to
// the external network should use.
type Egress struct {
metav1.TypeMeta `json:",inline"`
// Standard metadata of the object.
metav1.ObjectMeta `json:"metadata,omitempty"`
// Specification of the desired behavior of Egress.
Spec EgressSpec `json:"spec"`
// EgressStatus represents the current status of an Egress.
Status EgressStatus `json:"status"`
}
// EgressStatus represents the current status of an Egress.
type EgressStatus struct {
// The name of the Node that holds the Egress IP.
EgressNode string `json:"egressNode"`
// EgressIP indicates the effective Egress IP for the selected workloads. It could be empty if the Egress IP in spec
// is not assigned to any Node. It's also useful when there are more than one Egress IP specified in spec.
EgressIP string `json:"egressIP"`
}
// EgressSpec defines the desired state for Egress.
type EgressSpec struct {
// AppliedTo selects Pods to which the Egress will be applied.
AppliedTo AppliedTo `json:"appliedTo"`
// EgressIP specifies the SNAT IP address for the selected workloads.
// If ExternalIPPool is empty, it must be specified manually.
// If ExternalIPPool is non-empty, it can be empty and will be assigned by Antrea automatically.
// If both ExternalIPPool and EgressIP are non-empty, the IP must be in the pool.
EgressIP string `json:"egressIP,omitempty"`
// EgressIPs specifies multiple SNAT IP addresses for the selected workloads.
// Cannot be set with EgressIP.
EgressIPs []string `json:"egressIPs,omitempty"`
// ExternalIPPool specifies the IP Pool that the EgressIP should be allocated from.
// If it is empty, the specified EgressIP must be assigned to a Node manually.
// If it is non-empty, the EgressIP will be assigned to a Node specified by the pool automatically and will failover
// to a different Node when the Node becomes unreachable.
ExternalIPPool string `json:"externalIPPool,omitempty"`
// ExternalIPPools specifies multiple unique IP Pools that the EgressIPs should be allocated from. Entries with the
// same index in EgressIPs and ExternalIPPools are correlated.
// Cannot be set with ExternalIPPool.
ExternalIPPools []string `json:"externalIPPools,omitempty"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type EgressList struct {
metav1.TypeMeta `json:",inline"`
// +optional
metav1.ListMeta `json:"metadata,omitempty"`
Items []Egress `json:"items"`
}
// +genclient
// +genclient:nonNamespaced
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// ExternalIPPool defines one or multiple IP sets that can be used in the external network. For instance, the IPs can be
// allocated to the Egress resources as the Egress IPs.
type ExternalIPPool struct {
metav1.TypeMeta `json:",inline"`
// Standard metadata of the object.
metav1.ObjectMeta `json:"metadata,omitempty"`
// Specification of the ExternalIPPool.
Spec ExternalIPPoolSpec `json:"spec"`
// The current status of the ExternalIPPool.
Status ExternalIPPoolStatus `json:"status"`
}
type ExternalIPPoolSpec struct {
// The IP ranges of this IP pool, e.g. 10.10.0.0/24, 10.10.10.2-10.10.10.20, 10.10.10.30-10.10.10.30.
IPRanges []IPRange `json:"ipRanges"`
// The Nodes that the external IPs can be assigned to. If empty, it means all Nodes.
NodeSelector metav1.LabelSelector `json:"nodeSelector"`
}
// IPRange is a set of contiguous IP addresses, represented by a CIDR or a pair of start and end IPs.
type IPRange struct {
// The CIDR of this range, e.g. 10.10.10.0/24.
CIDR string `json:"cidr,omitempty"`
// The start IP of the range, e.g. 10.10.20.5, inclusive.
Start string `json:"start,omitempty"`
// The end IP of the range, e.g. 10.10.20.20, inclusive.
End string `json:"end,omitempty"`
}
type ExternalIPPoolStatus struct {
Usage IPPoolUsage `json:"usage,omitempty"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type ExternalIPPoolList struct {
metav1.TypeMeta `json:",inline"`
// +optional
metav1.ListMeta `json:"metadata,omitempty"`
Items []ExternalIPPool `json:"items"`
}
// +genclient
// +genclient:nonNamespaced
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// IPPool defines one or multiple IP sets that can be used for flexible IPAM feature. For instance, the IPs can be
// allocated to Pods according to IP pool specified in Deployment annotation.
type IPPool struct {
metav1.TypeMeta `json:",inline"`
// Standard metadata of the object.
metav1.ObjectMeta `json:"metadata,omitempty"`
// Specification of the IPPool.
Spec IPPoolSpec `json:"spec"`
// Most recently observed status of the pool.
Status IPPoolStatus `json:"status"`
}
type IPVersion int
const (
IPv4 = IPVersion(4)
IPv6 = IPVersion(6)
)
type IPPoolSpec struct {
// IP Version for this IP pool - either 4 or 6
IPVersion IPVersion `json:"ipVersion"`
// List IP ranges, along with subnet definition.
IPRanges []SubnetIPRange `json:"ipRanges"`
}
// SubnetInfo specifies subnet attributes for IP Range
type SubnetInfo struct {
// Gateway IP for this subnet, eg. 10.10.1.1
Gateway string `json:"gateway"`
// Prefix length for the subnet, eg. 24
PrefixLength int32 `json:"prefixLength"`
// VLAN ID for this subnet. Default is 0. Valid value is 0~4094.
VLAN uint16 `json:"vlan,omitempty"`
}
// SubnetIPRange is a set of contiguous IP addresses, represented by a CIDR or a pair of start and end IPs,
// along with subnet definition.
type SubnetIPRange struct {
IPRange `json:",inline"`
SubnetInfo `json:",inline"`
}
type IPPoolStatus struct {
IPAddresses []IPAddressState `json:"ipAddresses,omitempty"`
Usage IPPoolUsage `json:"usage,omitempty"`
}
type IPPoolUsage struct {
// Total number of IPs.
Total int `json:"total"`
// Number of allocated IPs.
Used int `json:"used"`
}
type IPAddressPhase string
const (
IPAddressPhaseAllocated IPAddressPhase = "Allocated"
IPAddressPhasePreallocated IPAddressPhase = "Preallocated"
IPAddressPhaseReserved IPAddressPhase = "Reserved"
)
type IPAddressState struct {
// IP Address this entry is tracking
IPAddress string `json:"ipAddress"`
// Allocation state - either Allocated or Preallocated
Phase IPAddressPhase `json:"phase"`
// Owner this IP Address is allocated to
Owner IPAddressOwner `json:"owner"`
// TODO: add usage statistics (consistent with ExternalIPPool status)
}
type IPAddressOwner struct {
Pod *PodOwner `json:"pod,omitempty"`
StatefulSet *StatefulSetOwner `json:"statefulSet,omitempty"`
}
// Pod owner
type PodOwner struct {
Name string `json:"name"`
Namespace string `json:"namespace"`
ContainerID string `json:"containerID"`
// Network interface name. Used when the IP is allocated for a secondary network interface
// of the Pod.
IFName string `json:"ifName,omitempty"`
}
// StatefulSet owner
type StatefulSetOwner struct {
Name string `json:"name"`
Namespace string `json:"namespace"`
Index int `json:"index"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type IPPoolList struct {
metav1.TypeMeta `json:",inline"`
// +optional
metav1.ListMeta `json:"metadata,omitempty"`
Items []IPPool `json:"items"`
}
// +genclient
// +genclient:nonNamespaced
// +genclient:noStatus
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// TrafficControl allows mirroring or redirecting the traffic Pods send or receive. It enables users to monitor and
// analyze Pod traffic, and to enforce custom network protections for Pods with fine-grained control over network
// traffic.
type TrafficControl struct {
metav1.TypeMeta `json:",inline"`
// Standard metadata of the object.
metav1.ObjectMeta `json:"metadata,omitempty"`
// Specification of the desired behavior of TrafficControl.
Spec TrafficControlSpec `json:"spec"`
}
type TrafficControlSpec struct {
// AppliedTo selects Pods to which the traffic control configuration will be applied.
AppliedTo AppliedTo `json:"appliedTo"`
// The direction of traffic that should be matched. It can be Ingress, Egress, or Both.
Direction Direction `json:"direction"`
// The action that should be taken for the traffic. It can be Redirect or Mirror.
Action TrafficControlAction `json:"action"`
// The port to which the traffic should be redirected or mirrored.
TargetPort TrafficControlPort `json:"targetPort"`
// The port from which the traffic will be sent back to OVS. It should only be set for Redirect action.
ReturnPort *TrafficControlPort `json:"returnPort,omitempty"`
}
type Direction string
const (
DirectionIngress Direction = "Ingress"
DirectionEgress Direction = "Egress"
DirectionBoth Direction = "Both"
)
type TrafficControlAction string
const (
ActionRedirect TrafficControlAction = "Redirect"
ActionMirror TrafficControlAction = "Mirror"
)
// TrafficControlPort represents a port that can be used as the target of traffic mirroring or redirecting, and the
// return port of traffic redirecting.
type TrafficControlPort struct {
// OVSInternal represents an OVS internal port.
OVSInternal *OVSInternalPort `json:"ovsInternal,omitempty"`
// Device represents a network device.
Device *NetworkDevice `json:"device,omitempty"`
// GENEVE represents a GENEVE tunnel.
GENEVE *UDPTunnel `json:"geneve,omitempty"`
// VXLAN represents a VXLAN tunnel.
VXLAN *UDPTunnel `json:"vxlan,omitempty"`
// GRE represents a GRE tunnel.
GRE *GRETunnel `json:"gre,omitempty"`
// ERSPAN represents a ERSPAN tunnel.
ERSPAN *ERSPANTunnel `json:"erspan,omitempty"`
}
// OVSInternalPort represents an OVS internal port. Antrea will create the port if it doesn't exist.
type OVSInternalPort struct {
// The name of the OVS internal port.
Name string `json:"name"`
}
// NetworkDevice represents a network device. It must exist on all Nodes. Antrea will attach it to the OVS bridge if it
// is not attached.
type NetworkDevice struct {
// The name of the network device.
Name string `json:"name"`
}
// UDPTunnel represents a UDP based tunnel. Antrea will create a port on the OVS bridge for the tunnel.
type UDPTunnel struct {
// The remote IP of the tunnel.
RemoteIP string `json:"remoteIP"`
// The ID of the tunnel.
VNI *int32 `json:"vni,omitempty"`
// The transport layer destination port of the tunnel. If not specified, the assigned IANA port will be used, i.e.,
// 4789 for VXLAN, 6081 for GENEVE.
DestinationPort *int32 `json:"destinationPort,omitempty"`
}
// GRETunnel represents a GRE tunnel. Antrea will create a port on the OVS bridge for the tunnel.
type GRETunnel struct {
// The remote IP of the tunnel.
RemoteIP string `json:"remoteIP"`
// GRE key.
Key *int32 `json:"key,omitempty"`
}
// ERSPANTunnel represents an ERSPAN tunnel. Antrea will create a port on the OVS bridge for the tunnel.
type ERSPANTunnel struct {
// The remote IP of the tunnel.
RemoteIP string `json:"remoteIP"`
// ERSPAN session ID.
SessionID *int32 `json:"sessionID,omitempty"`
// ERSPAN version.
Version int32 `json:"version"`
// ERSPAN Index.
Index *int32 `json:"index,omitempty"`
// ERSPAN v2 mirrored traffic’s direction.
Dir *int32 `json:"dir,omitempty"`
// ERSPAN hardware ID.
HardwareID *int32 `json:"hardwareID,omitempty"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type TrafficControlList struct {
metav1.TypeMeta `json:",inline"`
// +optional
metav1.ListMeta `json:"metadata,omitempty"`
Items []TrafficControl `json:"items"`
}