2022-11-02 16:01:25 +02:00
|
|
|
package resourcemonitor
|
|
|
|
|
|
|
|
import (
|
|
|
|
corev1 "k8s.io/api/core/v1"
|
|
|
|
"k8s.io/apimachinery/pkg/util/sets"
|
|
|
|
"k8s.io/klog/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ExcludeResourceList contains a list of resources to ignore during resources scan
|
|
|
|
type ExcludeResourceList struct {
|
2022-12-12 22:47:09 +02:00
|
|
|
excludeList sets.Set[string]
|
2022-11-02 16:01:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewExcludeResourceList returns new ExcludeList with values with set.String types
|
|
|
|
func NewExcludeResourceList(resMap map[string][]string, nodeName string) ExcludeResourceList {
|
2022-12-12 22:47:09 +02:00
|
|
|
excludeList := make(sets.Set[string])
|
|
|
|
|
2022-11-02 16:01:25 +02:00
|
|
|
for k, v := range resMap {
|
|
|
|
if k == nodeName || k == "*" {
|
|
|
|
excludeList.Insert(v...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ExcludeResourceList{
|
|
|
|
excludeList: excludeList,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rl *ExcludeResourceList) IsExcluded(resource corev1.ResourceName) bool {
|
|
|
|
if rl.excludeList.Has(string(resource)) {
|
2023-05-03 11:32:53 +03:00
|
|
|
klog.V(5).InfoS("resource excluded", "resourceName", resource)
|
2022-11-02 16:01:25 +02:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|