From e4d8138c10d13742cb34adf7ed877f40b0b1b02a Mon Sep 17 00:00:00 2001 From: husharp Date: Tue, 18 Jul 2023 19:28:58 +0800 Subject: [PATCH] update test Signed-off-by: husharp --- .../resource_group/controller/controller.go | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/client/resource_group/controller/controller.go b/client/resource_group/controller/controller.go index 3415a0d6b8b..7705c939f9b 100755 --- a/client/resource_group/controller/controller.go +++ b/client/resource_group/controller/controller.go @@ -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 }