@@ -86,12 +86,16 @@ type topologyAdapterImpl struct {
8686
8787 // resourceNameToZoneTypeMap is a map that stores the mapping relationship between resource names to zone types for device zones
8888 resourceNameToZoneTypeMap map [string ]string
89+
90+ // needValidationResources is the resources needed to be validated
91+ needValidationResources []string
8992}
9093
9194// NewPodResourcesServerTopologyAdapter creates a topology adapter which uses pod resources server
9295func NewPodResourcesServerTopologyAdapter (metaServer * metaserver.MetaServer , endpoints []string ,
9396 kubeletResourcePluginPaths []string , resourceNameToZoneTypeMap map [string ]string , skipDeviceNames sets.String ,
94- numaInfoGetter NumaInfoGetter , podResourcesFilter PodResourcesFilter , getClientFunc podresources.GetClientFunc ) (Adapter , error ) {
97+ numaInfoGetter NumaInfoGetter , podResourcesFilter PodResourcesFilter , getClientFunc podresources.GetClientFunc ,
98+ needValidationResources []string ) (Adapter , error ) {
9599 numaInfo , err := numaInfoGetter ()
96100 if err != nil {
97101 return nil , fmt .Errorf ("failed to get numa info: %s" , err )
@@ -116,6 +120,7 @@ func NewPodResourcesServerTopologyAdapter(metaServer *metaserver.MetaServer, end
116120 getClientFunc : getClientFunc ,
117121 podResourcesFilter : podResourcesFilter ,
118122 resourceNameToZoneTypeMap : resourceNameToZoneTypeMap ,
123+ needValidationResources : needValidationResources ,
119124 }, nil
120125}
121126
@@ -149,7 +154,7 @@ func (p *topologyAdapterImpl) GetTopologyZones(parentCtx context.Context) ([]*no
149154 }
150155
151156 // validate pod Resources server response to make sure report topology status is correct
152- if err = validatePodResourcesServerResponse (allocatableResources , listPodResourcesResponse ); err != nil {
157+ if err = p . validatePodResourcesServerResponse (allocatableResources , listPodResourcesResponse ); err != nil {
153158 return nil , errors .Wrap (err , "validate pod Resources server response failed" )
154159 }
155160
@@ -266,14 +271,21 @@ func (p *topologyAdapterImpl) Run(ctx context.Context, handler func()) error {
266271
267272// validatePodResourcesServerResponse validate pod resources server response, if the resource is empty,
268273// maybe the kubelet or qrm plugin is restarting
269- func validatePodResourcesServerResponse (allocatableResourcesResponse * podresv1.AllocatableResourcesResponse ,
270- listPodResourcesResponse * podresv1.ListPodResourcesResponse ) error {
271- if allocatableResourcesResponse == nil {
272- return fmt .Errorf ("allocatable Resources response is nil" )
273- }
274+ func (p * topologyAdapterImpl ) validatePodResourcesServerResponse (allocatableResourcesResponse * podresv1.
275+ AllocatableResourcesResponse , listPodResourcesResponse * podresv1.ListPodResourcesResponse ) error {
276+ if len (p .needValidationResources ) > 0 {
277+ if allocatableResourcesResponse == nil {
278+ return fmt .Errorf ("allocatable resources response is nil" )
279+ }
274280
275- if len (allocatableResourcesResponse .Resources ) == 0 {
276- return fmt .Errorf ("allocatable topology aware Resources is empty" )
281+ allocResSet := sets .NewString ()
282+ for _ , res := range allocatableResourcesResponse .Resources {
283+ allocResSet .Insert (res .ResourceName )
284+ }
285+
286+ if ! allocResSet .HasAll (p .needValidationResources ... ) {
287+ return fmt .Errorf ("allocatable resources response doen't contain all the resources that need to be validated" )
288+ }
277289 }
278290
279291 if listPodResourcesResponse == nil {
0 commit comments