From aa753ef9b816451e5b8e18dfab7f246082fe19c2 Mon Sep 17 00:00:00 2001 From: "hongzhen.cz" Date: Wed, 3 Jul 2024 14:46:07 +0800 Subject: [PATCH] feat:add RemoveResourceNodes --- core/stat/node_storage.go | 11 +++++++++++ core/stat/node_storage_test.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 core/stat/node_storage_test.go diff --git a/core/stat/node_storage.go b/core/stat/node_storage.go index cea5127ef..819fcd64d 100644 --- a/core/stat/node_storage.go +++ b/core/stat/node_storage.go @@ -54,6 +54,17 @@ func GetResourceNode(resource string) *ResourceNode { return resNodeMap[resource] } +func RemoveResourceNodes(resources []string) { + if len(resources) == 0 { + return + } + rnsMux.Lock() + defer rnsMux.Unlock() + for _, resource := range resources { + delete(resNodeMap, resource) + } +} + func GetOrCreateResourceNode(resource string, resourceType base.ResourceType) *ResourceNode { node := GetResourceNode(resource) if node != nil { diff --git a/core/stat/node_storage_test.go b/core/stat/node_storage_test.go new file mode 100644 index 000000000..17f86966a --- /dev/null +++ b/core/stat/node_storage_test.go @@ -0,0 +1,29 @@ +package stat + +import "testing" + +func TestRemoveResourceNodes(t *testing.T) { + type args struct { + resources []string + } + tests := []struct { + name string + args args + }{ + { + name: "empty", + args: args{}, + }, + { + name: "normal", + args: args{ + resources: []string{"test"}, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + RemoveResourceNodes(tt.args.resources) + }) + } +}