fix notfound error for multitenantnetworkcontainer
This commit is contained in:
Родитель
25daa48b30
Коммит
b85e611e46
|
@ -52,7 +52,7 @@ func (client *Client) GetNC(req cns.GetNetworkContainerRequest) (cns.GetNetworkC
|
|||
resp, returnCode := client.RestService.GetNetworkContainerInternal(req)
|
||||
if returnCode != 0 {
|
||||
if returnCode == types.UnknownContainerID {
|
||||
return resp, errors.New("containerID not found")
|
||||
return resp, errors.New(returnCode.String())
|
||||
}
|
||||
return resp, errors.Errorf("failed to get NC, request: %+v, errorCode: %d", req, returnCode)
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/Azure/azure-container-networking/cns"
|
||||
"github.com/Azure/azure-container-networking/cns/cnsclient"
|
||||
"github.com/Azure/azure-container-networking/cns/logger"
|
||||
"github.com/Azure/azure-container-networking/cns/types"
|
||||
ncapi "github.com/Azure/azure-container-networking/crds/multitenantnetworkcontainer/api/v1alpha1"
|
||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
|
@ -103,7 +104,7 @@ func (r *multiTenantCrdReconciler) Reconcile(ctx context.Context, request reconc
|
|||
if err == nil {
|
||||
logger.Printf("NC %s (UUID: %s) has already been created in CNS", request.NamespacedName.String(), nc.Spec.UUID)
|
||||
return ctrl.Result{}, nil
|
||||
} else if err.Error() != "NotFound" {
|
||||
} else if !strings.EqualFold(err.Error(), types.UnknownContainerID.String()) {
|
||||
logger.Errorf("Failed to fetch NC %s (UUID: %s) from CNS: %v", request.NamespacedName.String(), nc.Spec.UUID, err)
|
||||
return ctrl.Result{}, err
|
||||
}
|
||||
|
|
|
@ -3,11 +3,12 @@ package multitenantoperator
|
|||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"errors"
|
||||
|
||||
"github.com/Azure/azure-container-networking/cns"
|
||||
"github.com/Azure/azure-container-networking/cns/logger"
|
||||
"github.com/Azure/azure-container-networking/cns/multitenantcontroller/mockclients"
|
||||
cnstypes "github.com/Azure/azure-container-networking/cns/types"
|
||||
ncapi "github.com/Azure/azure-container-networking/crds/multitenantnetworkcontainer/api/v1alpha1"
|
||||
"github.com/golang/mock/gomock"
|
||||
. "github.com/onsi/ginkgo"
|
||||
|
@ -18,17 +19,20 @@ import (
|
|||
"sigs.k8s.io/controller-runtime/pkg/reconcile"
|
||||
)
|
||||
|
||||
var errContainerIDNotFound = errors.New(cnstypes.UnknownContainerID.String())
|
||||
|
||||
var _ = Describe("multiTenantCrdReconciler", func() {
|
||||
var kubeClient *mockclients.MockClient
|
||||
var cnsClient *mockclients.MockAPIClient
|
||||
var mockCtl *gomock.Controller
|
||||
var reconciler *multiTenantCrdReconciler
|
||||
var mockNodeName = "mockNodeName"
|
||||
var namespacedName = types.NamespacedName{
|
||||
const uuidValue = "uuid"
|
||||
mockNodeName := "mockNodeName"
|
||||
namespacedName := types.NamespacedName{
|
||||
Namespace: "test",
|
||||
Name: "test",
|
||||
}
|
||||
var podInfo = cns.KubernetesPodInfo{
|
||||
podInfo := cns.KubernetesPodInfo{
|
||||
PodName: namespacedName.Name,
|
||||
PodNamespace: namespacedName.Namespace,
|
||||
}
|
||||
|
@ -46,7 +50,6 @@ var _ = Describe("multiTenantCrdReconciler", func() {
|
|||
})
|
||||
|
||||
Context("lifecycle", func() {
|
||||
|
||||
It("Should succeed when the NC has already been deleted", func() {
|
||||
expectedError := &apierrors.StatusError{
|
||||
ErrStatus: metav1.Status{
|
||||
|
@ -104,7 +107,7 @@ var _ = Describe("multiTenantCrdReconciler", func() {
|
|||
})
|
||||
|
||||
It("Should succeed when the NC is in Initialized state and it has already been persisted in CNS", func() {
|
||||
var uuid = "uuid"
|
||||
uuid := uuidValue
|
||||
var nc ncapi.MultiTenantNetworkContainer = ncapi.MultiTenantNetworkContainer{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: namespacedName.Name,
|
||||
|
@ -137,7 +140,7 @@ var _ = Describe("multiTenantCrdReconciler", func() {
|
|||
})
|
||||
|
||||
It("Should fail when the NC subnet isn't in correct format", func() {
|
||||
var uuid = "uuid"
|
||||
uuid := uuidValue
|
||||
var nc ncapi.MultiTenantNetworkContainer = ncapi.MultiTenantNetworkContainer{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: namespacedName.Name,
|
||||
|
@ -163,7 +166,7 @@ var _ = Describe("multiTenantCrdReconciler", func() {
|
|||
cnsClient.EXPECT().GetNC(cns.GetNetworkContainerRequest{
|
||||
NetworkContainerid: uuid,
|
||||
OrchestratorContext: orchestratorContext,
|
||||
}).Return(cns.GetNetworkContainerResponse{}, fmt.Errorf("NotFound"))
|
||||
}).Return(cns.GetNetworkContainerResponse{}, errContainerIDNotFound)
|
||||
_, err = reconciler.Reconcile(context.TODO(), reconcile.Request{
|
||||
NamespacedName: namespacedName,
|
||||
})
|
||||
|
@ -172,7 +175,7 @@ var _ = Describe("multiTenantCrdReconciler", func() {
|
|||
})
|
||||
|
||||
It("Should succeed when the NC subnet is in correct format", func() {
|
||||
var uuid = "uuid"
|
||||
uuid := uuidValue
|
||||
var nc ncapi.MultiTenantNetworkContainer = ncapi.MultiTenantNetworkContainer{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: namespacedName.Name,
|
||||
|
@ -196,7 +199,7 @@ var _ = Describe("multiTenantCrdReconciler", func() {
|
|||
PodNamespace: namespacedName.Namespace,
|
||||
})
|
||||
Expect(err).To(BeNil())
|
||||
var networkContainerRequest = cns.CreateNetworkContainerRequest{
|
||||
networkContainerRequest := cns.CreateNetworkContainerRequest{
|
||||
NetworkContainerid: nc.Spec.UUID,
|
||||
NetworkContainerType: cns.Kubernetes,
|
||||
OrchestratorContext: orchestratorContext,
|
||||
|
@ -221,7 +224,7 @@ var _ = Describe("multiTenantCrdReconciler", func() {
|
|||
cnsClient.EXPECT().GetNC(cns.GetNetworkContainerRequest{
|
||||
NetworkContainerid: uuid,
|
||||
OrchestratorContext: orchestratorContext,
|
||||
}).Return(cns.GetNetworkContainerResponse{}, fmt.Errorf("NotFound"))
|
||||
}).Return(cns.GetNetworkContainerResponse{}, errContainerIDNotFound)
|
||||
cnsClient.EXPECT().CreateOrUpdateNC(networkContainerRequest).Return(nil)
|
||||
_, err = reconciler.Reconcile(context.TODO(), reconcile.Request{
|
||||
NamespacedName: namespacedName,
|
||||
|
|
Загрузка…
Ссылка в новой задаче