Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
Signed-off-by: husharp <[email protected]>
  • Loading branch information
HuSharp committed Jul 18, 2023
1 parent 78966d8 commit e4d8138
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions client/resource_group/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,14 +486,29 @@ func (c *ResourceGroupsController) IsBackgroundRequest(ctx context.Context,

gc.metaLock.RLock()
defer gc.metaLock.RUnlock()
if bg := gc.meta.BackgroundSettings; bg != nil {
if len(requestResource) == 0 || len(bg.JobTypes) == 0 {
return c.checkBackgroundSettings(ctx, gc.meta.BackgroundSettings, requestResource)
}

func (c *ResourceGroupsController) checkBackgroundSettings(ctx context.Context, bg *rmpb.BackgroundSettings, requestResource string) bool {
// fallback to default resource group.
if bg == nil {
resourceGroupName := "default"
gc, err := c.tryGetResourceGroup(ctx, resourceGroupName)
if err != nil {
failedRequestCounter.WithLabelValues(resourceGroupName).Inc()
return false
}
if idx := strings.LastIndex(requestResource, "_"); idx != -1 {
return slices.Contains(bg.JobTypes, requestResource[idx+1:])
}
bg = gc.meta.BackgroundSettings
}

if bg == nil || len(requestResource) == 0 || len(bg.JobTypes) == 0 {
return false
}

if idx := strings.LastIndex(requestResource, "_"); idx != -1 {
return slices.Contains(bg.JobTypes, requestResource[idx+1:])
}

return false
}

Expand Down

0 comments on commit e4d8138

Please sign in to comment.