Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert commit d57c4436e868106e3d7fc7e46f84e4e31af2c46e #3150

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ require (
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
github.com/lib/pq v1.10.9 // indirect
Expand Down
34 changes: 0 additions & 34 deletions pkg/awsutils/awsutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,10 @@ import (

"github.com/aws/aws-sdk-go-v2/service/ec2"
"github.com/golang/mock/gomock"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/testutil"
"github.com/stretchr/testify/assert"

mock_ec2wrapper "github.com/aws/amazon-vpc-cni-k8s/pkg/ec2wrapper/mocks"
"github.com/aws/amazon-vpc-cni-k8s/pkg/utils/eventrecorder"
"github.com/aws/amazon-vpc-cni-k8s/utils/prometheusmetrics"
"github.com/aws/aws-sdk-go-v2/aws"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -819,37 +816,6 @@ func TestFreeENIRetry(t *testing.T) {
assert.NoError(t, err)
}

func TestAwsAPIErrInc(t *testing.T) {
// Reset metrics before test
prometheusmetrics.AwsAPIErr.Reset()

// Test case 1: AWS error
awsErr := &smithy.GenericAPIError{
Code: "InvalidParameterException",
Message: "The parameter is invalid",
Fault: smithy.FaultUnknown,
}
awsAPIErrInc("CreateNetworkInterface", awsErr)

// Verify metric was incremented with correct labels
count := testutil.ToFloat64(prometheusmetrics.AwsAPIErr.With(prometheus.Labels{
"api": "CreateNetworkInterface",
"error": "InvalidParameterException",
}))
assert.Equal(t, float64(1), count)

// Test case 2: Non-AWS error
regularErr := errors.New("some other error")
awsAPIErrInc("CreateNetworkInterface", regularErr)

// Verify metric was not incremented for non-AWS error
count = testutil.ToFloat64(prometheusmetrics.AwsAPIErr.With(prometheus.Labels{
"api": "CreateNetworkInterface",
"error": "InvalidParameterException",
}))
assert.Equal(t, float64(1), count)
}

func TestFreeENIRetryMax(t *testing.T) {
ctrl, mockEC2 := setup(t)
defer ctrl.Finish()
Expand Down
73 changes: 0 additions & 73 deletions pkg/ipamd/datastore/data_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (

mock_netlinkwrapper "github.com/aws/amazon-vpc-cni-k8s/pkg/netlinkwrapper/mocks"
"github.com/aws/amazon-vpc-cni-k8s/pkg/networkutils"
"github.com/aws/amazon-vpc-cni-k8s/utils/prometheusmetrics"
"github.com/golang/mock/gomock"
"github.com/vishvananda/netlink"
"golang.org/x/sys/unix"
Expand All @@ -32,8 +31,6 @@ import (

"github.com/aws/amazon-vpc-cni-k8s/pkg/utils/logger"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/testutil"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -1545,73 +1542,3 @@ func TestDataStore_validateAllocationByPodVethExistence(t *testing.T) {
})
}
}

func TestForceRemovalMetrics(t *testing.T) {
// Reset metrics by creating new counters
prometheusmetrics.ForceRemovedENIs = prometheus.NewCounter(prometheus.CounterOpts{
Name: "awscni_force_removed_enis_total",
Help: "The total number of ENIs force removed",
})
prometheusmetrics.ForceRemovedIPs = prometheus.NewCounter(prometheus.CounterOpts{
Name: "awscni_force_removed_ips_total",
Help: "The total number of IPs force removed",
})

ds := NewDataStore(Testlog, NullCheckpoint{}, false)

// Add an ENI and IP
err := ds.AddENI("eni-1", 1, true, false, false)
assert.NoError(t, err)

ipv4Addr := net.IPNet{IP: net.ParseIP("1.1.1.1"), Mask: net.IPv4Mask(255, 255, 255, 255)}
err = ds.AddIPv4CidrToStore("eni-1", ipv4Addr, false)
assert.NoError(t, err)

// Assign IP to a pod
key := IPAMKey{"net0", "sandbox-1", "eth0"}
ip, device, err := ds.AssignPodIPv4Address(key, IPAMMetadata{K8SPodNamespace: "default", K8SPodName: "sample-pod-1"})
assert.NoError(t, err)
assert.Equal(t, "1.1.1.1", ip)
assert.Equal(t, 1, device)

// Test force removal of IP
err = ds.DelIPv4CidrFromStore("eni-1", ipv4Addr, false)
assert.Error(t, err) // Should fail without force
assert.Contains(t, err.Error(), "IP is used and can not be deleted")

ipCount := testutil.ToFloat64(prometheusmetrics.ForceRemovedIPs)
assert.Equal(t, float64(0), ipCount)

// Force remove the IP
err = ds.DelIPv4CidrFromStore("eni-1", ipv4Addr, true)
assert.NoError(t, err) // Should succeed with force

ipCount = testutil.ToFloat64(prometheusmetrics.ForceRemovedIPs)
assert.Equal(t, float64(1), ipCount)

// Add another IP and assign to pod for ENI removal test
ipv4Addr2 := net.IPNet{IP: net.ParseIP("1.1.1.2"), Mask: net.IPv4Mask(255, 255, 255, 255)}
err = ds.AddIPv4CidrToStore("eni-1", ipv4Addr2, false)
assert.NoError(t, err)

key2 := IPAMKey{"net0", "sandbox-2", "eth0"}
ip, device, err = ds.AssignPodIPv4Address(key2, IPAMMetadata{K8SPodNamespace: "default", K8SPodName: "sample-pod-2"})
assert.NoError(t, err)
assert.Equal(t, "1.1.1.2", ip)
assert.Equal(t, 1, device)

// Test force removal of ENI
err = ds.RemoveENIFromDataStore("eni-1", false)
assert.Error(t, err) // Should fail without force
assert.Contains(t, err.Error(), "datastore: ENI is used and can not be deleted") // Updated error message

eniCount := testutil.ToFloat64(prometheusmetrics.ForceRemovedENIs)
assert.Equal(t, float64(0), eniCount)

// Force remove the ENI
err = ds.RemoveENIFromDataStore("eni-1", true)
assert.NoError(t, err) // Should succeed with force

eniCount = testutil.ToFloat64(prometheusmetrics.ForceRemovedENIs)
assert.Equal(t, float64(1), eniCount)
}
Loading
Loading