Skip to content

Commit 75e1f71

Browse files
authored
[backport] - (#3776)(#3768) perf: update error message for MTPNC not found and not ready in CNS (#3775)
* fix: update network error msg to match kubelet expectations (#3768) update network error msg to match kubelet expectations Signed-off-by: GitHub <[email protected]> * fix: update error message for MTPNC not found and not ready in CNS (#3776) squash commit to prevent github CLA issue Signed-off-by: GitHub <[email protected]> --------- Signed-off-by: GitHub <[email protected]>
1 parent b5d7d2b commit 75e1f71

File tree

5 files changed

+287
-26
lines changed

5 files changed

+287
-26
lines changed

.devcontainer/devcontainer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@
5757
"postCreateCommand": "make setup",
5858
"remoteUser": "vscode",
5959
"features": {
60+
"ghcr.io/devcontainers/features/go:1": {
61+
"version": "1.23.2"
62+
},
6063
"docker-in-docker": "latest",
6164
"kubectl-helm-minikube": "latest",
6265
"git": "latest",

cns/middlewares/k8sSwiftV2.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package middlewares
22

33
import (
44
"context"
5-
"fmt"
65

76
"github.com/Azure/azure-container-networking/cns"
87
"github.com/Azure/azure-container-networking/cns/configuration"
@@ -13,11 +12,13 @@ import (
1312
"github.com/pkg/errors"
1413
v1 "k8s.io/api/core/v1"
1514
k8stypes "k8s.io/apimachinery/pkg/types"
15+
"k8s.io/kubernetes/pkg/kubelet"
1616
"sigs.k8s.io/controller-runtime/pkg/client"
1717
)
1818

1919
var (
20-
errMTPNCNotReady = errors.New("mtpnc is not ready")
20+
errMTPNCNotReady = errors.New(kubelet.NetworkNotReadyErrorMsg + " - mtpnc is not ready")
21+
errGetMTPNC = errors.New(kubelet.NetworkNotReadyErrorMsg + " - failed to get MTPNC")
2122
errInvalidSWIFTv2NICType = errors.New("invalid NIC type for SWIFT v2 scenario")
2223
errInvalidMTPNCPrefixLength = errors.New("invalid prefix length for MTPNC primaryIP, must be 32")
2324
)
@@ -72,7 +73,7 @@ func (k *K8sSWIFTv2Middleware) getIPConfig(ctx context.Context, podInfo cns.PodI
7273
mtpnc := v1alpha1.MultitenantPodNetworkConfig{}
7374
mtpncNamespacedName := k8stypes.NamespacedName{Namespace: podInfo.Namespace(), Name: podInfo.Name()}
7475
if err := k.Cli.Get(ctx, mtpncNamespacedName, &mtpnc); err != nil {
75-
return nil, errors.Wrapf(err, "failed to get pod's mtpnc from cache")
76+
return nil, errors.Wrap(err, errGetMTPNC.Error())
7677
}
7778

7879
// Check if the MTPNC CRD is ready. If one of the fields is empty, return error
@@ -190,7 +191,7 @@ func (k *K8sSWIFTv2Middleware) getMTPNC(ctx context.Context, podInfo cns.PodInfo
190191
mtpnc := v1alpha1.MultitenantPodNetworkConfig{}
191192
mtpncNamespacedName := k8stypes.NamespacedName{Namespace: podInfo.Namespace(), Name: podInfo.Name()}
192193
if err := k.Cli.Get(ctx, mtpncNamespacedName, &mtpnc); err != nil {
193-
return v1alpha1.MultitenantPodNetworkConfig{}, types.UnexpectedError, fmt.Errorf("failed to get pod's mtpnc from cache : %w", err).Error()
194+
return v1alpha1.MultitenantPodNetworkConfig{}, types.UnexpectedError, errors.Wrap(err, errGetMTPNC.Error()).Error()
194195
}
195196
// Check if the MTPNC CRD is ready. If one of the fields is empty, return error
196197
if !mtpnc.IsReady() {

cns/middlewares/k8sSwiftV2_linux_test.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package middlewares
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
7+
"strings"
68
"testing"
79

810
"github.com/Azure/azure-container-networking/cns"
@@ -13,6 +15,7 @@ import (
1315
"github.com/Azure/azure-container-networking/crd/multitenancy/api/v1alpha1"
1416
"github.com/google/go-cmp/cmp"
1517
"gotest.tools/v3/assert"
18+
"k8s.io/kubernetes/pkg/kubelet"
1619
)
1720

1821
var (
@@ -205,14 +208,16 @@ func TestValidateMultitenantIPConfigsRequestFailure(t *testing.T) {
205208
// Failed to get MTPNC
206209
b, _ = testPod3Info.OrchestratorContext()
207210
failReq.OrchestratorContext = b
208-
_, respCode, _ = middleware.GetPodInfoForIPConfigsRequest(context.TODO(), failReq)
211+
_, respCode, msg := middleware.GetPodInfoForIPConfigsRequest(context.TODO(), failReq)
209212
assert.Equal(t, respCode, types.UnexpectedError)
213+
assert.Assert(t, strings.Contains(msg, kubelet.NetworkNotReadyErrorMsg), "expected error message to contain '%s', got '%s'", kubelet.NetworkNotReadyErrorMsg, msg)
210214

211215
// MTPNC not ready
212216
b, _ = testPod4Info.OrchestratorContext()
213217
failReq.OrchestratorContext = b
214-
_, respCode, _ = middleware.GetPodInfoForIPConfigsRequest(context.TODO(), failReq)
218+
_, respCode, msg = middleware.GetPodInfoForIPConfigsRequest(context.TODO(), failReq)
215219
assert.Equal(t, respCode, types.UnexpectedError)
220+
assert.Assert(t, strings.Contains(msg, kubelet.NetworkNotReadyErrorMsg), "expected error message to contain '%s', got '%s'", kubelet.NetworkNotReadyErrorMsg, msg)
216221
}
217222

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

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

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

246253
func TestSetRoutesSuccess(t *testing.T) {

go.mod

Lines changed: 68 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ require (
4141
google.golang.org/grpc v1.73.0
4242
google.golang.org/protobuf v1.36.6
4343
gopkg.in/natefinch/lumberjack.v2 v2.2.1
44-
k8s.io/api v0.30.7
44+
k8s.io/api v0.30.14
4545
k8s.io/apiextensions-apiserver v0.30.1
46-
k8s.io/apimachinery v0.30.7
47-
k8s.io/client-go v0.30.7
46+
k8s.io/apimachinery v0.30.14
47+
k8s.io/client-go v0.30.14
4848
k8s.io/klog v1.0.0
4949
k8s.io/klog/v2 v2.130.1
5050
k8s.io/utils v0.0.0-20240310230437-4693a0247e57
@@ -131,16 +131,36 @@ require (
131131
golang.org/x/sync v0.15.0
132132
gotest.tools/v3 v3.5.2
133133
k8s.io/kubectl v0.28.5
134-
sigs.k8s.io/yaml v1.4.0
134+
k8s.io/kubernetes v1.30.7
135+
sigs.k8s.io/yaml v1.5.0
135136
)
136137

137138
require (
139+
cloud.google.com/go/compute/metadata v0.6.0 // indirect
140+
github.com/JeffAshton/win_pdh v0.0.0-20161109143554-76bb4ee9f0ab // indirect
141+
github.com/NYTimes/gziphandler v1.1.1 // indirect
142+
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230305170008-8188dc5388df // indirect
143+
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e // indirect
138144
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
139145
github.com/blang/semver/v4 v4.0.0 // indirect
140-
github.com/cilium/ebpf v0.12.3 // indirect
146+
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
147+
github.com/checkpoint-restore/go-criu/v6 v6.3.0 // indirect
148+
github.com/cilium/ebpf v0.16.0 // indirect
141149
github.com/cilium/proxy v0.0.0-20231202123106-38b645b854f3 // indirect
150+
github.com/container-storage-interface/spec v1.8.0 // indirect
151+
github.com/containerd/cgroups v1.1.0 // indirect
152+
github.com/containerd/console v1.0.4 // indirect
142153
github.com/containerd/errdefs/pkg v0.3.0 // indirect
154+
github.com/containerd/log v0.1.0 // indirect
155+
github.com/containerd/ttrpc v1.2.5 // indirect
143156
github.com/containerd/typeurl/v2 v2.2.0 // indirect
157+
github.com/coreos/go-semver v0.3.1 // indirect
158+
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
159+
github.com/cyphar/filepath-securejoin v0.3.5 // indirect
160+
github.com/distribution/reference v0.6.0 // indirect
161+
github.com/docker/go-units v0.5.0 // indirect
162+
github.com/euank/go-kmsg-parser v2.0.0+incompatible // indirect
163+
github.com/felixge/httpsnoop v1.0.4 // indirect
144164
github.com/go-logr/stdr v1.2.2 // indirect
145165
github.com/go-ole/go-ole v1.2.6 // indirect
146166
github.com/go-openapi/analysis v0.21.4 // indirect
@@ -151,30 +171,72 @@ require (
151171
github.com/go-openapi/strfmt v0.21.9 // indirect
152172
github.com/go-openapi/validate v0.22.3 // indirect
153173
github.com/go-viper/mapstructure/v2 v2.3.0 // indirect
174+
github.com/godbus/dbus/v5 v5.1.0 // indirect
175+
github.com/google/cadvisor v0.49.0 // indirect
176+
github.com/google/cel-go v0.17.8 // indirect
154177
github.com/google/gopacket v1.1.19 // indirect
155178
github.com/gorilla/websocket v1.5.1 // indirect
179+
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
180+
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
156181
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
182+
github.com/karrick/godirwalk v1.17.0 // indirect
157183
github.com/kr/pretty v0.3.1 // indirect
158184
github.com/kr/text v0.2.0 // indirect
159185
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
186+
github.com/mistifyio/go-zfs v2.1.2-0.20190413222219-f784269be439+incompatible // indirect
187+
github.com/moby/sys/mountinfo v0.7.1 // indirect
188+
github.com/moby/sys/user v0.3.0 // indirect
189+
github.com/moby/sys/userns v0.1.0 // indirect
190+
github.com/mrunalp/fileutils v0.5.1 // indirect
160191
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
161192
github.com/oklog/ulid v1.3.1 // indirect
193+
github.com/opencontainers/go-digest v1.0.0 // indirect
194+
github.com/opencontainers/runc v1.2.3 // indirect
195+
github.com/opencontainers/runtime-spec v1.2.0 // indirect
196+
github.com/opencontainers/selinux v1.11.0 // indirect
162197
github.com/opentracing/opentracing-go v1.2.1-0.20220228012449-10b1cf09e00b // indirect
163198
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect
164199
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
165200
github.com/rogpeppe/go-internal v1.13.1 // indirect
166201
github.com/sasha-s/go-deadlock v0.3.1 // indirect
202+
github.com/seccomp/libseccomp-golang v0.10.0 // indirect
167203
github.com/shirou/gopsutil/v3 v3.23.5 // indirect
204+
github.com/stoewer/go-strcase v1.2.0 // indirect
205+
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 // indirect
168206
github.com/tklauser/go-sysconf v0.3.11 // indirect
169207
github.com/tklauser/numcpus v0.6.0 // indirect
170208
github.com/yusufpapurcu/wmi v1.2.3 // indirect
209+
go.etcd.io/etcd/api/v3 v3.5.11 // indirect
210+
go.etcd.io/etcd/client/pkg/v3 v3.5.11 // indirect
211+
go.etcd.io/etcd/client/v3 v3.5.11 // indirect
171212
go.mongodb.org/mongo-driver v1.13.1 // indirect
172213
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
214+
go.opentelemetry.io/contrib/instrumentation/github.com/emicklei/go-restful/otelrestful v0.42.0 // indirect
215+
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.54.0 // indirect
216+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 // indirect
173217
go.opentelemetry.io/otel v1.35.0 // indirect
218+
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0 // indirect
219+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.19.0 // indirect
174220
go.opentelemetry.io/otel/metric v1.35.0 // indirect
221+
go.opentelemetry.io/otel/sdk v1.35.0 // indirect
175222
go.opentelemetry.io/otel/trace v1.35.0 // indirect
223+
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
176224
go.uber.org/dig v1.17.1 // indirect
225+
go.yaml.in/yaml/v2 v2.4.2 // indirect
177226
go4.org/netipx v0.0.0-20231129151722-fdeea329fbba // indirect
227+
google.golang.org/genproto/googleapis/api v0.0.0-20250324211829-b45e905df463 // indirect
228+
k8s.io/apiserver v0.30.14 // indirect
229+
k8s.io/cloud-provider v0.30.7 // indirect
230+
k8s.io/component-base v0.30.14 // indirect
231+
k8s.io/component-helpers v0.30.7 // indirect
232+
k8s.io/controller-manager v0.30.7 // indirect
233+
k8s.io/cri-api v0.30.14 // indirect
234+
k8s.io/csi-translation-lib v0.30.14 // indirect
235+
k8s.io/dynamic-resource-allocation v0.30.14 // indirect
236+
k8s.io/kms v0.30.14 // indirect
237+
k8s.io/kube-scheduler v0.30.14 // indirect
238+
k8s.io/mount-utils v0.30.14 // indirect
239+
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.29.0 // indirect
178240
)
179241

180242
require (
@@ -184,7 +246,7 @@ require (
184246
github.com/golang-jwt/jwt/v5 v5.2.2 // indirect
185247
github.com/sagikazarmark/locafero v0.7.0 // indirect
186248
github.com/sourcegraph/conc v0.3.0 // indirect
187-
k8s.io/kubelet v0.30.7
249+
k8s.io/kubelet v0.30.14
188250
)
189251

190252
replace (

0 commit comments

Comments
 (0)