Skip to content

Commit

Permalink
fix: CNS init must have an NC (#2030)
Browse files Browse the repository at this point in the history
Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>
  • Loading branch information
rbtr committed Jun 23, 2023
1 parent fa2cbef commit a1b90ca
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
2 changes: 1 addition & 1 deletion cns/restserver/internalapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func (service *HTTPRestService) syncHostNCVersion(ctx context.Context, channelMo

// This API will be called by CNS RequestController on CRD update.
func (service *HTTPRestService) ReconcileNCState(ncRequest *cns.CreateNetworkContainerRequest, podInfoByIP map[string]cns.PodInfo, nnc *v1alpha.NodeNetworkConfig) types.ResponseCode {
logger.Printf("Reconciling NC state with podInfo %+v", podInfoByIP)
logger.Printf("Reconciling NC state with CreateNCRequest: [%v], PodInfo [%+v], NNC: [%+v]", ncRequest, podInfoByIP, nnc)
// check if ncRequest is null, then return as there is no CRD state yet
if ncRequest == nil {
logger.Printf("CNS starting with no NC state, podInfoMap count %d", len(podInfoByIP))
Expand Down
25 changes: 9 additions & 16 deletions cns/service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import (
"github.com/avast/retry-go/v3"
"github.com/pkg/errors"
"go.uber.org/zap"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
kuberuntime "k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -998,28 +999,21 @@ func reconcileInitialCNSState(ctx context.Context, cli nodeNetworkConfigGetter,
// Get nnc using direct client
nnc, err := cli.Get(ctx)
if err != nil {

if crd.IsNotDefined(err) {
return errors.Wrap(err, "failed to get NNC during init CNS state")
return errors.Wrap(err, "failed to init CNS state: NNC CRD is not defined")
}

// If instance of crd is not found, pass nil to CNSClient
if client.IgnoreNotFound(err) == nil {
err = restserver.ResponseCodeToError(ncReconciler.ReconcileNCState(nil, nil, nnc))
return errors.Wrap(err, "failed to reconcile NC state")
if apierrors.IsNotFound(err) {
return errors.Wrap(err, "failed to init CNS state: NNC not found")
}

// If it's any other error, log it and return
return errors.Wrap(err, "error getting NodeNetworkConfig when initializing CNS state")
return errors.Wrap(err, "failed to init CNS state: failed to get NNC CRD")
}

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

// Convert to CreateNetworkContainerRequest
// For each NC, we need to create a CreateNetworkContainerRequest and use it to rebuild our state.
for i := range nnc.Status.NetworkContainers {
var ncRequest *cns.CreateNetworkContainerRequest
var err error
Expand All @@ -1035,8 +1029,7 @@ func reconcileInitialCNSState(ctx context.Context, cli nodeNetworkConfigGetter,
return errors.Wrapf(err, "failed to convert NNC status to network container request, "+
"assignmentMode: %s", nnc.Status.NetworkContainers[i].AssignmentMode)
}

// rebuild CNS state
// Get previous PodInfo state from podInfoByIPProvider
podInfoByIP, err := podInfoByIPProvider.PodInfoByIP()
if err != nil {
return errors.Wrap(err, "provider failed to provide PodInfoByIP")
Expand Down

0 comments on commit a1b90ca

Please sign in to comment.