Skip to content

Commit c48c3e1

Browse files
authored
fix: CNS init must have an NC (#2030)
Signed-off-by: Evan Baker <[email protected]>
1 parent 175a1f6 commit c48c3e1

File tree

2 files changed

+10
-17
lines changed

2 files changed

+10
-17
lines changed

cns/restserver/internalapi.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ func (service *HTTPRestService) syncHostNCVersion(ctx context.Context, channelMo
276276

277277
// This API will be called by CNS RequestController on CRD update.
278278
func (service *HTTPRestService) ReconcileNCState(ncRequest *cns.CreateNetworkContainerRequest, podInfoByIP map[string]cns.PodInfo, nnc *v1alpha.NodeNetworkConfig) types.ResponseCode {
279-
logger.Printf("Reconciling NC state with podInfo %+v", podInfoByIP)
279+
logger.Printf("Reconciling NC state with CreateNCRequest: [%v], PodInfo [%+v], NNC: [%+v]", ncRequest, podInfoByIP, nnc)
280280
// check if ncRequest is null, then return as there is no CRD state yet
281281
if ncRequest == nil {
282282
logger.Printf("CNS starting with no NC state, podInfoMap count %d", len(podInfoByIP))

cns/service/main.go

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import (
5454
"github.com/avast/retry-go/v3"
5555
"github.com/pkg/errors"
5656
"go.uber.org/zap"
57+
apierrors "k8s.io/apimachinery/pkg/api/errors"
5758
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
5859
"k8s.io/apimachinery/pkg/fields"
5960
kuberuntime "k8s.io/apimachinery/pkg/runtime"
@@ -1022,28 +1023,21 @@ func reconcileInitialCNSState(ctx context.Context, cli nodeNetworkConfigGetter,
10221023
// Get nnc using direct client
10231024
nnc, err := cli.Get(ctx)
10241025
if err != nil {
1025-
10261026
if crd.IsNotDefined(err) {
1027-
return errors.Wrap(err, "failed to get NNC during init CNS state")
1027+
return errors.Wrap(err, "failed to init CNS state: NNC CRD is not defined")
10281028
}
1029-
1030-
// If instance of crd is not found, pass nil to CNSClient
1031-
if client.IgnoreNotFound(err) == nil {
1032-
err = restserver.ResponseCodeToError(ncReconciler.ReconcileNCState(nil, nil, nnc))
1033-
return errors.Wrap(err, "failed to reconcile NC state")
1029+
if apierrors.IsNotFound(err) {
1030+
return errors.Wrap(err, "failed to init CNS state: NNC not found")
10341031
}
1035-
1036-
// If it's any other error, log it and return
1037-
return errors.Wrap(err, "error getting NodeNetworkConfig when initializing CNS state")
1032+
return errors.Wrap(err, "failed to init CNS state: failed to get NNC CRD")
10381033
}
10391034

1040-
// If there are no NCs, pass nil to CNSClient
1035+
// If there are no NCs, we can't initialize our state and we should fail out.
10411036
if len(nnc.Status.NetworkContainers) == 0 {
1042-
err = restserver.ResponseCodeToError(ncReconciler.ReconcileNCState(nil, nil, nnc))
1043-
return errors.Wrap(err, "failed to reconcile NC state")
1037+
return errors.Wrap(err, "failed to init CNS state: no NCs found in NNC CRD")
10441038
}
10451039

1046-
// Convert to CreateNetworkContainerRequest
1040+
// For each NC, we need to create a CreateNetworkContainerRequest and use it to rebuild our state.
10471041
for i := range nnc.Status.NetworkContainers {
10481042
var ncRequest *cns.CreateNetworkContainerRequest
10491043
var err error
@@ -1059,8 +1053,7 @@ func reconcileInitialCNSState(ctx context.Context, cli nodeNetworkConfigGetter,
10591053
return errors.Wrapf(err, "failed to convert NNC status to network container request, "+
10601054
"assignmentMode: %s", nnc.Status.NetworkContainers[i].AssignmentMode)
10611055
}
1062-
1063-
// rebuild CNS state
1056+
// Get previous PodInfo state from podInfoByIPProvider
10641057
podInfoByIP, err := podInfoByIPProvider.PodInfoByIP()
10651058
if err != nil {
10661059
return errors.Wrap(err, "provider failed to provide PodInfoByIP")

0 commit comments

Comments
 (0)