Skip to content
Closed
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
10 changes: 7 additions & 3 deletions cns/deviceplugin/pluginmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,17 @@ func TestPluginManagerStartStop(t *testing.T) {
req := &v1beta1.AllocateRequest{
ContainerRequests: []*v1beta1.ContainerAllocateRequest{
{
DevicesIDs: []string{"device-0", "device-1"},
DevicesIds: []string{"device-0", "device-1"},
},
},
}
allocateResp := getAllocateResponse(t, vnetPluginEndpoint, req)

if len(allocateResp.ContainerResponses[0].Envs) != len(req.ContainerRequests[0].DevicesIDs) {
t.Fatalf("expected allocations %v but received allocations %v", len(req.ContainerRequests[0].DevicesIDs), len(allocateResp.ContainerResponses[0].Envs))
if len(allocateResp.GetContainerResponses()[0].GetEnvs()) !=
len(req.GetContainerRequests()[0].GetDevicesIds()) {
t.Fatalf("expected allocations %v but received allocations %v",
len(req.GetContainerRequests()[0].GetDevicesIds()),
len(allocateResp.GetContainerResponses()[0].GetEnvs()))
}

// call getDevicePluginOptions method
Expand Down Expand Up @@ -142,6 +145,7 @@ func TestPluginManagerStartStop(t *testing.T) {
}

type fakeKubelet struct {
v1beta1.UnimplementedRegistrationServer
vnetPluginRegisterChan chan string
ibPluginRegisterChan chan string
pluginPrefix string
Expand Down
5 changes: 3 additions & 2 deletions cns/deviceplugin/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type deviceCounter interface {
}

type Server struct {
v1beta1.UnimplementedDevicePluginServer
address string
logger *zap.Logger
deviceCounter deviceCounter
Expand Down Expand Up @@ -94,8 +95,8 @@ func (s *Server) Allocate(_ context.Context, req *v1beta1.AllocateRequest) (*v1b
resp := &v1beta1.ContainerAllocateResponse{
Envs: make(map[string]string),
}
for j := range containerReq.DevicesIDs {
resp.Envs[fmt.Sprintf("%s%d", devicePrefix, j)] = containerReq.DevicesIDs[j]
for j, id := range containerReq.GetDevicesIds() {
resp.GetEnvs()[fmt.Sprintf("%s%d", devicePrefix, j)] = id
}
resps[i] = resp
}
Expand Down
16 changes: 8 additions & 8 deletions cns/middlewares/k8sSwiftV2.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@
"github.com/pkg/errors"
v1 "k8s.io/api/core/v1"
k8stypes "k8s.io/apimachinery/pkg/types"
"k8s.io/kubernetes/pkg/kubelet"
"sigs.k8s.io/controller-runtime/pkg/client"
)

var (
errMTPNCNotReady = errors.New(kubelet.NetworkNotReadyErrorMsg + " - mtpnc is not ready")
errGetMTPNC = errors.New(kubelet.NetworkNotReadyErrorMsg + " - failed to get MTPNC")
errInvalidSWIFTv2NICType = errors.New("invalid NIC type for SWIFT v2 scenario")
errInvalidMTPNCPrefixLength = errors.New("invalid prefix length for MTPNC primaryIP, must be 32")
)

const (
NetworkNotReadyErrorMsg = "network is not ready"
prefixLength = 32
overlayGatewayv4 = "169.254.1.1"
virtualGW = "169.254.2.1"
overlayGatewayV6 = "fe80::1234:5678:9abc"
)

var (
errMTPNCNotReady = errors.New(NetworkNotReadyErrorMsg + " - mtpnc is not ready")
errGetMTPNC = errors.New(NetworkNotReadyErrorMsg + " - failed to get MTPNC")
errInvalidSWIFTv2NICType = errors.New("invalid NIC type for SWIFT v2 scenario")

Check failure on line 29 in cns/middlewares/k8sSwiftV2.go

View workflow job for this annotation

GitHub Actions / Lint (windows-latest)

var `errInvalidSWIFTv2NICType` is unused (unused)
errInvalidMTPNCPrefixLength = errors.New("invalid prefix length for MTPNC primaryIP, must be 32")
)

type K8sSWIFTv2Middleware struct {
Cli client.Client
}
Expand Down
9 changes: 4 additions & 5 deletions cns/middlewares/k8sSwiftV2_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/Azure/azure-container-networking/crd/multitenancy/api/v1alpha1"
"github.com/google/go-cmp/cmp"
"gotest.tools/v3/assert"
"k8s.io/kubernetes/pkg/kubelet"
)

var (
Expand Down Expand Up @@ -210,14 +209,14 @@ func TestValidateMultitenantIPConfigsRequestFailure(t *testing.T) {
failReq.OrchestratorContext = b
_, respCode, msg := middleware.GetPodInfoForIPConfigsRequest(context.TODO(), failReq)
assert.Equal(t, respCode, types.UnexpectedError)
assert.Assert(t, strings.Contains(msg, kubelet.NetworkNotReadyErrorMsg), "expected error message to contain '%s', got '%s'", kubelet.NetworkNotReadyErrorMsg, msg)
assert.Assert(t, strings.Contains(msg, NetworkNotReadyErrorMsg), "expected error message to contain '%s', got '%s'", NetworkNotReadyErrorMsg, msg)

// MTPNC not ready
b, _ = testPod4Info.OrchestratorContext()
failReq.OrchestratorContext = b
_, respCode, msg = middleware.GetPodInfoForIPConfigsRequest(context.TODO(), failReq)
assert.Equal(t, respCode, types.UnexpectedError)
assert.Assert(t, strings.Contains(msg, kubelet.NetworkNotReadyErrorMsg), "expected error message to contain '%s', got '%s'", kubelet.NetworkNotReadyErrorMsg, msg)
assert.Assert(t, strings.Contains(msg, NetworkNotReadyErrorMsg), "expected error message to contain '%s', got '%s'", NetworkNotReadyErrorMsg, msg)
}

func TestGetSWIFTv2IPConfigSuccess(t *testing.T) {
Expand All @@ -242,12 +241,12 @@ func TestGetSWIFTv2IPConfigFailure(t *testing.T) {
// Pod's MTPNC doesn't exist in cache test
_, err := middleware.getIPConfig(context.TODO(), testPod3Info)
assert.Assert(t, strings.Contains(err.Error(), errGetMTPNC.Error()), "expected error to wrap errMTPNCNotFound, got: %v", err)
assert.ErrorContains(t, err, kubelet.NetworkNotReadyErrorMsg)
assert.ErrorContains(t, err, NetworkNotReadyErrorMsg)

// Pod's MTPNC is not ready test
_, err = middleware.getIPConfig(context.TODO(), testPod4Info)
assert.Assert(t, errors.Is(err, errMTPNCNotReady), "expected error to wrap errMTPNCNotReady, got: %v", err)
assert.ErrorContains(t, err, kubelet.NetworkNotReadyErrorMsg)
assert.ErrorContains(t, err, NetworkNotReadyErrorMsg)
}

func TestSetRoutesSuccess(t *testing.T) {
Expand Down
Loading
Loading