Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions api/external/go.universe.tf/metallb/api/v1beta1/bfdprofile_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
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 v1beta1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// BFDProfileSpec defines the desired state of BFDProfile.
type BFDProfileSpec struct {
// The minimum interval that this system is capable of
// receiving control packets in milliseconds.
// Defaults to 300ms.
// +kubebuilder:validation:Maximum:=60000
// +kubebuilder:validation:Minimum:=10
// +optional
ReceiveInterval *uint32 `json:"receiveInterval,omitempty"`
// The minimum transmission interval (less jitter)
// that this system wants to use to send BFD control packets in
// milliseconds. Defaults to 300ms
// +kubebuilder:validation:Maximum:=60000
// +kubebuilder:validation:Minimum:=10
// +optional
TransmitInterval *uint32 `json:"transmitInterval,omitempty"`
// Configures the detection multiplier to determine
// packet loss. The remote transmission interval will be multiplied
// by this value to determine the connection loss detection timer.
// +kubebuilder:validation:Maximum:=255
// +kubebuilder:validation:Minimum:=2
// +optional
DetectMultiplier *uint32 `json:"detectMultiplier,omitempty"`
// Configures the minimal echo receive transmission
// interval that this system is capable of handling in milliseconds.
// Defaults to 50ms
// +kubebuilder:validation:Maximum:=60000
// +kubebuilder:validation:Minimum:=10
// +optional
EchoInterval *uint32 `json:"echoInterval,omitempty"`
// Enables or disables the echo transmission mode.
// This mode is disabled by default, and not supported on multi
// hops setups.
// +optional
EchoMode *bool `json:"echoMode,omitempty"`
// Mark session as passive: a passive session will not
// attempt to start the connection and will wait for control packets
// from peer before it begins replying.
// +optional
PassiveMode *bool `json:"passiveMode,omitempty"`
// For multi hop sessions only: configure the minimum
// expected TTL for an incoming BFD control packet.
// +kubebuilder:validation:Maximum:=254
// +kubebuilder:validation:Minimum:=1
// +optional
MinimumTTL *uint32 `json:"minimumTtl,omitempty"`
}

// BFDProfileStatus defines the observed state of BFDProfile.
type BFDProfileStatus struct {
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:printcolumn:name="Passive Mode",type=boolean,JSONPath=`.spec.passiveMode`
//+kubebuilder:printcolumn:name="Transmit Interval",type=integer,JSONPath=`.spec.transmitInterval`
//+kubebuilder:printcolumn:name="Receive Interval",type=integer,JSONPath=`.spec.receiveInterval`
//+kubebuilder:printcolumn:name="Multiplier",type=integer,JSONPath=`.spec.detectMultiplier`

// BFDProfile represents the settings of the bfd session that can be
// optionally associated with a BGP session.
type BFDProfile struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec BFDProfileSpec `json:"spec,omitempty"`
Status BFDProfileStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// BFDProfileList contains a list of BFDProfile.
type BFDProfileList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []BFDProfile `json:"items"`
}

func init() {
SchemeBuilder.Register(&BFDProfile{}, &BFDProfileList{})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
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 v1beta1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// BGPAdvertisementSpec defines the desired state of BGPAdvertisement.
type BGPAdvertisementSpec struct {
// The aggregation-length advertisement option lets you “roll up” the /32s into a larger prefix. Defaults to 32. Works for IPv4 addresses.
// +kubebuilder:validation:Minimum=1
// +kubebuilder:default:=32
// +optional
AggregationLength *int32 `json:"aggregationLength,omitempty"`

// The aggregation-length advertisement option lets you “roll up” the /128s into a larger prefix. Defaults to 128. Works for IPv6 addresses.
// +kubebuilder:default:=128
// +optional
AggregationLengthV6 *int32 `json:"aggregationLengthV6,omitempty"`

// The BGP LOCAL_PREF attribute which is used by BGP best path algorithm,
// Path with higher localpref is preferred over one with lower localpref.
// +optional
LocalPref uint32 `json:"localPref,omitempty"`

// The BGP communities to be associated with the announcement. Each item can be a standard community of the
// form 1234:1234, a large community of the form large:1234:1234:1234 or the name of an alias defined in the
// Community CRD.
// +optional
Communities []string `json:"communities,omitempty"`

// The list of IPAddressPools to advertise via this advertisement, selected by name.
// +optional
IPAddressPools []string `json:"ipAddressPools,omitempty"`

// A selector for the IPAddressPools which would get advertised via this advertisement.
// If no IPAddressPool is selected by this or by the list, the advertisement is applied to all the IPAddressPools.
// +optional
IPAddressPoolSelectors []metav1.LabelSelector `json:"ipAddressPoolSelectors,omitempty"`

// NodeSelectors allows to limit the nodes to announce as next hops for the LoadBalancer IP. When empty, all the nodes having are announced as next hops.
// +optional
NodeSelectors []metav1.LabelSelector `json:"nodeSelectors,omitempty"`

// Peers limits the bgppeer to advertise the ips of the selected pools to.
// When empty, the loadbalancer IP is announced to all the BGPPeers configured.
// +optional
Peers []string `json:"peers,omitempty"`
}

// BGPAdvertisementStatus defines the observed state of BGPAdvertisement.
type BGPAdvertisementStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:printcolumn:name="IPAddressPools",type=string,JSONPath=`.spec.ipAddressPools`
//+kubebuilder:printcolumn:name="IPAddressPool Selectors",type=string,JSONPath=`.spec.ipAddressPoolSelectors`
//+kubebuilder:printcolumn:name="Peers",type=string,JSONPath=`.spec.peers`
//+kubebuilder:printcolumn:name="Node Selectors",type=string,JSONPath=`.spec.nodeSelectors`,priority=10

// BGPAdvertisement allows to advertise the IPs coming
// from the selected IPAddressPools via BGP, setting the parameters of the
// BGP Advertisement.
type BGPAdvertisement struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec BGPAdvertisementSpec `json:"spec,omitempty"`
Status BGPAdvertisementStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// BGPAdvertisementList contains a list of BGPAdvertisement.
type BGPAdvertisementList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []BGPAdvertisement `json:"items"`
}

func init() {
SchemeBuilder.Register(&BGPAdvertisement{}, &BGPAdvertisementList{})
}
108 changes: 108 additions & 0 deletions api/external/go.universe.tf/metallb/api/v1beta1/bgppeer_conversion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// SPDX-License-Identifier:Apache-2.0

package v1beta1

import (
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/external/go.universe.tf/metallb/api/v1beta2"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/conversion"
)

// ConvertTo converts this BGPPeer to the Hub version (v1beta2).
func (src *BGPPeer) ConvertTo(dstRaw conversion.Hub) error {
dst := dstRaw.(*v1beta2.BGPPeer)
dst.Spec.ASN = src.Spec.ASN
dst.Spec.MyASN = src.Spec.MyASN
dst.Spec.Address = src.Spec.Address
dst.Spec.SrcAddress = src.Spec.SrcAddress
dst.Spec.Port = src.Spec.Port
dst.Spec.HoldTime = &src.Spec.HoldTime
dst.Spec.KeepaliveTime = &src.Spec.KeepaliveTime
dst.Spec.RouterID = src.Spec.RouterID
dst.Spec.Password = src.Spec.Password
dst.Spec.BFDProfile = src.Spec.BFDProfile
dst.Spec.EBGPMultiHop = src.Spec.EBGPMultiHop
dst.Spec.NodeSelectors = parseNodeSelectors(src.Spec.NodeSelectors)
dst.ObjectMeta = src.ObjectMeta
return nil
}

// ConvertFrom converts from the Hub version (v1beta2) to this version.
func (dst *BGPPeer) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*v1beta2.BGPPeer)
var ht metav1.Duration
if src.Spec.HoldTime != nil {
ht = *src.Spec.HoldTime
}
var ka metav1.Duration
if src.Spec.KeepaliveTime != nil {
ka = *src.Spec.KeepaliveTime
}
dst.ObjectMeta = src.ObjectMeta
dst.Spec.MyASN = src.Spec.MyASN
dst.Spec.ASN = src.Spec.ASN
dst.Spec.Address = src.Spec.Address
dst.Spec.SrcAddress = src.Spec.SrcAddress
dst.Spec.Port = src.Spec.Port
dst.Spec.HoldTime = ht
dst.Spec.KeepaliveTime = ka
dst.Spec.RouterID = src.Spec.RouterID
dst.Spec.Password = src.Spec.Password
dst.Spec.BFDProfile = src.Spec.BFDProfile
dst.Spec.EBGPMultiHop = src.Spec.EBGPMultiHop
dst.Spec.NodeSelectors = labelsToLegacySelector(src.Spec.NodeSelectors)
return nil
}

func parseNodeSelectors(selectors []NodeSelector) []metav1.LabelSelector {
var nodeSels []metav1.LabelSelector
for _, sel := range selectors {
nodeSels = append(nodeSels, parseNodeSelector(sel))
}
return nodeSels
}

func parseNodeSelector(ns NodeSelector) metav1.LabelSelector {
if len(ns.MatchLabels)+len(ns.MatchExpressions) == 0 {
return metav1.LabelSelector{}
}

sel := metav1.LabelSelector{
MatchLabels: make(map[string]string),
}
for k, v := range ns.MatchLabels {
sel.MatchLabels[k] = v
}
for _, req := range ns.MatchExpressions {
sel.MatchExpressions = append(sel.MatchExpressions, metav1.LabelSelectorRequirement{
Key: req.Key,
Operator: metav1.LabelSelectorOperator(req.Operator),
Values: req.Values,
})
}
return sel
}

func labelsToLegacySelector(selectors []metav1.LabelSelector) []NodeSelector {
res := []NodeSelector{}
for _, sel := range selectors {
toAdd := NodeSelector{
MatchLabels: make(map[string]string),
MatchExpressions: make([]MatchExpression, 0),
}
for k, v := range sel.MatchLabels {
toAdd.MatchLabels[k] = v
}
for _, e := range sel.MatchExpressions {
m := MatchExpression{
Key: e.Key,
Operator: string(e.Operator),
Values: make([]string, len(e.Values)),
}
copy(m.Values, e.Values)
toAdd.MatchExpressions = append(toAdd.MatchExpressions, m)
}
res = append(res, toAdd)
}
return res
}
Loading
Loading