github.com/kubewharf/katalyst-core@v0.5.3/pkg/agent/resourcemanager/reporter/reporter.go (about) 1 /* 2 Copyright 2022 The Katalyst Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 // Package reporter is responsible for collecting per-node 18 // resources for scheduler; those resources are collected through multiple 19 // different sources, and updated in different K8S objects for needs. 20 package reporter // import "github.com/kubewharf/katalyst-core/pkg/reportermanager/reporter" 21 22 import ( 23 "context" 24 "sync" 25 26 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 27 28 "github.com/kubewharf/katalyst-api/pkg/protocol/reporterplugin/v1alpha1" 29 "github.com/kubewharf/katalyst-core/pkg/client" 30 "github.com/kubewharf/katalyst-core/pkg/config" 31 "github.com/kubewharf/katalyst-core/pkg/metaserver" 32 "github.com/kubewharf/katalyst-core/pkg/metrics" 33 ) 34 35 // Reporter use to update specific kind crd 36 type Reporter interface { 37 // Update receives ReportField list from report manager, the reporter implementation 38 // should be responsible for assembling and updating the specific object 39 // todo: consider whether we should perform real update actions asynchronously 40 Update(ctx context.Context, fields []*v1alpha1.ReportField) error 41 42 // Run starts the syncing logic of reporter 43 Run(ctx context.Context) 44 } 45 46 var reporterInitializers sync.Map 47 48 // InitFunc is used to initialize a particular reporter. 49 type InitFunc func(*client.GenericClientSet, *metaserver.MetaServer, metrics.MetricEmitter, *config.Configuration) (Reporter, error) 50 51 func RegisterReporterInitializer(gvk metav1.GroupVersionKind, initFunc InitFunc) { 52 reporterInitializers.Store(gvk, initFunc) 53 } 54 55 func getRegisteredInitializers() map[metav1.GroupVersionKind]InitFunc { 56 updaters := make(map[metav1.GroupVersionKind]InitFunc) 57 reporterInitializers.Range(func(key, value interface{}) bool { 58 updaters[key.(metav1.GroupVersionKind)] = value.(InitFunc) 59 return true 60 }) 61 return updaters 62 }