github.com/cilium/cilium@v1.16.2/pkg/alibabacloud/eni/types/types.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright Authors of Cilium
     3  
     4  package types
     5  
     6  import (
     7  	"github.com/cilium/cilium/pkg/ipam/types"
     8  )
     9  
    10  // Spec is the ENI specification of a node. This specification is considered
    11  // by the cilium-operator to act as an IPAM operator and makes ENI IPs available
    12  // via the IPAMSpec section.
    13  //
    14  // The ENI specification can either be provided explicitly by the user or the
    15  // cilium-agent running on the node can be instructed to create the CiliumNode
    16  // custom resource along with an ENI specification when the node registers
    17  // itself to the Kubernetes cluster.
    18  type Spec struct {
    19  	// InstanceType is the ECS instance type, e.g. "ecs.g6.2xlarge"
    20  	//
    21  	// +kubebuilder:validation:Optional
    22  	InstanceType string `json:"instance-type,omitempty"`
    23  
    24  	// AvailabilityZone is the availability zone to use when allocating
    25  	// ENIs.
    26  	//
    27  	// +kubebuilder:validation:Optional
    28  	AvailabilityZone string `json:"availability-zone,omitempty"`
    29  
    30  	// VPCID is the VPC ID to use when allocating ENIs.
    31  	//
    32  	// +kubebuilder:validation:Optional
    33  	VPCID string `json:"vpc-id,omitempty"`
    34  
    35  	// CIDRBlock is vpc ipv4 CIDR
    36  	//
    37  	// +kubebuilder:validation:Optional
    38  	CIDRBlock string `json:"cidr-block,omitempty"`
    39  
    40  	// VSwitches is the ID of vSwitch available for ENI
    41  	//
    42  	// +kubebuilder:validation:Optional
    43  	VSwitches []string `json:"vswitches,omitempty"`
    44  
    45  	// VSwitchTags is the list of tags to use when evaluating which
    46  	// vSwitch to use for the ENI.
    47  	//
    48  	// +kubebuilder:validation:Optional
    49  	VSwitchTags map[string]string `json:"vswitch-tags,omitempty"`
    50  
    51  	// SecurityGroups is the list of security groups to attach to any ENI
    52  	// that is created and attached to the instance.
    53  	//
    54  	// +kubebuilder:validation:Optional
    55  	SecurityGroups []string `json:"security-groups,omitempty"`
    56  
    57  	// SecurityGroupTags is the list of tags to use when evaluating which
    58  	// security groups to use for the ENI.
    59  	//
    60  	// +kubebuilder:validation:Optional
    61  	SecurityGroupTags map[string]string `json:"security-group-tags,omitempty"`
    62  }
    63  
    64  const (
    65  	// ENITypePrimary is the type for ENI
    66  	ENITypePrimary string = "Primary"
    67  	// ENITypeSecondary is the type for ENI
    68  	ENITypeSecondary string = "Secondary"
    69  )
    70  
    71  // ENI represents an AlibabaCloud Elastic Network Interface
    72  type ENI struct {
    73  	// NetworkInterfaceID is the ENI id
    74  	//
    75  	// +optional
    76  	NetworkInterfaceID string `json:"network-interface-id,omitempty"`
    77  
    78  	// MACAddress is the mac address of the ENI
    79  	//
    80  	// +optional
    81  	MACAddress string `json:"mac-address,omitempty"`
    82  
    83  	// Type is the ENI type Primary or Secondary
    84  	//
    85  	// +optional
    86  	Type string `json:"type,omitempty"`
    87  
    88  	// InstanceID is the InstanceID using this ENI
    89  	//
    90  	// +optional
    91  	InstanceID string `json:"instance-id,omitempty"`
    92  
    93  	// SecurityGroupIDs is the security group ids used by this ENI
    94  	//
    95  	// +optional
    96  	SecurityGroupIDs []string `json:"security-groupids,omitempty"`
    97  
    98  	// VPC is the vpc to which the ENI belongs
    99  	//
   100  	// +optional
   101  	VPC VPC `json:"vpc,omitempty"`
   102  
   103  	// ZoneID is the zone to which the ENI belongs
   104  	//
   105  	// +optional
   106  	ZoneID string `json:"zone-id,omitempty"`
   107  
   108  	// VSwitch is the vSwitch the ENI is using
   109  	//
   110  	// +optional
   111  	VSwitch VSwitch `json:"vswitch,omitempty"`
   112  
   113  	// PrimaryIPAddress is the primary IP on ENI
   114  	//
   115  	// +optional
   116  	PrimaryIPAddress string `json:"primary-ip-address,omitempty"`
   117  
   118  	// PrivateIPSets is the list of all IPs on the ENI, including PrimaryIPAddress
   119  	//
   120  	// +optional
   121  	PrivateIPSets []PrivateIPSet `json:"private-ipsets,omitempty"`
   122  
   123  	// Tags is the tags on this ENI
   124  	//
   125  	// +optional
   126  	Tags map[string]string `json:"tags,omitempty"`
   127  }
   128  
   129  func (e *ENI) DeepCopyInterface() types.Interface {
   130  	return e.DeepCopy()
   131  }
   132  
   133  // InterfaceID returns the identifier of the interface
   134  func (e *ENI) InterfaceID() string {
   135  	return e.NetworkInterfaceID
   136  }
   137  
   138  // ForeachAddress iterates over all addresses and calls fn
   139  func (e *ENI) ForeachAddress(id string, fn types.AddressIterator) error {
   140  	for _, address := range e.PrivateIPSets {
   141  		if address.Primary {
   142  			continue
   143  		}
   144  		if err := fn(id, e.NetworkInterfaceID, address.PrivateIpAddress, "", address); err != nil {
   145  			return err
   146  		}
   147  	}
   148  
   149  	return nil
   150  }
   151  
   152  // ENIStatus is the status of ENI addressing of the node
   153  type ENIStatus struct {
   154  	// ENIs is the list of ENIs on the node
   155  	//
   156  	// +optional
   157  	ENIs map[string]ENI `json:"enis,omitempty"`
   158  }
   159  
   160  // PrivateIPSet is a nested struct in ecs response
   161  type PrivateIPSet struct {
   162  	PrivateIpAddress string `json:"private-ip-address,omitempty"`
   163  	Primary          bool   `json:"primary,omitempty" `
   164  }
   165  
   166  type VPC struct {
   167  	// VPCID is the vpc to which the ENI belongs
   168  	//
   169  	// +optional
   170  	VPCID string `json:"vpc-id,omitempty"`
   171  
   172  	// CIDRBlock is the VPC IPv4 CIDR
   173  	//
   174  	// +optional
   175  	CIDRBlock string `json:"cidr,omitempty"`
   176  
   177  	// IPv6CIDRBlock is the VPC IPv6 CIDR
   178  	//
   179  	// +optional
   180  	IPv6CIDRBlock string `json:"ipv6-cidr,omitempty"`
   181  
   182  	// SecondaryCIDRs is the list of Secondary CIDRs associated with the VPC
   183  	//
   184  	// +optional
   185  	SecondaryCIDRs []string `json:"secondary-cidrs,omitempty"`
   186  }
   187  
   188  type VSwitch struct {
   189  	// VSwitchID is the vSwitch to which the ENI belongs
   190  	//
   191  	// +optional
   192  	VSwitchID string `json:"vswitch-id,omitempty"`
   193  
   194  	// CIDRBlock is the vSwitch IPv4 CIDR
   195  	//
   196  	// +optional
   197  	CIDRBlock string `json:"cidr,omitempty"`
   198  
   199  	// IPv6CIDRBlock is the vSwitch IPv6 CIDR
   200  	//
   201  	// +optional
   202  	IPv6CIDRBlock string `json:"ipv6-cidr,omitempty"`
   203  }