Skip to content

Commit a1b90ca

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

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
@@ -275,7 +275,7 @@ func (service *HTTPRestService) syncHostNCVersion(ctx context.Context, channelMo
275275

276276
// This API will be called by CNS RequestController on CRD update.
277277
func (service *HTTPRestService) ReconcileNCState(ncRequest *cns.CreateNetworkContainerRequest, podInfoByIP map[string]cns.PodInfo, nnc *v1alpha.NodeNetworkConfig) types.ResponseCode {
278-
logger.Printf("Reconciling NC state with podInfo %+v", podInfoByIP)
278+
logger.Printf("Reconciling NC state with CreateNCRequest: [%v], PodInfo [%+v], NNC: [%+v]", ncRequest, podInfoByIP, nnc)
279279
// check if ncRequest is null, then return as there is no CRD state yet
280280
if ncRequest == nil {
281281
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"
@@ -998,28 +999,21 @@ func reconcileInitialCNSState(ctx context.Context, cli nodeNetworkConfigGetter,
998999
// Get nnc using direct client
9991000
nnc, err := cli.Get(ctx)
10001001
if err != nil {
1001-
10021002
if crd.IsNotDefined(err) {
1003-
return errors.Wrap(err, "failed to get NNC during init CNS state")
1003+
return errors.Wrap(err, "failed to init CNS state: NNC CRD is not defined")
10041004
}
1005-
1006-
// If instance of crd is not found, pass nil to CNSClient
1007-
if client.IgnoreNotFound(err) == nil {
1008-
err = restserver.ResponseCodeToError(ncReconciler.ReconcileNCState(nil, nil, nnc))
1009-
return errors.Wrap(err, "failed to reconcile NC state")
1005+
if apierrors.IsNotFound(err) {
1006+
return errors.Wrap(err, "failed to init CNS state: NNC not found")
10101007
}
1011-
1012-
// If it's any other error, log it and return
1013-
return errors.Wrap(err, "error getting NodeNetworkConfig when initializing CNS state")
1008+
return errors.Wrap(err, "failed to init CNS state: failed to get NNC CRD")
10141009
}
10151010

1016-
// If there are no NCs, pass nil to CNSClient
1011+
// If there are no NCs, we can't initialize our state and we should fail out.
10171012
if len(nnc.Status.NetworkContainers) == 0 {
1018-
err = restserver.ResponseCodeToError(ncReconciler.ReconcileNCState(nil, nil, nnc))
1019-
return errors.Wrap(err, "failed to reconcile NC state")
1013+
return errors.Wrap(err, "failed to init CNS state: no NCs found in NNC CRD")
10201014
}
10211015

1022-
// Convert to CreateNetworkContainerRequest
1016+
// For each NC, we need to create a CreateNetworkContainerRequest and use it to rebuild our state.
10231017
for i := range nnc.Status.NetworkContainers {
10241018
var ncRequest *cns.CreateNetworkContainerRequest
10251019
var err error
@@ -1035,8 +1029,7 @@ func reconcileInitialCNSState(ctx context.Context, cli nodeNetworkConfigGetter,
10351029
return errors.Wrapf(err, "failed to convert NNC status to network container request, "+
10361030
"assignmentMode: %s", nnc.Status.NetworkContainers[i].AssignmentMode)
10371031
}
1038-
1039-
// rebuild CNS state
1032+
// Get previous PodInfo state from podInfoByIPProvider
10401033
podInfoByIP, err := podInfoByIPProvider.PodInfoByIP()
10411034
if err != nil {
10421035
return errors.Wrap(err, "provider failed to provide PodInfoByIP")

0 commit comments

Comments
 (0)