Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 8 additions & 0 deletions api/core/v1alpha1/bgp_peer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
)

// BGPPeerSpec defines the desired state of BGPPeer
// +kubebuilder:validation:XValidation:rule="!(has(self.localAS) && has(self.localASNumber))",message="localAS and localASNumber are mutually exclusive"
type BGPPeerSpec struct {
// DeviceName is the name of the Device this object belongs to. The Device object must exist in the same namespace.
// Immutable.
Expand Down Expand Up @@ -61,6 +62,13 @@ type BGPPeerSpec struct {
// +optional
AddressFamilies *BGPPeerAddressFamilies `json:"addressFamilies,omitempty"`

// LocalASNumber specifies a local AS number to present to the BGP peer.
// When set, it is equivalent to LocalAS with ASNumber set and PrependLocalAS/PrependGlobalAS defaults.
//
// Deprecated: Use LocalAS.ASNumber instead. This field will be removed in a future release.
// +optional
LocalASNumber *intstr.IntOrString `json:"localASNumber,omitempty"`

// LocalAS configures the local AS number and how it factors into BGP announcements for this peer.
// +optional
LocalAS *LocalAS `json:"localAS,omitempty"`
Expand Down
5 changes: 5 additions & 0 deletions api/core/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions config/crd/bases/networking.metal.ironcore.dev_bgppeers.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/api-reference/index.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions internal/controller/core/bgp_peer_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,16 @@ func (r *BGPPeerReconciler) reconcile(ctx context.Context, s *bgpPeerScope) (ret
sourceInterface = intf.Spec.Name
}

// TODO: remove use of deprecated LocalASNumber field in a future release.
//nolint:staticcheck // handling deprecated field for backward compatibility
if s.BGPPeer.Spec.LocalASNumber != nil {
s.BGPPeer.Spec.LocalAS = &v1alpha1.LocalAS{
ASNumber: *s.BGPPeer.Spec.LocalASNumber, //nolint:staticcheck
PrependLocalAS: new(bool),
PrependGlobalAS: new(bool),
}
}

if s.BGPPeer.Spec.LocalAS != nil && s.BGPPeer.Spec.ASNumber.String() == bgp.Spec.ASNumber.String() {
conditions.Set(s.BGPPeer, metav1.Condition{
Type: v1alpha1.ConfiguredCondition,
Expand Down
20 changes: 18 additions & 2 deletions internal/webhook/core/v1alpha1/bgppeer_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,23 @@ var _ admission.Validator[*v1alpha1.BGPPeer] = &BGPPeerCustomValidator{}
func (v *BGPPeerCustomValidator) ValidateCreate(_ context.Context, bgppeer *v1alpha1.BGPPeer) (admission.Warnings, error) {
bgppeerlog.Info("Validation for BGPPeer upon creation", "name", bgppeer.GetName())

return nil, validateBGPPeer(bgppeer.Spec)
var warnings admission.Warnings
if bgppeer.Spec.LocalASNumber != nil { //nolint:staticcheck
warnings = append(warnings, "spec.localASNumber is deprecated; use spec.localAS.asNumber instead")
}

return warnings, validateBGPPeer(bgppeer.Spec)
}

// ValidateUpdate implements admission.Validator so a webhook will be registered for the type BGPPeer.
func (v *BGPPeerCustomValidator) ValidateUpdate(_ context.Context, _, bgppeer *v1alpha1.BGPPeer) (admission.Warnings, error) {
bgppeerlog.Info("Validation for BGPPeer upon update", "name", bgppeer.GetName())

return nil, validateBGPPeer(bgppeer.Spec)
var warnings admission.Warnings
if bgppeer.Spec.LocalASNumber != nil { //nolint:staticcheck
warnings = append(warnings, "spec.localASNumber is deprecated; use spec.localAS.asNumber instead")
}
return warnings, validateBGPPeer(bgppeer.Spec)
}

// ValidateDelete implements admission.Validator so a webhook will be registered for the type BGPPeer.
Expand All @@ -60,5 +69,12 @@ func validateBGPPeer(bgppeer v1alpha1.BGPPeerSpec) error {
return err
}
}
// TODO: Remove when LocalASNumber is removed from the spec.
if bgppeer.LocalASNumber != nil { //nolint:staticcheck
if err := validateASNumber(*bgppeer.LocalASNumber); err != nil { //nolint:staticcheck
return err
}
}

return nil
}
Loading
Loading