@@ -81,7 +81,7 @@ func (r *defaultPodENIInfoResolver) Resolve(ctx context.Context, pods []k8s.PodI
8181 eniInfoByPodKey := r .fetchENIInfosFromCache (pods )
8282 podsWithoutENIInfo := computePodsWithoutENIInfo (pods , eniInfoByPodKey )
8383 if len (podsWithoutENIInfo ) > 0 {
84- eniInfoByPodKeyViaLookup , err := r .resolveViaCascadedLookup (ctx , podsWithoutENIInfo )
84+ eniInfoByPodKeyViaLookup , err := r .resolvePodsViaCascadedLookup (ctx , podsWithoutENIInfo )
8585 if err != nil {
8686 return nil , err
8787 }
@@ -139,20 +139,49 @@ func (r *defaultPodENIInfoResolver) saveENIInfosToCache(pods []k8s.PodInfo, eniI
139139 }
140140}
141141
142- func (r * defaultPodENIInfoResolver ) resolveViaCascadedLookup (ctx context.Context , pods []k8s.PodInfo ) (map [types.NamespacedName ]ENIInfo , error ) {
142+ func (r * defaultPodENIInfoResolver ) resolvePodsViaCascadedLookup (ctx context.Context , pods []k8s.PodInfo ) (map [types.NamespacedName ]ENIInfo , error ) {
143+ podsOnEc2 , podsOnFargate , err := r .classifyPodsByComputeType (ctx , pods )
144+ if err != nil {
145+ return nil , err
146+ }
147+ eniInfoByPodKey := make (map [types.NamespacedName ]ENIInfo )
148+ if len (podsOnEc2 ) > 0 {
149+ eniInfoByPodKeyEc2 , err := r .resolveViaCascadedLookup (ctx , podsOnEc2 , false )
150+ if err != nil {
151+ return nil , err
152+ }
153+ eniInfoByPodKey = eniInfoByPodKeyEc2
154+ }
155+ if len (podsOnFargate ) > 0 {
156+ eniInfoByPodKeyFargate , err := r .resolveViaCascadedLookup (ctx , podsOnFargate , true )
157+ if err != nil {
158+ return nil , err
159+ }
160+ if len (eniInfoByPodKeyFargate ) > 0 {
161+ for podKey , eniInfo := range eniInfoByPodKeyFargate {
162+ eniInfoByPodKey [podKey ] = eniInfo
163+ }
164+ }
165+ }
166+ return eniInfoByPodKey , nil
167+ }
168+
169+ func (r * defaultPodENIInfoResolver ) resolveViaCascadedLookup (ctx context.Context , pods []k8s.PodInfo , isFargateNode bool ) (map [types.NamespacedName ]ENIInfo , error ) {
170+ eniInfoByPodKey := make (map [types.NamespacedName ]ENIInfo )
143171 resolveFuncs := []func (ctx context.Context , pods []k8s.PodInfo ) (map [types.NamespacedName ]ENIInfo , error ){
144172 r .resolveViaPodENIAnnotation ,
145173 r .resolveViaNodeENIs ,
146- r .resolveViaVPCENIs ,
147174 // TODO, add support for kubenet CNI plugin(kops) by resolve via routeTable.
148175 }
149-
150- eniInfoByPodKey := make (map [types.NamespacedName ]ENIInfo )
176+ if isFargateNode {
177+ resolveFuncs = []func (ctx context.Context , pods []k8s.PodInfo ) (map [types.NamespacedName ]ENIInfo , error ){
178+ r .resolveViaVPCENIs ,
179+ }
180+ }
151181 for _ , resolveFunc := range resolveFuncs {
152182 if len (pods ) == 0 {
153183 break
154184 }
155-
156185 resolvedENIInfoByPodKey , err := resolveFunc (ctx , pods )
157186 if err != nil {
158187 return nil , err
@@ -358,6 +387,35 @@ func (r *defaultPodENIInfoResolver) isPodSupportedByNodeENI(pod k8s.PodInfo, nod
358387 return false
359388}
360389
390+ // classifyPodsByComputeType classifies in to ec2 and fargate groups
391+ func (r * defaultPodENIInfoResolver ) classifyPodsByComputeType (ctx context.Context , pods []k8s.PodInfo ) ([]k8s.PodInfo , []k8s.PodInfo , error ) {
392+ podsOnFargate := make ([]k8s.PodInfo , 0 , len (pods ))
393+ podsOnEc2 := make ([]k8s.PodInfo , 0 , len (pods ))
394+ nodeNameByComputeType := make (map [string ]string )
395+ for _ , pod := range pods {
396+ if _ , exists := nodeNameByComputeType [pod .NodeName ]; exists {
397+ if nodeNameByComputeType [pod .NodeName ] == "fargate" {
398+ podsOnFargate = append (podsOnFargate , pod )
399+ } else {
400+ podsOnEc2 = append (podsOnEc2 , pod )
401+ }
402+ }
403+ nodeKey := types.NamespacedName {Name : pod .NodeName }
404+ node := & corev1.Node {}
405+ if err := r .k8sClient .Get (ctx , nodeKey , node ); err != nil {
406+ return nil , nil , err
407+ }
408+ if node .Labels [labelEKSComputeType ] == "fargate" {
409+ podsOnFargate = append (podsOnFargate , pod )
410+ nodeNameByComputeType [pod .NodeName ] = "fargate"
411+ } else {
412+ podsOnEc2 = append (podsOnEc2 , pod )
413+ nodeNameByComputeType [pod .NodeName ] = "ec2"
414+ }
415+ }
416+ return podsOnEc2 , podsOnFargate , nil
417+ }
418+
361419// computePodENIInfoCacheKey computes the cacheKey for pod's ENIInfo cache.
362420func computePodENIInfoCacheKey (podInfo k8s.PodInfo ) podENIInfoCacheKey {
363421 return podENIInfoCacheKey {
0 commit comments