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

     1  // Copyright (c) 2017, 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  	KindIPReservation     = "IPReservation"
    23  	KindIPReservationList = "IPReservationList"
    24  )
    25  
    26  // +genclient:nonNamespaced
    27  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
    28  
    29  // IPReservationList contains a list of IPReservation resources.
    30  type IPReservationList struct {
    31  	metav1.TypeMeta `json:",inline"`
    32  	metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
    33  
    34  	Items []IPReservation `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  // IPReservation allows certain IP addresses to be reserved (i.e. prevented from being allocated) by Calico
    42  // IPAM.  Reservations only block new allocations, they do not cause existing IP allocations to be released.
    43  // The current implementation is only suitable for reserving small numbers of IP addresses relative to the
    44  // size of the IP pool.  If large portions of an IP pool are reserved, Calico IPAM may hunt for a long time
    45  // to find a non-reserved IP.
    46  type IPReservation struct {
    47  	metav1.TypeMeta   `json:",inline"`
    48  	metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
    49  
    50  	Spec IPReservationSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`
    51  }
    52  
    53  // IPReservationSpec contains the specification for an IPReservation resource.
    54  type IPReservationSpec struct {
    55  	// ReservedCIDRs is a list of CIDRs and/or IP addresses that Calico IPAM will exclude from new allocations.
    56  	ReservedCIDRs []string `json:"reservedCIDRs,omitempty" validate:"cidrs,omitempty"`
    57  }
    58  
    59  // NewIPReservation creates a new (zeroed) IPReservation struct with the TypeMetadata initialised to the current
    60  // version.
    61  func NewIPReservation() *IPReservation {
    62  	return &IPReservation{
    63  		TypeMeta: metav1.TypeMeta{
    64  			Kind:       KindIPReservation,
    65  			APIVersion: GroupVersionCurrent,
    66  		},
    67  	}
    68  }