github.com/cilium/cilium@v1.16.2/pkg/alibabacloud/eni/node_stat_test.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright Authors of Cilium 3 4 package eni 5 6 import ( 7 "context" 8 "testing" 9 10 "github.com/stretchr/testify/assert" 11 12 "github.com/cilium/cilium/pkg/alibabacloud/eni/limits" 13 eniTypes "github.com/cilium/cilium/pkg/alibabacloud/eni/types" 14 ipamTypes "github.com/cilium/cilium/pkg/ipam/types" 15 v2 "github.com/cilium/cilium/pkg/k8s/apis/cilium.io/v2" 16 ) 17 18 func TestENIIPAMCapacityAccounting(t *testing.T) { 19 assert := assert.New(t) 20 limits.Update(map[string]ipamTypes.Limits{ 21 "ecs.g6.large": { 22 IPv4: 10, 23 Adapters: 3, 24 }, 25 }) 26 m := ipamTypes.NewInstanceMap() 27 resource := &eniTypes.ENI{ 28 NetworkInterfaceID: "eni-1", 29 PrivateIPSets: []eniTypes.PrivateIPSet{ 30 { 31 Primary: true, // one primary IP 32 }, 33 }, 34 } 35 m.Update("vm1", ipamTypes.InterfaceRevision{ 36 Resource: resource.DeepCopy(), 37 }) 38 39 n := &Node{ 40 node: mockIPAMNode("vm1"), 41 manager: &InstancesManager{ 42 instances: m, 43 }, 44 k8sObj: &v2.CiliumNode{ 45 Spec: v2.NodeSpec{ 46 AlibabaCloud: eniTypes.Spec{ 47 InstanceType: "ecs.g6.large", 48 }, 49 }, 50 }, 51 } 52 _, stats, err := n.ResyncInterfacesAndIPs(context.Background(), log) 53 assert.NoError(err) 54 // 3 ENIs, 10 IPs per ENI, 1 primary IP and one ENI is primary. 55 assert.Equal(19, stats.NodeCapacity) 56 } 57 58 type mockIPAMNode string 59 60 func (m mockIPAMNode) InstanceID() string { 61 return string(m) 62 }