github.com/tigera/api@v0.0.0-20240320170621-278e89a8c5fb/pkg/apis/projectcalico/v3/ippool.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  	KindIPPool     = "IPPool"
    23  	KindIPPoolList = "IPPoolList"
    24  )
    25  
    26  // +genclient:nonNamespaced
    27  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
    28  
    29  // IPPoolList contains a list of IPPool resources.
    30  type IPPoolList struct {
    31  	metav1.TypeMeta `json:",inline"`
    32  	metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
    33  
    34  	Items []IPPool `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 IPPool struct {
    42  	metav1.TypeMeta   `json:",inline"`
    43  	metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
    44  
    45  	Spec IPPoolSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`
    46  }
    47  
    48  // IPPoolSpec contains the specification for an IPPool resource.
    49  type IPPoolSpec struct {
    50  	// The pool CIDR.
    51  	CIDR string `json:"cidr" validate:"net"`
    52  
    53  	// Contains configuration for VXLAN tunneling for this pool. If not specified,
    54  	// then this is defaulted to "Never" (i.e. VXLAN tunneling is disabled).
    55  	VXLANMode VXLANMode `json:"vxlanMode,omitempty" validate:"omitempty,vxlanMode"`
    56  
    57  	// Contains configuration for IPIP tunneling for this pool. If not specified,
    58  	// then this is defaulted to "Never" (i.e. IPIP tunneling is disabled).
    59  	IPIPMode IPIPMode `json:"ipipMode,omitempty" validate:"omitempty,ipIpMode"`
    60  
    61  	// When natOutgoing is true, packets sent from Calico networked containers in
    62  	// this pool to destinations outside of this pool will be masqueraded.
    63  	NATOutgoing bool `json:"natOutgoing,omitempty"`
    64  
    65  	// When disabled is true, Calico IPAM will not assign addresses from this pool.
    66  	Disabled bool `json:"disabled,omitempty"`
    67  
    68  	// Disable exporting routes from this IP Pool's CIDR over BGP. [Default: false]
    69  	DisableBGPExport bool `json:"disableBGPExport,omitempty" validate:"omitempty"`
    70  
    71  	// The block size to use for IP address assignments from this pool. Defaults to 26 for IPv4 and 122 for IPv6.
    72  	BlockSize int `json:"blockSize,omitempty"`
    73  
    74  	// Allows IPPool to allocate for a specific node by label selector.
    75  	NodeSelector string `json:"nodeSelector,omitempty" validate:"omitempty,selector"`
    76  
    77  	// Deprecated: this field is only used for APIv1 backwards compatibility.
    78  	// Setting this field is not allowed, this field is for internal use only.
    79  	IPIP *IPIPConfiguration `json:"ipip,omitempty" validate:"omitempty,mustBeNil"`
    80  
    81  	// Deprecated: this field is only used for APIv1 backwards compatibility.
    82  	// Setting this field is not allowed, this field is for internal use only.
    83  	NATOutgoingV1 bool `json:"nat-outgoing,omitempty" validate:"omitempty,mustBeFalse"`
    84  
    85  	// AllowedUse controls what the IP pool will be used for.  If not specified or empty, defaults to
    86  	// ["Tunnel", "Workload"] for back-compatibility
    87  	AllowedUses []IPPoolAllowedUse `json:"allowedUses,omitempty" validate:"omitempty"`
    88  
    89  	// AWSSubnetID if specified Calico will attempt to ensure that IPs chosen from this IP pool are routed
    90  	// to the corresponding node by adding one or more secondary ENIs to the node and explicitly assigning
    91  	// the IP to one of the secondary ENIs.  Important: since subnets cannot cross availability zones,
    92  	// it's important to use Kubernetes node selectors to avoid scheduling pods to one availability zone
    93  	// using an IP pool that is backed by a subnet that belongs to another availability zone. If AWSSubnetID
    94  	// is specified, then the CIDR of the IP pool must be contained within the specified AWS subnet.
    95  	AWSSubnetID string `json:"awsSubnetID,omitempty" validate:"omitempty"`
    96  }
    97  
    98  type IPPoolAllowedUse string
    99  
   100  const (
   101  	IPPoolAllowedUseWorkload      IPPoolAllowedUse = "Workload"
   102  	IPPoolAllowedUseTunnel        IPPoolAllowedUse = "Tunnel"
   103  	IPPoolAllowedUseHostSecondary IPPoolAllowedUse = "HostSecondaryInterface"
   104  )
   105  
   106  type VXLANMode string
   107  
   108  const (
   109  	VXLANModeNever       VXLANMode = "Never"
   110  	VXLANModeAlways      VXLANMode = "Always"
   111  	VXLANModeCrossSubnet VXLANMode = "CrossSubnet"
   112  )
   113  
   114  type IPIPMode string
   115  
   116  const (
   117  	IPIPModeNever       IPIPMode = "Never"
   118  	IPIPModeAlways      IPIPMode = "Always"
   119  	IPIPModeCrossSubnet IPIPMode = "CrossSubnet"
   120  )
   121  
   122  // The following definitions are only used for APIv1 backwards compatibility.
   123  // They are for internal use only.
   124  type EncapMode string
   125  
   126  const (
   127  	Undefined   EncapMode = ""
   128  	Always      EncapMode = "always"
   129  	CrossSubnet EncapMode = "cross-subnet"
   130  )
   131  
   132  const DefaultMode = Always
   133  
   134  type IPIPConfiguration struct {
   135  	// When enabled is true, ipip tunneling will be used to deliver packets to
   136  	// destinations within this pool.
   137  	Enabled bool `json:"enabled,omitempty"`
   138  
   139  	// The IPIP mode.  This can be one of "always" or "cross-subnet".  A mode
   140  	// of "always" will also use IPIP tunneling for routing to destination IP
   141  	// addresses within this pool.  A mode of "cross-subnet" will only use IPIP
   142  	// tunneling when the destination node is on a different subnet to the
   143  	// originating node.  The default value (if not specified) is "always".
   144  	Mode EncapMode `json:"mode,omitempty" validate:"ipIpMode"`
   145  }
   146  
   147  // NewIPPool creates a new (zeroed) IPPool struct with the TypeMetadata initialised to the current
   148  // version.
   149  func NewIPPool() *IPPool {
   150  	return &IPPool{
   151  		TypeMeta: metav1.TypeMeta{
   152  			Kind:       KindIPPool,
   153  			APIVersion: GroupVersionCurrent,
   154  		},
   155  	}
   156  }