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

     1  // Copyright (c) 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  
    21  const (
    22  	KindCalicoNodeStatus     = "CalicoNodeStatus"
    23  	KindCalicoNodeStatusList = "CalicoNodeStatusList"
    24  )
    25  
    26  // +genclient:nonNamespaced
    27  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
    28  
    29  // CalicoNodeStatusList is a list of CalicoNodeStatus resources.
    30  type CalicoNodeStatusList struct {
    31  	metav1.TypeMeta `json:",inline"`
    32  	metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
    33  
    34  	Items []CalicoNodeStatus `json:"items" protobuf:"bytes,2,rep,name=items"`
    35  }
    36  
    37  // +genclient
    38  // +genclient:nonNamespaced
    39  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
    40  
    41  type CalicoNodeStatus struct {
    42  	metav1.TypeMeta   `json:",inline"`
    43  	metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
    44  
    45  	Spec   CalicoNodeStatusSpec   `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`
    46  	Status CalicoNodeStatusStatus `json:"status,omitempty" protobuf:"bytes,2,opt,name=status"`
    47  }
    48  
    49  // CalicoNodeStatusSpec contains the specification for a CalicoNodeStatus resource.
    50  type CalicoNodeStatusSpec struct {
    51  	// The node name identifies the Calico node instance for node status.
    52  	Node string `json:"node,omitempty" validate:"required,name"`
    53  
    54  	// Classes declares the types of information to monitor for this calico/node,
    55  	// and allows for selective status reporting about certain subsets of information.
    56  	Classes []NodeStatusClassType `json:"classes,omitempty" validate:"required,unique"`
    57  
    58  	// UpdatePeriodSeconds is the period at which CalicoNodeStatus should be updated.
    59  	// Set to 0 to disable CalicoNodeStatus refresh. Maximum update period is one day.
    60  	UpdatePeriodSeconds *uint32 `json:"updatePeriodSeconds,omitempty" validate:"required,gte=0,lte=86400"`
    61  }
    62  
    63  // CalicoNodeStatusStatus defines the observed state of CalicoNodeStatus.
    64  // No validation needed for status since it is updated by Calico.
    65  type CalicoNodeStatusStatus struct {
    66  	// LastUpdated is a timestamp representing the server time when CalicoNodeStatus object
    67  	// last updated. It is represented in RFC3339 form and is in UTC.
    68  	// +nullable
    69  	LastUpdated metav1.Time `json:"lastUpdated,omitempty"`
    70  
    71  	// Agent holds agent status on the node.
    72  	Agent CalicoNodeAgentStatus `json:"agent,omitempty"`
    73  
    74  	// BGP holds node BGP status.
    75  	BGP CalicoNodeBGPStatus `json:"bgp,omitempty"`
    76  
    77  	// Routes reports routes known to the Calico BGP daemon on the node.
    78  	Routes CalicoNodeBGPRouteStatus `json:"routes,omitempty"`
    79  }
    80  
    81  // CalicoNodeAgentStatus defines the observed state of agent status on the node.
    82  type CalicoNodeAgentStatus struct {
    83  	// BIRDV4 represents the latest observed status of bird4.
    84  	BIRDV4 BGPDaemonStatus `json:"birdV4,omitempty"`
    85  
    86  	// BIRDV6 represents the latest observed status of bird6.
    87  	BIRDV6 BGPDaemonStatus `json:"birdV6,omitempty"`
    88  }
    89  
    90  // CalicoNodeBGPStatus defines the observed state of BGP status on the node.
    91  type CalicoNodeBGPStatus struct {
    92  	// The total number of IPv4 established bgp sessions.
    93  	NumberEstablishedV4 int `json:"numberEstablishedV4"`
    94  
    95  	// The total number of IPv4 non-established bgp sessions.
    96  	NumberNotEstablishedV4 int `json:"numberNotEstablishedV4"`
    97  
    98  	// The total number of IPv6 established bgp sessions.
    99  	NumberEstablishedV6 int `json:"numberEstablishedV6"`
   100  
   101  	// The total number of IPv6 non-established bgp sessions.
   102  	NumberNotEstablishedV6 int `json:"numberNotEstablishedV6"`
   103  
   104  	// PeersV4 represents IPv4 BGP peers status on the node.
   105  	PeersV4 []CalicoNodePeer `json:"peersV4,omitempty"`
   106  
   107  	// PeersV6 represents IPv6 BGP peers status on the node.
   108  	PeersV6 []CalicoNodePeer `json:"peersV6,omitempty"`
   109  }
   110  
   111  // CalicoNodeBGPRouteStatus defines the observed state of routes status on the node.
   112  type CalicoNodeBGPRouteStatus struct {
   113  	// RoutesV4 represents IPv4 routes on the node.
   114  	RoutesV4 []CalicoNodeRoute `json:"routesV4,omitempty"`
   115  
   116  	// RoutesV6 represents IPv6 routes on the node.
   117  	RoutesV6 []CalicoNodeRoute `json:"routesV6,omitempty"`
   118  }
   119  
   120  // BGPDaemonStatus defines the observed state of BGP daemon.
   121  type BGPDaemonStatus struct {
   122  	// The state of the BGP Daemon.
   123  	State BGPDaemonState `json:"state,omitempty"`
   124  
   125  	// Version of the BGP daemon
   126  	Version string `json:"version,omitempty"`
   127  
   128  	// Router ID used by bird.
   129  	RouterID string `json:"routerID,omitempty"`
   130  
   131  	// LastBootTime holds the value of lastBootTime from bird.ctl output.
   132  	LastBootTime string `json:"lastBootTime,omitempty"`
   133  
   134  	// LastReconfigurationTime holds the value of lastReconfigTime from bird.ctl output.
   135  	LastReconfigurationTime string `json:"lastReconfigurationTime,omitempty"`
   136  }
   137  
   138  // CalicoNodePeer contains the status of BGP peers on the node.
   139  type CalicoNodePeer struct {
   140  	// IP address of the peer whose condition we are reporting.
   141  	PeerIP string `json:"peerIP,omitempty" validate:"omitempty,ip"`
   142  
   143  	// Type indicates whether this peer is configured via the node-to-node mesh,
   144  	// or via en explicit global or per-node BGPPeer object.
   145  	Type BGPPeerType `json:"type,omitempty"`
   146  
   147  	// State is the BGP session state.
   148  	State BGPSessionState `json:"state,omitempty"`
   149  
   150  	// Since the state or reason last changed.
   151  	Since string `json:"since,omitempty"`
   152  }
   153  
   154  // CalicoNodeRoute contains the status of BGP routes on the node.
   155  type CalicoNodeRoute struct {
   156  	// Type indicates if the route is being used for forwarding or not.
   157  	Type CalicoNodeRouteType `json:"type,omitempty"`
   158  
   159  	// Destination of the route.
   160  	Destination string `json:"destination,omitempty"`
   161  
   162  	// Gateway for the destination.
   163  	Gateway string `json:"gateway,omitempty"`
   164  
   165  	// Interface for the destination
   166  	Interface string `json:"interface,omitempty"`
   167  
   168  	// LearnedFrom contains information regarding where this route originated.
   169  	LearnedFrom CalicoNodeRouteLearnedFrom `json:"learnedFrom,omitempty"`
   170  }
   171  
   172  // CalicoNodeRouteLearnedFrom contains the information of the source from which a routes has been learned.
   173  type CalicoNodeRouteLearnedFrom struct {
   174  	// Type of the source where a route is learned from.
   175  	SourceType CalicoNodeRouteSourceType `json:"sourceType,omitempty"`
   176  
   177  	// If sourceType is NodeMesh or BGPPeer, IP address of the router that sent us this route.
   178  	PeerIP string `json:"peerIP,omitempty" validate:"omitempty,ip"`
   179  }
   180  
   181  // NewCalicoNodeStatus creates a new (zeroed) CalicoNodeStatus struct with the TypeMetadata initialised to the current
   182  // version.
   183  func NewCalicoNodeStatus() *CalicoNodeStatus {
   184  	return &CalicoNodeStatus{
   185  		TypeMeta: metav1.TypeMeta{
   186  			Kind:       KindCalicoNodeStatus,
   187  			APIVersion: GroupVersionCurrent,
   188  		},
   189  	}
   190  }
   191  
   192  type CalicoNodeRouteType string
   193  
   194  const (
   195  	RouteTypeFIB CalicoNodeRouteType = "FIB"
   196  	RouteTypeRIB CalicoNodeRouteType = "RIB"
   197  )
   198  
   199  type CalicoNodeRouteSourceType string
   200  
   201  const (
   202  	RouteSourceTypeKernel   CalicoNodeRouteSourceType = "Kernel"
   203  	RouteSourceTypeStatic   CalicoNodeRouteSourceType = "Static"
   204  	RouteSourceTypeDirect   CalicoNodeRouteSourceType = "Direct"
   205  	RouteSourceTypeNodeMesh CalicoNodeRouteSourceType = "NodeMesh"
   206  	RouteSourceTypeBGPPeer  CalicoNodeRouteSourceType = "BGPPeer"
   207  )
   208  
   209  type NodeStatusClassType string
   210  
   211  const (
   212  	NodeStatusClassTypeAgent  NodeStatusClassType = "Agent"
   213  	NodeStatusClassTypeBGP    NodeStatusClassType = "BGP"
   214  	NodeStatusClassTypeRoutes NodeStatusClassType = "Routes"
   215  )
   216  
   217  type BGPPeerType string
   218  
   219  const (
   220  	BGPPeerTypeNodeMesh   BGPPeerType = "NodeMesh"
   221  	BGPPeerTypeNodePeer   BGPPeerType = "NodePeer"
   222  	BGPPeerTypeGlobalPeer BGPPeerType = "GlobalPeer"
   223  )
   224  
   225  type BGPDaemonState string
   226  
   227  const (
   228  	BGPDaemonStateReady    BGPDaemonState = "Ready"
   229  	BGPDaemonStateNotReady BGPDaemonState = "NotReady"
   230  )
   231  
   232  type BGPSessionState string
   233  
   234  const (
   235  	BGPSessionStateIdle        BGPSessionState = "Idle"
   236  	BGPSessionStateConnect     BGPSessionState = "Connect"
   237  	BGPSessionStateActive      BGPSessionState = "Active"
   238  	BGPSessionStateOpenSent    BGPSessionState = "OpenSent"
   239  	BGPSessionStateOpenConfirm BGPSessionState = "OpenConfirm"
   240  	BGPSessionStateEstablished BGPSessionState = "Established"
   241  	BGPSessionStateClose       BGPSessionState = "Close"
   242  )