Skip to content

Commit

Permalink
feat: add GetNodeMetric in statesInformer interface
Browse files Browse the repository at this point in the history
add func GetNodeMetric, so we can get nodeMetric conveniently by
statesInformer interface

Signed-off-by: j4ckstraw <[email protected]>
  • Loading branch information
j4ckstraw committed Nov 22, 2024
1 parent b4c53c8 commit 4a03d7f
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/koordlet/prediction/prediction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,15 @@ func (m *mockStatesInformer) HasSynced() bool {
func (m *mockStatesInformer) GetNode() *v1.Node {
return m.node
}

func (m *mockStatesInformer) GetNodeSLO() *slov1alpha1.NodeSLO {
return nil
}

func (m *mockStatesInformer) GetNodeMetric() *slov1alpha1.NodeMetric {
return nil
}

func (m *mockStatesInformer) GetAllPods() []*statesinformer.PodMeta {
return m.pods
}
Expand Down
1 change: 1 addition & 0 deletions pkg/koordlet/statesinformer/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ type StatesInformer interface {

GetNode() *corev1.Node
GetNodeSLO() *slov1alpha1.NodeSLO
GetNodeMetric() *slov1alpha1.NodeMetric

GetAllPods() []*PodMeta

Expand Down
13 changes: 13 additions & 0 deletions pkg/koordlet/statesinformer/impl/states_informer.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type StatesInformer interface {

GetNode() *corev1.Node
GetNodeSLO() *slov1alpha1.NodeSLO
GetNodeMetric() *slov1alpha1.NodeMetric

GetAllPods() []*statesinformer.PodMeta

Expand Down Expand Up @@ -101,6 +102,8 @@ type informerPlugin interface {
HasSynced() bool
}

var _ StatesInformer = &statesInformer{}

// TODO merge all clients into one struct
func NewStatesInformer(config *Config, kubeClient clientset.Interface, crdClient koordclientset.Interface, topologyClient topologyclientset.Interface,
metricsCache metriccache.MetricCache, nodeName string, schedulingClient schedv1alpha1.SchedulingV1alpha1Interface, predictorFactory prediction.PredictorFactory) StatesInformer {
Expand Down Expand Up @@ -225,6 +228,16 @@ func (s *statesInformer) GetNodeSLO() *slov1alpha1.NodeSLO {
return nodeSLOInformer.GetNodeSLO()
}

func (s *statesInformer) GetNodeMetric() *slov1alpha1.NodeMetric {
nodeMetricInformerIf := s.states.informerPlugins[nodeMetricInformerName]
nodeMetricInformer, ok := nodeMetricInformerIf.(*nodeMetricInformer)
if !ok {
klog.Errorf("node metric informer format error")
return nil
}
return nodeMetricInformer.GetNodeMetric()
}

func (s *statesInformer) GetNodeTopo() *topov1alpha1.NodeResourceTopology {
nodeTopoInformerIf := s.states.informerPlugins[nodeTopoInformerName]
nodeTopoInformer, ok := nodeTopoInformerIf.(*nodeTopoInformer)
Expand Down
10 changes: 10 additions & 0 deletions pkg/koordlet/statesinformer/impl/states_nodemetric.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ func NewNodeMetricInformer() *nodeMetricInformer {
return &nodeMetricInformer{}
}

func (s *nodeMetricInformer) GetNodeMetric() *slov1alpha1.NodeMetric {
s.rwMutex.RLock()
defer s.rwMutex.RUnlock()

if s.nodeMetric == nil {
return nil
}
return s.nodeMetric.DeepCopy()
}

func (r *nodeMetricInformer) HasSynced() bool {
if !r.reportEnabled {
return true
Expand Down
14 changes: 14 additions & 0 deletions pkg/koordlet/statesinformer/mockstatesinformer/mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4a03d7f

Please sign in to comment.