|
| 1 | +// SPDX-FileCopyrightText: 2025 SAP SE or an SAP affiliate company and IronCore contributors |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +package v1alpha1 |
| 5 | + |
| 6 | +import ( |
| 7 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 8 | + |
| 9 | + "github.com/ironcore-dev/network-operator/api/core/v1alpha1" |
| 10 | +) |
| 11 | + |
| 12 | +// BorderGatewaySpec defines the desired state of BorderGateway |
| 13 | +type BorderGatewaySpec struct { |
| 14 | + // DeviceName is the name of the Device this object belongs to. The Device object must exist in the same namespace. |
| 15 | + // Immutable. |
| 16 | + // +required |
| 17 | + // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="DeviceRef is immutable" |
| 18 | + DeviceRef v1alpha1.LocalObjectReference `json:"deviceRef"` |
| 19 | + |
| 20 | + // MultisiteID is the identifier for the multisite border gateway. |
| 21 | + // +required |
| 22 | + // +kubebuilder:validation:Minimum=1 |
| 23 | + // +kubebuilder:validation:Maximum=281474976710655 |
| 24 | + // +kubebuilder:validation:ExclusiveMaximum=false |
| 25 | + MultisiteID int64 `json:"multisiteId"` |
| 26 | + |
| 27 | + // SourceInterfaceRef is a reference to the loopback interface used as the source for the |
| 28 | + // border gateway virtual IP address. A best practice is to use a separate loopback address |
| 29 | + // for the NVE source interface and multi-site source interface. The loopback interface must |
| 30 | + // be configured with a /32 IPv4 address. This /32 IP address needs be known by the transient |
| 31 | + // devices in the transport network and the remote VTEPs. |
| 32 | + // +required |
| 33 | + SourceInterfaceRef v1alpha1.LocalObjectReference `json:"sourceInterfaceRef"` |
| 34 | + |
| 35 | + // DelayRestoreTime specifies the time to wait before restoring EVPN multisite border gateway |
| 36 | + // functionality after a failure. This allows time for the network to stabilize before resuming |
| 37 | + // traffic forwarding across sites. |
| 38 | + // +optional |
| 39 | + // +kubebuilder:default="180s" |
| 40 | + // +kubebuilder:validation:Type=string |
| 41 | + // +kubebuilder:validation:Pattern="^([0-9]+(\\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$" |
| 42 | + DelayRestoreTime metav1.Duration `json:"delayRestoreTime"` |
| 43 | + |
| 44 | + // InterconnectInterfaceRefs is a list of interfaces that provide connectivity to the border gateway. |
| 45 | + // Each interface can be configured with object tracking to monitor its availability. |
| 46 | + // +optional |
| 47 | + // +listType=atomic |
| 48 | + // +kubebuilder:validation:MinItems=1 |
| 49 | + InterconnectInterfaceRefs []InterconnectInterfaceReference `json:"interconnectInterfaceRefs,omitempty"` |
| 50 | + |
| 51 | + // BGPPeerRefs is a list of BGP peers that are part of the border gateway configuration. |
| 52 | + // Each peer can be configured with a peer type to specify its role in the EVPN multisite topology. |
| 53 | + // +optional |
| 54 | + // +listType=atomic |
| 55 | + // +kubebuilder:validation:MinItems=1 |
| 56 | + BGPPeerRefs []BGPPeerReference `json:"bgpPeerRefs,omitempty"` |
| 57 | + |
| 58 | + // StormControl is the storm control configuration for the border gateway, allowing to rate-limit |
| 59 | + // BUM (Broadcast, Unknown unicast, Multicast) traffic on the border gateway interface. |
| 60 | + // +optional |
| 61 | + // +listType=map |
| 62 | + // +listMapKey=traffic |
| 63 | + // +kubebuilder:validation:MinItems=1 |
| 64 | + StormControl []StormControl `json:"stormControl,omitempty"` |
| 65 | +} |
| 66 | + |
| 67 | +// InterconnectInterfaceReference defines an interface used for border gateway interconnectivity |
| 68 | +// with optional object tracking configuration. |
| 69 | +type InterconnectInterfaceReference struct { |
| 70 | + v1alpha1.LocalObjectReference `json:",inline"` |
| 71 | + |
| 72 | + // Tracking specifies the EVPN multisite tracking mode for this interconnect interface. |
| 73 | + // DCI tracking is used for Data Center Interconnect interfaces, while Fabric tracking |
| 74 | + // is used for fabric-facing interfaces. |
| 75 | + // +required |
| 76 | + Tracking InterconnectTrackingType `json:"tracking"` |
| 77 | +} |
| 78 | + |
| 79 | +// InterconnectTrackingType defines the tracking mode for border gateway interconnect interfaces. |
| 80 | +// +kubebuilder:validation:Enum=DCI;Fabric |
| 81 | +type InterconnectTrackingType string |
| 82 | + |
| 83 | +const ( |
| 84 | + // InterconnectTrackingTypeDCI represents DCI (Data Center Interconnect) tracking mode. |
| 85 | + // Used for interfaces connecting to remote data centers. |
| 86 | + InterconnectTrackingTypeDCI InterconnectTrackingType = "DCI" |
| 87 | + |
| 88 | + // InterconnectTrackingTypeFabric represents Fabric tracking mode. |
| 89 | + // Used for interfaces connecting to the local fabric. |
| 90 | + InterconnectTrackingTypeFabric InterconnectTrackingType = "Fabric" |
| 91 | +) |
| 92 | + |
| 93 | +// BGPPeerReference defines a BGP peer used for border gateway with peer type configuration. |
| 94 | +type BGPPeerReference struct { |
| 95 | + v1alpha1.LocalObjectReference `json:",inline"` |
| 96 | + |
| 97 | + // PeerType specifies the role of this BGP peer in the EVPN multisite topology. |
| 98 | + // FabricExternal is used for peers outside the fabric, while FabricBorderLeaf is used |
| 99 | + // for border leaf peers within the fabric. |
| 100 | + // +required |
| 101 | + PeerType BGPPeerType `json:"peerType,omitempty"` |
| 102 | +} |
| 103 | + |
| 104 | +// BGPPeerType defines the peer type for border gateway BGP peers. |
| 105 | +// +kubebuilder:validation:Enum=FabricExternal;FabricBorderLeaf |
| 106 | +type BGPPeerType string |
| 107 | + |
| 108 | +const ( |
| 109 | + // BGPPeerTypeFabricExternal represents a BGP peer outside the fabric. |
| 110 | + // Used for external peers in EVPN multisite configurations. |
| 111 | + BGPPeerTypeFabricExternal BGPPeerType = "FabricExternal" |
| 112 | + |
| 113 | + // BGPPeerTypeFabricBorderLeaf represents a BGP peer that is a border leaf within the fabric. |
| 114 | + // Used for border leaf peers in EVPN multisite configurations. |
| 115 | + BGPPeerTypeFabricBorderLeaf BGPPeerType = "FabricBorderLeaf" |
| 116 | +) |
| 117 | + |
| 118 | +type StormControl struct { |
| 119 | + // Level is the suppression level as a percentage of the interface bandwidth. |
| 120 | + // Must be a floating point number between 1.0 and 100.0. |
| 121 | + // +required |
| 122 | + // +kubebuilder:validation:Pattern=`^([1-9][0-9]?(\.[0-9]+)?|100(\.0+)?)$` |
| 123 | + Level string `json:"level"` |
| 124 | + |
| 125 | + // Traffic specifies the type of BUM traffic the storm control applies to. |
| 126 | + // +required |
| 127 | + Traffic TrafficType `json:"traffic"` |
| 128 | +} |
| 129 | + |
| 130 | +// TrafficType defines the type of traffic for storm control. |
| 131 | +// +kubebuilder:validation:Enum=Broadcast;Multicast;Unicast |
| 132 | +type TrafficType string |
| 133 | + |
| 134 | +const ( |
| 135 | + // TrafficTypeBroadcast represents broadcast traffic. |
| 136 | + TrafficTypeBroadcast TrafficType = "Broadcast" |
| 137 | + // TrafficTypeMulticast represents multicast traffic. |
| 138 | + TrafficTypeMulticast TrafficType = "Multicast" |
| 139 | + // TrafficTypeUnicast represents unicast traffic. |
| 140 | + TrafficTypeUnicast TrafficType = "Unicast" |
| 141 | +) |
| 142 | + |
| 143 | +// BorderGatewayStatus defines the observed state of BorderGateway. |
| 144 | +type BorderGatewayStatus struct { |
| 145 | + // The conditions are a list of status objects that describe the state of the Banner. |
| 146 | + //+listType=map |
| 147 | + //+listMapKey=type |
| 148 | + //+patchStrategy=merge |
| 149 | + //+patchMergeKey=type |
| 150 | + //+optional |
| 151 | + Conditions []metav1.Condition `json:"conditions,omitempty"` |
| 152 | +} |
| 153 | + |
| 154 | +// +kubebuilder:object:root=true |
| 155 | +// +kubebuilder:subresource:status |
| 156 | +// +kubebuilder:resource:path=bordergateways |
| 157 | +// +kubebuilder:resource:singular=bordergateway |
| 158 | +// +kubebuilder:resource:shortName=bgw |
| 159 | +// +kubebuilder:printcolumn:name="Device",type=string,JSONPath=`.spec.deviceRef.name` |
| 160 | +// +kubebuilder:printcolumn:name="Ready",type=string,JSONPath=`.status.conditions[?(@.type=="Ready")].status` |
| 161 | +// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp" |
| 162 | + |
| 163 | +// BorderGateway is the Schema for the bordergateways API |
| 164 | +type BorderGateway struct { |
| 165 | + metav1.TypeMeta `json:",inline"` |
| 166 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 167 | + |
| 168 | + // Specification of the desired state of the resource. |
| 169 | + // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status |
| 170 | + // +required |
| 171 | + Spec BorderGatewaySpec `json:"spec,omitempty"` |
| 172 | + |
| 173 | + // Status of the resource. This is set and updated automatically. |
| 174 | + // Read-only. |
| 175 | + // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status |
| 176 | + // +optional |
| 177 | + Status BorderGatewayStatus `json:"status,omitempty,omitzero"` |
| 178 | +} |
| 179 | + |
| 180 | +// GetConditions implements conditions.Getter. |
| 181 | +func (bgw *BorderGateway) GetConditions() []metav1.Condition { |
| 182 | + return bgw.Status.Conditions |
| 183 | +} |
| 184 | + |
| 185 | +// SetConditions implements conditions.Setter. |
| 186 | +func (bgw *BorderGateway) SetConditions(conditions []metav1.Condition) { |
| 187 | + bgw.Status.Conditions = conditions |
| 188 | +} |
| 189 | + |
| 190 | +// +kubebuilder:object:root=true |
| 191 | + |
| 192 | +// BorderGatewayList contains a list of BorderGateway |
| 193 | +type BorderGatewayList struct { |
| 194 | + metav1.TypeMeta `json:",inline"` |
| 195 | + metav1.ListMeta `json:"metadata,omitzero"` |
| 196 | + Items []BorderGateway `json:"items"` |
| 197 | +} |
| 198 | + |
| 199 | +func init() { |
| 200 | + SchemeBuilder.Register(&BorderGateway{}, &BorderGatewayList{}) |
| 201 | +} |
0 commit comments