github.com/tigera/api@v0.0.0-20240320170621-278e89a8c5fb/pkg/apis/projectcalico/v3/bgpconfig.go (about)

     1  // Copyright (c) 2020-2021 Tigera, Inc. All rights reserved.
     2  
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package v3
    16  
    17  import (
    18  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    19  
    20  	"github.com/tigera/api/pkg/lib/numorstring"
    21  )
    22  
    23  const (
    24  	KindBGPConfiguration     = "BGPConfiguration"
    25  	KindBGPConfigurationList = "BGPConfigurationList"
    26  )
    27  
    28  type BindMode string
    29  
    30  const (
    31  	BindModeNone   BindMode = "None"
    32  	BindModeNodeIP BindMode = "NodeIP"
    33  )
    34  
    35  // +genclient:nonNamespaced
    36  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
    37  
    38  // BGPConfigurationList is a list of BGPConfiguration resources.
    39  type BGPConfigurationList struct {
    40  	metav1.TypeMeta `json:",inline"`
    41  	metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
    42  
    43  	Items []BGPConfiguration `json:"items" protobuf:"bytes,2,rep,name=items"`
    44  }
    45  
    46  // +genclient
    47  // +genclient:nonNamespaced
    48  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
    49  
    50  type BGPConfiguration struct {
    51  	metav1.TypeMeta   `json:",inline"`
    52  	metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
    53  
    54  	Spec BGPConfigurationSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`
    55  }
    56  
    57  // BGPConfigurationSpec contains the values of the BGP configuration.
    58  type BGPConfigurationSpec struct {
    59  	// LogSeverityScreen is the log severity above which logs are sent to the stdout. [Default: INFO]
    60  	LogSeverityScreen string `json:"logSeverityScreen,omitempty" validate:"omitempty,logLevel" confignamev1:"loglevel"`
    61  
    62  	// NodeToNodeMeshEnabled sets whether full node to node BGP mesh is enabled. [Default: true]
    63  	NodeToNodeMeshEnabled *bool `json:"nodeToNodeMeshEnabled,omitempty" validate:"omitempty" confignamev1:"node_mesh"`
    64  
    65  	// ASNumber is the default AS number used by a node. [Default: 64512]
    66  	ASNumber *numorstring.ASNumber `json:"asNumber,omitempty" validate:"omitempty" confignamev1:"as_num"`
    67  
    68  	// Extensions is a mapping of keys to values that can be used in custom BGP templates
    69  	Extensions map[string]string `json:"extensions,omitempty" validate:"omitempty" confignamev1:"extensions"`
    70  
    71  	// ServiceLoadBalancerIPs are the CIDR blocks for Kubernetes Service LoadBalancer IPs.
    72  	// Kubernetes Service status.LoadBalancer.Ingress IPs will only be advertised if they are within one of these blocks.
    73  	ServiceLoadBalancerIPs []ServiceLoadBalancerIPBlock `json:"serviceLoadBalancerIPs,omitempty" validate:"omitempty,dive" confignamev1:"svc_loadbalancer_ips"`
    74  
    75  	// ServiceExternalIPs are the CIDR blocks for Kubernetes Service External IPs.
    76  	// Kubernetes Service ExternalIPs will only be advertised if they are within one of these blocks.
    77  	ServiceExternalIPs []ServiceExternalIPBlock `json:"serviceExternalIPs,omitempty" validate:"omitempty,dive" confignamev1:"svc_external_ips"`
    78  
    79  	// ServiceClusterIPs are the CIDR blocks from which service cluster IPs are allocated.
    80  	// If specified, Calico will advertise these blocks, as well as any cluster IPs within them.
    81  	ServiceClusterIPs []ServiceClusterIPBlock `json:"serviceClusterIPs,omitempty" validate:"omitempty,dive" confignamev1:"svc_cluster_ips"`
    82  
    83  	// Communities is a list of BGP community values and their arbitrary names for tagging routes.
    84  	Communities []Community `json:"communities,omitempty" validate:"omitempty,dive" confignamev1:"communities"`
    85  
    86  	// PrefixAdvertisements contains per-prefix advertisement configuration.
    87  	PrefixAdvertisements []PrefixAdvertisement `json:"prefixAdvertisements,omitempty" validate:"omitempty,dive" confignamev1:"prefix_advertisements"`
    88  
    89  	// ListenPort is the port where BGP protocol should listen. Defaults to 179
    90  	// +kubebuilder:validation:Minimum:=1
    91  	// +kubebuilder:validation:Maximum:=65535
    92  	ListenPort uint16 `json:"listenPort,omitempty" validate:"omitempty,gt=0" confignamev1:"listen_port"`
    93  
    94  	// Optional BGP password for full node-to-mesh peerings.
    95  	// This field can only be set on the default BGPConfiguration instance and requires that NodeMesh is enabled
    96  	// +optional
    97  	NodeMeshPassword *BGPPassword `json:"nodeMeshPassword,omitempty" validate:"omitempty" confignamev1:"node_mesh_password"`
    98  
    99  	// Time to allow for software restart for node-to-mesh peerings.  When specified, this is configured
   100  	// as the graceful restart timeout.  When not specified, the BIRD default of 120s is used.
   101  	// This field can only be set on the default BGPConfiguration instance and requires that NodeMesh is enabled
   102  	// +optional
   103  	NodeMeshMaxRestartTime *metav1.Duration `json:"nodeMeshMaxRestartTime,omitempty" confignamev1:"node_mesh_restart_time"`
   104  
   105  	// BindMode indicates whether to listen for BGP connections on all addresses (None)
   106  	// or only on the node's canonical IP address Node.Spec.BGP.IPvXAddress (NodeIP).
   107  	// Default behaviour is to listen for BGP connections on all addresses.
   108  	// +optional
   109  	BindMode *BindMode `json:"bindMode,omitempty"`
   110  
   111  	// IgnoredInterfaces indicates the network interfaces that needs to be excluded when reading device routes.
   112  	// +optional
   113  	IgnoredInterfaces []string `json:"ignoredInterfaces,omitempty" validate:"omitempty,dive,ignoredInterface"`
   114  }
   115  
   116  // ServiceLoadBalancerIPBlock represents a single allowed LoadBalancer IP CIDR block.
   117  type ServiceLoadBalancerIPBlock struct {
   118  	CIDR string `json:"cidr,omitempty" validate:"omitempty,net"`
   119  }
   120  
   121  // ServiceExternalIPBlock represents a single allowed External IP CIDR block.
   122  type ServiceExternalIPBlock struct {
   123  	CIDR string `json:"cidr,omitempty" validate:"omitempty,net"`
   124  }
   125  
   126  // ServiceClusterIPBlock represents a single allowed ClusterIP CIDR block.
   127  type ServiceClusterIPBlock struct {
   128  	CIDR string `json:"cidr,omitempty" validate:"omitempty,net"`
   129  }
   130  
   131  // Community contains standard or large community value and its name.
   132  type Community struct {
   133  	// Name given to community value.
   134  	Name string `json:"name,omitempty" validate:"required,name"`
   135  	// Value must be of format `aa:nn` or `aa:nn:mm`.
   136  	// For standard community use `aa:nn` format, where `aa` and `nn` are 16 bit number.
   137  	// For large community use `aa:nn:mm` format, where `aa`, `nn` and `mm` are 32 bit number.
   138  	// Where, `aa` is an AS Number, `nn` and `mm` are per-AS identifier.
   139  	// +kubebuilder:validation:Pattern=`^(\d+):(\d+)$|^(\d+):(\d+):(\d+)$`
   140  	Value string `json:"value,omitempty" validate:"required"`
   141  }
   142  
   143  // PrefixAdvertisement configures advertisement properties for the specified CIDR.
   144  type PrefixAdvertisement struct {
   145  	// CIDR for which properties should be advertised.
   146  	CIDR string `json:"cidr,omitempty" validate:"required,net"`
   147  	// Communities can be list of either community names already defined in `Specs.Communities` or community value of format `aa:nn` or `aa:nn:mm`.
   148  	// For standard community use `aa:nn` format, where `aa` and `nn` are 16 bit number.
   149  	// For large community use `aa:nn:mm` format, where `aa`, `nn` and `mm` are 32 bit number.
   150  	// Where,`aa` is an AS Number, `nn` and `mm` are per-AS identifier.
   151  	Communities []string `json:"communities,omitempty" validate:"required"`
   152  }
   153  
   154  // New BGPConfiguration creates a new (zeroed) BGPConfiguration struct with the TypeMetadata
   155  // initialized to the current version.
   156  func NewBGPConfiguration() *BGPConfiguration {
   157  	return &BGPConfiguration{
   158  		TypeMeta: metav1.TypeMeta{
   159  			Kind:       KindBGPConfiguration,
   160  			APIVersion: GroupVersionCurrent,
   161  		},
   162  	}
   163  }