Skip to content
Merged
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
3 changes: 3 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
"postCreateCommand": "make setup",
"remoteUser": "vscode",
"features": {
"ghcr.io/devcontainers/features/go:1": {
"version": "1.23.2"
},
"docker-in-docker": "latest",
"kubectl-helm-minikube": "latest",
"git": "latest",
Expand Down
9 changes: 5 additions & 4 deletions cns/middlewares/k8sSwiftV2.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package middlewares

import (
"context"
"fmt"

"github.com/Azure/azure-container-networking/cns"
"github.com/Azure/azure-container-networking/cns/configuration"
Expand All @@ -13,11 +12,13 @@ import (
"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("mtpnc is not ready")
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")
)
Expand Down Expand Up @@ -72,7 +73,7 @@ func (k *K8sSWIFTv2Middleware) getIPConfig(ctx context.Context, podInfo cns.PodI
mtpnc := v1alpha1.MultitenantPodNetworkConfig{}
mtpncNamespacedName := k8stypes.NamespacedName{Namespace: podInfo.Namespace(), Name: podInfo.Name()}
if err := k.Cli.Get(ctx, mtpncNamespacedName, &mtpnc); err != nil {
return nil, errors.Wrapf(err, "failed to get pod's mtpnc from cache")
return nil, errors.Wrap(err, errGetMTPNC.Error())
}

// Check if the MTPNC CRD is ready. If one of the fields is empty, return error
Expand Down Expand Up @@ -190,7 +191,7 @@ func (k *K8sSWIFTv2Middleware) getMTPNC(ctx context.Context, podInfo cns.PodInfo
mtpnc := v1alpha1.MultitenantPodNetworkConfig{}
mtpncNamespacedName := k8stypes.NamespacedName{Namespace: podInfo.Namespace(), Name: podInfo.Name()}
if err := k.Cli.Get(ctx, mtpncNamespacedName, &mtpnc); err != nil {
return v1alpha1.MultitenantPodNetworkConfig{}, types.UnexpectedError, fmt.Errorf("failed to get pod's mtpnc from cache : %w", err).Error()
return v1alpha1.MultitenantPodNetworkConfig{}, types.UnexpectedError, errors.Wrap(err, errGetMTPNC.Error()).Error()
}
// Check if the MTPNC CRD is ready. If one of the fields is empty, return error
if !mtpnc.IsReady() {
Expand Down
15 changes: 11 additions & 4 deletions cns/middlewares/k8sSwiftV2_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package middlewares

import (
"context"
"errors"
"fmt"
"strings"
"testing"

"github.com/Azure/azure-container-networking/cns"
Expand All @@ -13,6 +15,7 @@ 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 @@ -205,14 +208,16 @@ func TestValidateMultitenantIPConfigsRequestFailure(t *testing.T) {
// Failed to get MTPNC
b, _ = testPod3Info.OrchestratorContext()
failReq.OrchestratorContext = b
_, respCode, _ = middleware.GetPodInfoForIPConfigsRequest(context.TODO(), failReq)
_, 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)

// MTPNC not ready
b, _ = testPod4Info.OrchestratorContext()
failReq.OrchestratorContext = b
_, respCode, _ = middleware.GetPodInfoForIPConfigsRequest(context.TODO(), failReq)
_, 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)
}

func TestGetSWIFTv2IPConfigSuccess(t *testing.T) {
Expand All @@ -236,11 +241,13 @@ func TestGetSWIFTv2IPConfigFailure(t *testing.T) {

// Pod's MTPNC doesn't exist in cache test
_, err := middleware.getIPConfig(context.TODO(), testPod3Info)
assert.ErrorContains(t, err, mock.ErrMTPNCNotFound.Error())
assert.Assert(t, strings.Contains(err.Error(), errGetMTPNC.Error()), "expected error to wrap errMTPNCNotFound, got: %v", err)
assert.ErrorContains(t, err, kubelet.NetworkNotReadyErrorMsg)

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

func TestSetRoutesSuccess(t *testing.T) {
Expand Down
74 changes: 68 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ require (
google.golang.org/grpc v1.73.0
google.golang.org/protobuf v1.36.6
gopkg.in/natefinch/lumberjack.v2 v2.2.1
k8s.io/api v0.30.7
k8s.io/api v0.30.14
k8s.io/apiextensions-apiserver v0.30.1
k8s.io/apimachinery v0.30.7
k8s.io/client-go v0.30.7
k8s.io/apimachinery v0.30.14
k8s.io/client-go v0.30.14
k8s.io/klog v1.0.0
k8s.io/klog/v2 v2.130.1
k8s.io/utils v0.0.0-20240310230437-4693a0247e57
Expand Down Expand Up @@ -131,16 +131,36 @@ require (
golang.org/x/sync v0.15.0
gotest.tools/v3 v3.5.2
k8s.io/kubectl v0.28.5
sigs.k8s.io/yaml v1.4.0
k8s.io/kubernetes v1.30.7
sigs.k8s.io/yaml v1.5.0
)

require (
cloud.google.com/go/compute/metadata v0.6.0 // indirect
github.com/JeffAshton/win_pdh v0.0.0-20161109143554-76bb4ee9f0ab // indirect
github.com/NYTimes/gziphandler v1.1.1 // indirect
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230305170008-8188dc5388df // indirect
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e // indirect
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/cilium/ebpf v0.12.3 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/checkpoint-restore/go-criu/v6 v6.3.0 // indirect
github.com/cilium/ebpf v0.16.0 // indirect
github.com/cilium/proxy v0.0.0-20231202123106-38b645b854f3 // indirect
github.com/container-storage-interface/spec v1.8.0 // indirect
github.com/containerd/cgroups v1.1.0 // indirect
github.com/containerd/console v1.0.4 // indirect
github.com/containerd/errdefs/pkg v0.3.0 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/containerd/ttrpc v1.2.5 // indirect
github.com/containerd/typeurl/v2 v2.2.0 // indirect
github.com/coreos/go-semver v0.3.1 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/cyphar/filepath-securejoin v0.3.5 // indirect
github.com/distribution/reference v0.6.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/euank/go-kmsg-parser v2.0.0+incompatible // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-openapi/analysis v0.21.4 // indirect
Expand All @@ -151,30 +171,72 @@ require (
github.com/go-openapi/strfmt v0.21.9 // indirect
github.com/go-openapi/validate v0.22.3 // indirect
github.com/go-viper/mapstructure/v2 v2.3.0 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/google/cadvisor v0.49.0 // indirect
github.com/google/cel-go v0.17.8 // indirect
github.com/google/gopacket v1.1.19 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/karrick/godirwalk v1.17.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/mistifyio/go-zfs v2.1.2-0.20190413222219-f784269be439+incompatible // indirect
github.com/moby/sys/mountinfo v0.7.1 // indirect
github.com/moby/sys/user v0.3.0 // indirect
github.com/moby/sys/userns v0.1.0 // indirect
github.com/mrunalp/fileutils v0.5.1 // indirect
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/runc v1.2.3 // indirect
github.com/opencontainers/runtime-spec v1.2.0 // indirect
github.com/opencontainers/selinux v1.11.0 // indirect
github.com/opentracing/opentracing-go v1.2.1-0.20220228012449-10b1cf09e00b // indirect
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/rogpeppe/go-internal v1.13.1 // indirect
github.com/sasha-s/go-deadlock v0.3.1 // indirect
github.com/seccomp/libseccomp-golang v0.10.0 // indirect
github.com/shirou/gopsutil/v3 v3.23.5 // indirect
github.com/stoewer/go-strcase v1.2.0 // indirect
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 // indirect
github.com/tklauser/go-sysconf v0.3.11 // indirect
github.com/tklauser/numcpus v0.6.0 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
go.etcd.io/etcd/api/v3 v3.5.11 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.11 // indirect
go.etcd.io/etcd/client/v3 v3.5.11 // indirect
go.mongodb.org/mongo-driver v1.13.1 // indirect
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
go.opentelemetry.io/contrib/instrumentation/github.com/emicklei/go-restful/otelrestful v0.42.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.54.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 // indirect
go.opentelemetry.io/otel v1.35.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.19.0 // indirect
go.opentelemetry.io/otel/metric v1.35.0 // indirect
go.opentelemetry.io/otel/sdk v1.35.0 // indirect
go.opentelemetry.io/otel/trace v1.35.0 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
go.uber.org/dig v1.17.1 // indirect
go.yaml.in/yaml/v2 v2.4.2 // indirect
go4.org/netipx v0.0.0-20231129151722-fdeea329fbba // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20250324211829-b45e905df463 // indirect
k8s.io/apiserver v0.30.14 // indirect
k8s.io/cloud-provider v0.30.7 // indirect
k8s.io/component-base v0.30.14 // indirect
k8s.io/component-helpers v0.30.7 // indirect
k8s.io/controller-manager v0.30.7 // indirect
k8s.io/cri-api v0.30.14 // indirect
k8s.io/csi-translation-lib v0.30.14 // indirect
k8s.io/dynamic-resource-allocation v0.30.14 // indirect
k8s.io/kms v0.30.14 // indirect
k8s.io/kube-scheduler v0.30.14 // indirect
k8s.io/mount-utils v0.30.14 // indirect
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.29.0 // indirect
)

require (
Expand All @@ -184,7 +246,7 @@ require (
github.com/golang-jwt/jwt/v5 v5.2.2 // indirect
github.com/sagikazarmark/locafero v0.7.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
k8s.io/kubelet v0.30.7
k8s.io/kubelet v0.30.14
)

replace (
Expand Down
Loading
Loading