@@ -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