From ea26c436991522a84e8c3ad1b42a6699eb54dba9 Mon Sep 17 00:00:00 2001 From: Sushmitha Ravikumar Date: Fri, 13 Oct 2023 20:55:22 +0000 Subject: [PATCH] Revert "annotate pods with v6 addr from branch ENI when present (#309)" This reverts commit d488780db8784b4654e4db90cccb627ec2849a8f. --- .../pkg/aws/ec2/mock_instance.go | 28 ---------- pkg/aws/ec2/instance.go | 37 ++----------- pkg/provider/branch/trunk/trunk.go | 18 ++---- pkg/provider/branch/trunk/trunk_test.go | 55 +++++++------------ 4 files changed, 29 insertions(+), 109 deletions(-) diff --git a/mocks/amazon-vcp-resource-controller-k8s/pkg/aws/ec2/mock_instance.go b/mocks/amazon-vcp-resource-controller-k8s/pkg/aws/ec2/mock_instance.go index d287cff4..902cafb1 100644 --- a/mocks/amazon-vcp-resource-controller-k8s/pkg/aws/ec2/mock_instance.go +++ b/mocks/amazon-vcp-resource-controller-k8s/pkg/aws/ec2/mock_instance.go @@ -212,34 +212,6 @@ func (mr *MockEC2InstanceMockRecorder) SubnetMask() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SubnetMask", reflect.TypeOf((*MockEC2Instance)(nil).SubnetMask)) } -// SubnetV6CidrBlock mocks base method. -func (m *MockEC2Instance) SubnetV6CidrBlock() string { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "SubnetV6CidrBlock") - ret0, _ := ret[0].(string) - return ret0 -} - -// SubnetV6CidrBlock indicates an expected call of SubnetV6CidrBlock. -func (mr *MockEC2InstanceMockRecorder) SubnetV6CidrBlock() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SubnetV6CidrBlock", reflect.TypeOf((*MockEC2Instance)(nil).SubnetV6CidrBlock)) -} - -// SubnetV6Mask mocks base method. -func (m *MockEC2Instance) SubnetV6Mask() string { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "SubnetV6Mask") - ret0, _ := ret[0].(string) - return ret0 -} - -// SubnetV6Mask indicates an expected call of SubnetV6Mask. -func (mr *MockEC2InstanceMockRecorder) SubnetV6Mask() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SubnetV6Mask", reflect.TypeOf((*MockEC2Instance)(nil).SubnetV6Mask)) -} - // Type mocks base method. func (m *MockEC2Instance) Type() string { m.ctrl.T.Helper() diff --git a/pkg/aws/ec2/instance.go b/pkg/aws/ec2/instance.go index adde9058..698943ae 100644 --- a/pkg/aws/ec2/instance.go +++ b/pkg/aws/ec2/instance.go @@ -38,18 +38,15 @@ type ec2Instance struct { // subnetId is the instance's subnet id instanceSubnetID string // instanceSubnetCidrBlock is the cidr block of the instance's subnet - instanceSubnetCidrBlock string - instanceSubnetV6CidrBlock string + instanceSubnetCidrBlock string // currentSubnetID can either point to the Subnet ID of the instance or subnet ID from the ENIConfig currentSubnetID string // currentSubnetCIDRBlock can either point to the Subnet CIDR block for instance subnet or subnet from ENIConfig - currentSubnetCIDRBlock string - currentSubnetV6CIDRBlock string + currentSubnetCIDRBlock string // currentInstanceSecurityGroups can either point to the primary network interface security groups or the security groups in ENIConfig currentInstanceSecurityGroups []string // subnetMask is the mask of the subnet CIDR block - subnetMask string - subnetV6Mask string + subnetMask string // deviceIndexes is the list of indexes used by the EC2 Instance deviceIndexes []bool // primaryENIGroups is the security group used by the primary network interface @@ -73,9 +70,7 @@ type EC2Instance interface { InstanceID() string SubnetID() string SubnetMask() string - SubnetV6Mask() string SubnetCidrBlock() string - SubnetV6CidrBlock() string PrimaryNetworkInterfaceID() string CurrentInstanceSecurityGroups() []string SetNewCustomNetworkingSpec(subnetID string, securityGroup []string) @@ -115,16 +110,8 @@ func (i *ec2Instance) LoadDetails(ec2APIHelper api.EC2APIHelper) error { i.instanceSubnetID, i.instanceID) } i.instanceSubnetCidrBlock = *instanceSubnet.CidrBlock - i.subnetMask = strings.Split(i.instanceSubnetCidrBlock, "/")[1] - // Cache IPv6 CIDR block if one is present - for _, v6CidrBlock := range instanceSubnet.Ipv6CidrBlockAssociationSet { - if v6CidrBlock.Ipv6CidrBlock != nil { - i.instanceSubnetV6CidrBlock = *v6CidrBlock.Ipv6CidrBlock - i.subnetV6Mask = strings.Split(i.instanceSubnetV6CidrBlock, "/")[1] - break - } - } + i.subnetMask = strings.Split(i.instanceSubnetCidrBlock, "/")[1] i.instanceType = *instance.InstanceType limits, ok := vpc.Limits[i.instanceType] if !ok { @@ -191,13 +178,6 @@ func (i *ec2Instance) SubnetCidrBlock() string { return i.currentSubnetCIDRBlock } -func (i *ec2Instance) SubnetV6CidrBlock() string { - i.lock.RLock() - defer i.lock.RUnlock() - - return i.currentSubnetV6CIDRBlock -} - // Name returns the name of the node func (i *ec2Instance) Name() string { return i.name @@ -251,13 +231,6 @@ func (i *ec2Instance) SubnetMask() string { return i.subnetMask } -func (i *ec2Instance) SubnetV6Mask() string { - i.lock.Lock() - defer i.lock.Unlock() - - return i.subnetV6Mask -} - // SetNewCustomNetworkingSpec updates the subnet ID and subnet CIDR block for the instance func (i *ec2Instance) SetNewCustomNetworkingSpec(subnet string, securityGroups []string) { i.lock.Lock() @@ -298,14 +271,12 @@ func (i *ec2Instance) updateCurrentSubnetAndCidrBlock(ec2APIHelper api.EC2APIHel } i.currentSubnetID = i.newCustomNetworkingSubnetID i.currentSubnetCIDRBlock = *customSubnet.CidrBlock - // NOTE: IPv6 does not support custom networking } } else { // Custom networking in not being used, point to the primary network interface security group and // subnet details i.currentSubnetID = i.instanceSubnetID i.currentSubnetCIDRBlock = i.instanceSubnetCidrBlock - i.currentSubnetV6CIDRBlock = i.instanceSubnetV6CidrBlock i.currentInstanceSecurityGroups = i.primaryENISecurityGroups } diff --git a/pkg/provider/branch/trunk/trunk.go b/pkg/provider/branch/trunk/trunk.go index 7b656fa5..1dd75304 100644 --- a/pkg/provider/branch/trunk/trunk.go +++ b/pkg/provider/branch/trunk/trunk.go @@ -127,14 +127,12 @@ type ENIDetails struct { ID string `json:"eniId"` // MacAdd is the MAC address of the network interface MACAdd string `json:"ifAddress"` - // IPv4 and/or IPv6 address assigned to the branch Network interface + // BranchIp is the primary IP of the branch Network interface IPV4Addr string `json:"privateIp"` - IPV6Addr string `json:"ipv6Addr"` // VlanId is the VlanId of the branch network interface VlanID int `json:"vlanId"` // SubnetCIDR is the CIDR block of the subnet - SubnetCIDR string `json:"subnetCidr"` - SubnetV6CIDR string `json:"subnetV6Cidr"` + SubnetCIDR string `json:"subnetCidr"` // deletionTimeStamp is the time when the pod was marked deleted. deletionTimeStamp time.Time // deleteRetryCount is the @@ -385,17 +383,9 @@ func (t *trunkENI) CreateAndAssociateBranchENIs(pod *v1.Pod, securityGroups []st branchENIOperationsSuccessCount.WithLabelValues("created_branch_eni_succeeded").Inc() } - // Branch ENI can have an IPv4 address, IPv6 address, or both - var v4Addr, v6Addr string - if nwInterface.PrivateIpAddress != nil { - v4Addr = *nwInterface.PrivateIpAddress - } - if nwInterface.Ipv6Address != nil { - v6Addr = *nwInterface.Ipv6Address - } newENI := &ENIDetails{ID: *nwInterface.NetworkInterfaceId, MACAdd: *nwInterface.MacAddress, - IPV4Addr: v4Addr, IPV6Addr: v6Addr, SubnetCIDR: t.instance.SubnetCidrBlock(), - SubnetV6CIDR: t.instance.SubnetV6CidrBlock(), VlanID: vlanID} + IPV4Addr: *nwInterface.PrivateIpAddress, SubnetCIDR: t.instance.SubnetCidrBlock(), VlanID: vlanID} + newENIs = append(newENIs, newENI) // Associate Branch to trunk diff --git a/pkg/provider/branch/trunk/trunk_test.go b/pkg/provider/branch/trunk/trunk_test.go index 021dd0b0..ab322c03 100644 --- a/pkg/provider/branch/trunk/trunk_test.go +++ b/pkg/provider/branch/trunk/trunk_test.go @@ -40,7 +40,6 @@ var ( InstanceType = "c5.xlarge" SubnetId = "subnet-00000000000000000" SubnetCidrBlock = "192.168.0.0/16" - SubnetV6CidrBlock = "2600::/64" NodeName = "test-node" FakeInstance = ec2.NewEC2Instance(NodeName, InstanceId, config.OSLinux) InstanceSecurityGroup = []string{"sg-1", "sg-2"} @@ -57,9 +56,9 @@ var ( UID: MockPodUID1, Name: MockPodName1, Namespace: MockPodNamespace1, - Annotations: map[string]string{config.ResourceNamePodENI: "[{\"eniId\":\"eni-00000000000000000\",\"ifAddress\":\"FF:FF:FF:FF:FF:FF\",\"privateIp\":\"192.168.0.15\"," + - "\"ipv6Addr\":\"2600::\",\"vlanId\":1,\"subnetCidr\":\"192.168.0.0/16\",\"subnetV6Cidr\":\"2600::/64\"},{\"eniId\":\"eni-00000000000000001\",\"ifAddress\":\"" + - "FF:FF:FF:FF:FF:F9\",\"privateIp\":\"192.168.0.16\",\"ipv6Addr\":\"2600::1\",\"vlanId\":2,\"subnetCidr\":\"192.168.0.0/16\",\"subnetV6Cidr\":\"2600::/64\"}]"}}, + Annotations: map[string]string{config.ResourceNamePodENI: "[{\"eniId\":\"eni-00000000000000000\",\"ifAddress\":\"FF:FF:FF:FF:FF:FF\",\"privateIp\":\"192.168.0.15\"" + + ",\"vlanId\":1,\"subnetCidr\":\"192.168.0.0/16\"},{\"eniId\":\"eni-00000000000000001\",\"ifAddress\":\"" + + "FF:FF:FF:FF:FF:F9\",\"privateIp\":\"192.168.0.16\",\"vlanId\":2,\"subnetCidr\":\"192.168.0.0/16\"}]"}}, Spec: v1.PodSpec{NodeName: NodeName}, Status: v1.PodStatus{}, } @@ -89,20 +88,17 @@ var ( SecurityGroups = []string{SecurityGroup1, SecurityGroup2} // Branch Interface 1 - Branch1Id = "eni-00000000000000000" - MacAddr1 = "FF:FF:FF:FF:FF:FF" - BranchIp1 = "192.168.0.15" - BranchV6Ip1 = "2600::" - VlanId1 = 1 + Branch1Id = "eni-00000000000000000" + MacAddr1 = "FF:FF:FF:FF:FF:FF" + BranchIp1 = "192.168.0.15" + VlanId1 = 1 EniDetails1 = &ENIDetails{ - ID: Branch1Id, - MACAdd: MacAddr1, - IPV4Addr: BranchIp1, - IPV6Addr: BranchV6Ip1, - VlanID: VlanId1, - SubnetCIDR: SubnetCidrBlock, - SubnetV6CIDR: SubnetV6CidrBlock, + ID: Branch1Id, + MACAdd: MacAddr1, + IPV4Addr: BranchIp1, + VlanID: VlanId1, + SubnetCIDR: SubnetCidrBlock, } branchENIs1 = []*ENIDetails{EniDetails1} @@ -111,31 +107,26 @@ var ( MacAddress: &MacAddr1, NetworkInterfaceId: &Branch1Id, PrivateIpAddress: &BranchIp1, - Ipv6Address: &BranchV6Ip1, } // Branch Interface 2 - Branch2Id = "eni-00000000000000001" - MacAddr2 = "FF:FF:FF:FF:FF:F9" - BranchIp2 = "192.168.0.16" - BranchV6Ip2 = "2600::1" - VlanId2 = 2 + Branch2Id = "eni-00000000000000001" + MacAddr2 = "FF:FF:FF:FF:FF:F9" + BranchIp2 = "192.168.0.16" + VlanId2 = 2 EniDetails2 = &ENIDetails{ - ID: Branch2Id, - MACAdd: MacAddr2, - IPV4Addr: BranchIp2, - IPV6Addr: BranchV6Ip2, - VlanID: VlanId2, - SubnetCIDR: SubnetCidrBlock, - SubnetV6CIDR: SubnetV6CidrBlock, + ID: Branch2Id, + MACAdd: MacAddr2, + IPV4Addr: BranchIp2, + VlanID: VlanId2, + SubnetCIDR: SubnetCidrBlock, } BranchInterface2 = &awsEc2.NetworkInterface{ MacAddress: &MacAddr2, NetworkInterfaceId: &Branch2Id, PrivateIpAddress: &BranchIp2, - Ipv6Address: &BranchV6Ip2, } branchENIs2 = []*ENIDetails{EniDetails2} @@ -734,7 +725,6 @@ func TestTrunkENI_CreateAndAssociateBranchENIs(t *testing.T) { mockInstance.EXPECT().Type().Return(InstanceType) mockInstance.EXPECT().SubnetID().Return(SubnetId).Times(2) mockInstance.EXPECT().SubnetCidrBlock().Return(SubnetCidrBlock).Times(2) - mockInstance.EXPECT().SubnetV6CidrBlock().Return(SubnetV6CidrBlock).Times(2) mockEC2APIHelper.EXPECT().CreateNetworkInterface(&BranchEniDescription, &SubnetId, SecurityGroups, vlan1Tag, nil, nil).Return(BranchInterface1, nil) @@ -767,7 +757,6 @@ func TestTrunkENI_CreateAndAssociateBranchENIs_InstanceSecurityGroup(t *testing. mockInstance.EXPECT().Type().Return(InstanceType) mockInstance.EXPECT().SubnetID().Return(SubnetId).Times(2) mockInstance.EXPECT().SubnetCidrBlock().Return(SubnetCidrBlock).Times(2) - mockInstance.EXPECT().SubnetV6CidrBlock().Return(SubnetV6CidrBlock).Times(2) mockInstance.EXPECT().CurrentInstanceSecurityGroups().Return(InstanceSecurityGroup) mockEC2APIHelper.EXPECT().CreateNetworkInterface(&BranchEniDescription, &SubnetId, InstanceSecurityGroup, @@ -801,7 +790,6 @@ func TestTrunkENI_CreateAndAssociateBranchENIs_ErrorAssociate(t *testing.T) { mockInstance.EXPECT().Type().Return(InstanceType) mockInstance.EXPECT().SubnetID().Return(SubnetId).Times(2) mockInstance.EXPECT().SubnetCidrBlock().Return(SubnetCidrBlock).Times(2) - mockInstance.EXPECT().SubnetV6CidrBlock().Return(SubnetV6CidrBlock).Times(2) gomock.InOrder( mockEC2APIHelper.EXPECT().CreateNetworkInterface(&BranchEniDescription, &SubnetId, SecurityGroups, @@ -829,7 +817,6 @@ func TestTrunkENI_CreateAndAssociateBranchENIs_ErrorCreate(t *testing.T) { mockInstance.EXPECT().Type().Return(InstanceType) mockInstance.EXPECT().SubnetID().Return(SubnetId).Times(2) mockInstance.EXPECT().SubnetCidrBlock().Return(SubnetCidrBlock).Times(1) - mockInstance.EXPECT().SubnetV6CidrBlock().Return(SubnetV6CidrBlock).Times(1) gomock.InOrder( mockEC2APIHelper.EXPECT().CreateNetworkInterface(&BranchEniDescription, &SubnetId, SecurityGroups, vlan1Tag,