Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

koordlet: add GetNodeMetricSpec in statesInformer interface #2278

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) GetNodeMetricSpec() *slov1alpha1.NodeMetricSpec {
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
GetNodeMetricSpec() *slov1alpha1.NodeMetricSpec

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
GetNodeMetricSpec() *slov1alpha1.NodeMetricSpec

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) GetNodeMetricSpec() *slov1alpha1.NodeMetricSpec {
nodeMetricInformerIf := s.states.informerPlugins[nodeMetricInformerName]
nodeMetricInformer, ok := nodeMetricInformerIf.(*nodeMetricInformer)
if !ok {
klog.Errorf("node metric informer format error")
return nil
}
return nodeMetricInformer.getNodeMetricSpec()
}

func (s *statesInformer) GetNodeTopo() *topov1alpha1.NodeResourceTopology {
nodeTopoInformerIf := s.states.informerPlugins[nodeTopoInformerName]
nodeTopoInformer, ok := nodeTopoInformerIf.(*nodeTopoInformer)
Expand Down
75 changes: 75 additions & 0 deletions pkg/koordlet/statesinformer/impl/states_informer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,81 @@ func Test_statesInformer_GetNodeSLO(t *testing.T) {
}
}

func Test_statesInformer_GetNodeMetricSpec(t *testing.T) {
type fields struct {
nodeMetric *slov1alpha1.NodeMetric
}
collectPolicy := slov1alpha1.UsageWithoutPageCache
tests := []struct {
name string
fields fields
want *slov1alpha1.NodeMetricSpec
}{
{
name: "get node metric spec with default",
fields: fields{
nodeMetric: nil,
},
want: &defaultNodeMetricSpec,
},
{
name: "get node metric spec",
fields: fields{
nodeMetric: &slov1alpha1.NodeMetric{
ObjectMeta: metav1.ObjectMeta{
Name: "test-node-slo-name",
UID: "test-node-slo-uid",
},
Spec: slov1alpha1.NodeMetricSpec{
CollectPolicy: &slov1alpha1.NodeMetricCollectPolicy{},
},
},
},
want: &slov1alpha1.NodeMetricSpec{
CollectPolicy: &slov1alpha1.NodeMetricCollectPolicy{},
},
},
{
name: "get node metric spec",
fields: fields{
nodeMetric: &slov1alpha1.NodeMetric{
ObjectMeta: metav1.ObjectMeta{
Name: "test-node-slo-name",
UID: "test-node-slo-uid",
},
Spec: slov1alpha1.NodeMetricSpec{
CollectPolicy: &slov1alpha1.NodeMetricCollectPolicy{
NodeMemoryCollectPolicy: &collectPolicy,
},
},
},
},
want: &slov1alpha1.NodeMetricSpec{
CollectPolicy: &slov1alpha1.NodeMetricCollectPolicy{
NodeMemoryCollectPolicy: &collectPolicy,
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
nodeMetricInformer := &nodeMetricInformer{
nodeMetric: tt.fields.nodeMetric,
}
s := &statesInformer{
states: &PluginState{
informerPlugins: map[PluginName]informerPlugin{
nodeMetricInformerName: nodeMetricInformer,
},
},
}
if got := s.GetNodeMetricSpec(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("GetNodeMetricSpec() = %v, want %v", got, tt.want)
}
})
}
}

func Test_statesInformer_GetNodeTopo(t *testing.T) {
type fields struct {
nodeTopo *topov1alpha1.NodeResourceTopology
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.