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