diff --git a/.github/workflows/integration-tests.yaml b/.github/workflows/integration-tests.yaml index a284243c55..ba50c6d0b0 100644 --- a/.github/workflows/integration-tests.yaml +++ b/.github/workflows/integration-tests.yaml @@ -23,7 +23,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v3 with: - go-version: "1.21" + go-version: "1.22" - name: Set up tools run: | # Install ginkgo version from go.mod diff --git a/.github/workflows/nightly-cron-tests.yaml b/.github/workflows/nightly-cron-tests.yaml index 095d8e94ac..0ac5f6b668 100644 --- a/.github/workflows/nightly-cron-tests.yaml +++ b/.github/workflows/nightly-cron-tests.yaml @@ -22,7 +22,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v3 with: - go-version: "1.21" + go-version: "1.22" - name: Set up tools run: | # Install ginkgo version from go.mod diff --git a/.github/workflows/pr-automated-tests.yaml b/.github/workflows/pr-automated-tests.yaml index a3fe113a3b..c34827f3c9 100644 --- a/.github/workflows/pr-automated-tests.yaml +++ b/.github/workflows/pr-automated-tests.yaml @@ -16,7 +16,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v3 with: - go-version: "1.21" + go-version: "1.22" - name: Set up tools run: | go install golang.org/x/lint/golint@latest @@ -50,7 +50,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v3 with: - go-version: "1.21" + go-version: "1.22" - name: Build CNI images run: make multi-arch-cni-build - name: Build CNI Init images diff --git a/.github/workflows/pr-manual-tests.yaml b/.github/workflows/pr-manual-tests.yaml index c50994a46e..0f84bbd6f6 100644 --- a/.github/workflows/pr-manual-tests.yaml +++ b/.github/workflows/pr-manual-tests.yaml @@ -29,7 +29,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v3 with: - go-version: "1.21" + go-version: "1.22" - name: Set up tools run: | # Install ginkgo version from go.mod diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index d449df4213..93350c60e3 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -22,7 +22,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v3 with: - go-version: "1.21" + go-version: "1.22" - name: Generate CNI YAML run: make generate-cni-yaml - name: Create eks-charts PR diff --git a/.github/workflows/weekly-cron-tests.yaml b/.github/workflows/weekly-cron-tests.yaml index c12e9139d4..505526b46e 100644 --- a/.github/workflows/weekly-cron-tests.yaml +++ b/.github/workflows/weekly-cron-tests.yaml @@ -23,7 +23,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v3 with: - go-version: "1.21" + go-version: "1.22" - name: Set up tools run: | # Install ginkgo version from go.mod diff --git a/go.mod b/go.mod index 2a203b9655..16717c2606 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/aws/amazon-vpc-cni-k8s -go 1.21 +go 1.22.3 require ( github.com/apparentlymart/go-cidr v1.1.0 diff --git a/pkg/ipamd/ipamd_test.go b/pkg/ipamd/ipamd_test.go index ac5802c257..7dc6133a34 100644 --- a/pkg/ipamd/ipamd_test.go +++ b/pkg/ipamd/ipamd_test.go @@ -1397,8 +1397,6 @@ func datastoreWith3PodsFromPrefix() *datastore.DataStore { } func TestIPAMContext_filterUnmanagedENIs(t *testing.T) { - ctrl := gomock.NewController(t) - eni1, eni2, eni3 := getDummyENIMetadata() allENIs := []awsutils.ENIMetadata{eni1, eni2, eni3} primaryENIonly := []awsutils.ENIMetadata{eni1} @@ -1417,26 +1415,29 @@ func TestIPAMContext_filterUnmanagedENIs(t *testing.T) { eni2.ENIID: {"hi": "tag", eniNodeTagKey: "i-abcdabcdabcd"}, eni3.ENIID: {"hi": "tag", eniNodeTagKey: instanceID}} - mockAWSUtils := mock_awsutils.NewMockAPIs(ctrl) - mockAWSUtils.EXPECT().GetPrimaryENI().Times(5).Return(eni1.ENIID) - mockAWSUtils.EXPECT().GetInstanceID().Times(3).Return(instanceID) - tests := []struct { - name string - tagMap map[string]awsutils.TagMap - enis []awsutils.ENIMetadata - want []awsutils.ENIMetadata - unmanagedenis []string + name string + tagMap map[string]awsutils.TagMap + enis []awsutils.ENIMetadata + want []awsutils.ENIMetadata + unmanagedenis []string + expectedGetPrimaryENICalls int + expectedGetInstanceIDCalls int }{ - {"No tags at all", nil, allENIs, allENIs, nil}, - {"Primary ENI unmanaged", Test1TagMap, allENIs, allENIs, nil}, - {"Secondary/Tertiary ENI unmanaged", Test2TagMap, allENIs, primaryENIonly, []string{eni2.ENIID, eni3.ENIID}}, - {"Secondary ENI unmanaged", Test3TagMap, allENIs, filteredENIonly, []string{eni2.ENIID}}, - {"Secondary ENI unmanaged and Tertiary ENI CNI created", Test4TagMap, allENIs, filteredENIonly, []string{eni2.ENIID}}, - {"Secondary ENI not CNI created and Tertiary ENI CNI created", Test5TagMap, allENIs, filteredENIonly, nil}, + {"No tags at all", nil, allENIs, allENIs, nil, 0, 0}, + {"Primary ENI unmanaged", Test1TagMap, allENIs, allENIs, nil, 1, 0}, + {"Secondary/Tertiary ENI unmanaged", Test2TagMap, allENIs, primaryENIonly, []string{eni2.ENIID, eni3.ENIID}, 2, 0}, + {"Secondary ENI unmanaged", Test3TagMap, allENIs, filteredENIonly, []string{eni2.ENIID}, 1, 0}, + {"Secondary ENI unmanaged and Tertiary ENI CNI created", Test4TagMap, allENIs, filteredENIonly, []string{eni2.ENIID}, 1, 1}, + {"Secondary ENI not CNI created and Tertiary ENI CNI created", Test5TagMap, allENIs, filteredENIonly, nil, 0, 2}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + mockAWSUtils := mock_awsutils.NewMockAPIs(ctrl) + c := &IPAMContext{ awsClient: mockAWSUtils, enableManageUntaggedMode: true} @@ -1447,6 +1448,10 @@ func TestIPAMContext_filterUnmanagedENIs(t *testing.T) { sort.Strings(args) assert.Equal(t, tt.unmanagedenis, args) }).AnyTimes() + + mockAWSUtils.EXPECT().GetPrimaryENI().Times(tt.expectedGetPrimaryENICalls).Return(eni1.ENIID) + mockAWSUtils.EXPECT().GetInstanceID().Times(tt.expectedGetInstanceIDCalls).Return(instanceID) + c.setUnmanagedENIs(tt.tagMap) mockAWSUtils.EXPECT().IsUnmanagedENI(gomock.Any()).DoAndReturn( @@ -1479,7 +1484,6 @@ func TestIPAMContext_filterUnmanagedENIs(t *testing.T) { } func TestIPAMContext_filterUnmanagedENIs_disableManageUntaggedMode(t *testing.T) { - ctrl := gomock.NewController(t) eni1, eni2, eni3 := getDummyENIMetadata() allENIs := []awsutils.ENIMetadata{eni1, eni2, eni3} @@ -1499,30 +1503,37 @@ func TestIPAMContext_filterUnmanagedENIs_disableManageUntaggedMode(t *testing.T) eni2.ENIID: {"hi": "tag", eniNodeTagKey: "i-abcdabcdabcd"}, eni3.ENIID: {"hi": "tag", eniNodeTagKey: instanceID}} - mockAWSUtils := mock_awsutils.NewMockAPIs(ctrl) - mockAWSUtils.EXPECT().GetPrimaryENI().Times(6).Return(eni1.ENIID) - mockAWSUtils.EXPECT().GetInstanceID().Times(3).Return(instanceID) - tests := []struct { - name string - tagMap map[string]awsutils.TagMap - enis []awsutils.ENIMetadata - want []awsutils.ENIMetadata - unmanagedenis []string + name string + tagMap map[string]awsutils.TagMap + enis []awsutils.ENIMetadata + want []awsutils.ENIMetadata + unmanagedenis []string + expectedGetPrimaryENICalls int + expectedGetInstanceIDCalls int }{ - {"No tags at all", nil, allENIs, allENIs, []string{eni2.ENIID, eni3.ENIID}}, - {"Primary ENI unmanaged", Test1TagMap, allENIs, allENIs, nil}, - {"Secondary/Tertiary ENI unmanaged", Test2TagMap, allENIs, primaryENIonly, []string{eni2.ENIID, eni3.ENIID}}, - {"Secondary ENI unmanaged", Test3TagMap, allENIs, filteredENIonly, []string{eni2.ENIID}}, - {"Secondary ENI unmanaged and Tertiary ENI CNI created", Test4TagMap, allENIs, filteredENIonly, []string{eni2.ENIID}}, - {"Secondary ENI not CNI created and Tertiary ENI CNI created", Test5TagMap, allENIs, filteredENIonly, []string{eni2.ENIID}}, + {"No tags at all", nil, allENIs, allENIs, []string{eni2.ENIID, eni3.ENIID}, 0, 0}, + {"Primary ENI unmanaged", Test1TagMap, allENIs, allENIs, nil, 1, 0}, + {"Secondary/Tertiary ENI unmanaged", Test2TagMap, allENIs, primaryENIonly, []string{eni2.ENIID, eni3.ENIID}, 2, 0}, + {"Secondary ENI unmanaged", Test3TagMap, allENIs, filteredENIonly, []string{eni2.ENIID}, 1, 0}, + {"Secondary ENI unmanaged and Tertiary ENI CNI created", Test4TagMap, allENIs, filteredENIonly, []string{eni2.ENIID}, 1, 1}, + {"Secondary ENI not CNI created and Tertiary ENI CNI created", Test5TagMap, allENIs, filteredENIonly, []string{eni2.ENIID}, 1, 2}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + ctrl := gomock.NewController(t) + + defer ctrl.Finish() + + mockAWSUtils := mock_awsutils.NewMockAPIs(ctrl) + c := &IPAMContext{ awsClient: mockAWSUtils, enableManageUntaggedMode: false} + mockAWSUtils.EXPECT().GetPrimaryENI().Times(tt.expectedGetPrimaryENICalls).Return(eni1.ENIID) + mockAWSUtils.EXPECT().GetInstanceID().Times(tt.expectedGetInstanceIDCalls).Return(instanceID) + mockAWSUtils. EXPECT(). SetUnmanagedENIs(gomock.Any()). diff --git a/test/agent/go.mod b/test/agent/go.mod index db9ac45b64..81506d3f38 100644 --- a/test/agent/go.mod +++ b/test/agent/go.mod @@ -1,6 +1,6 @@ module github.com/aws/amazon-vpc-cni-k8s/test/agent -go 1.21 +go 1.22.3 require ( github.com/coreos/go-iptables v0.7.0