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: generate mock states informer #1257

Merged
merged 1 commit into from
Apr 27, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions hack/mock-gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ cd $GOPATH/src/github.com/koordinator-sh/koordinator
# generates gomock files
mockgen -source pkg/koordlet/statesinformer/states_informer.go \
-destination pkg/koordlet/statesinformer/mockstatesinformer/mock.go \
-aux_files github.com/koordinator-sh/koordinator/pkg/koordlet/statesinformer=pkg/koordlet/statesinformer/states_informer.go \
-copyright_file ${LICENSE_HEADER_PATH}
mockgen -source pkg/koordlet/metriccache/metric_cache.go \
-destination pkg/koordlet/metriccache/mockmetriccache/mock.go \
Expand Down
9 changes: 5 additions & 4 deletions pkg/koordlet/metriccache/mockmetriccache/mock.go

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

8 changes: 4 additions & 4 deletions pkg/koordlet/statesinformer/callback_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ func TestRegisterCallbacksAndRun(t *testing.T) {
RegisterTypeNodeTopology: {},
},
statesInformer: &statesInformer{
states: &pluginState{
informerPlugins: map[pluginName]informerPlugin{
states: &PluginState{
informerPlugins: map[PluginName]informerPlugin{
nodeSLOInformerName: &nodeSLOInformer{
nodeSLO: &slov1alpha1.NodeSLO{},
},
Expand Down Expand Up @@ -142,9 +142,9 @@ func Test_statesInformer_startCallbackRunners(t *testing.T) {
},
}
si := &statesInformer{
states: &pluginState{
states: &PluginState{
callbackRunner: cr,
informerPlugins: map[pluginName]informerPlugin{
informerPlugins: map[PluginName]informerPlugin{
nodeSLOInformerName: &nodeSLOInformer{
nodeSLO: tt.args.nodeSLO,
},
Expand Down
63 changes: 63 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.

2 changes: 1 addition & 1 deletion pkg/koordlet/statesinformer/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package statesinformer

// NOTE: variables in this file can be overwritten for extension

var DefaultPluginRegistry = map[pluginName]informerPlugin{
var DefaultPluginRegistry = map[PluginName]informerPlugin{
nodeSLOInformerName: NewNodeSLOInformer(),
pvcInformerName: NewPVCInformer(),
nodeTopoInformerName: NewNodeTopoInformer(),
Expand Down
4 changes: 2 additions & 2 deletions pkg/koordlet/statesinformer/states_device_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ func Test_reportGPUDevice(t *testing.T) {
r := &statesInformer{
deviceClient: fakeClient,
metricsCache: mockMetricCache,
states: &pluginState{
informerPlugins: map[pluginName]informerPlugin{
states: &PluginState{
informerPlugins: map[PluginName]informerPlugin{
nodeInformerName: &nodeInformer{
node: testNode,
},
Expand Down
20 changes: 10 additions & 10 deletions pkg/koordlet/statesinformer/states_informer.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,20 @@ type StatesInformer interface {
RegisterCallbacks(objType RegisterType, name, description string, callbackFn UpdateCbFn)
}

type pluginName string
type PluginName string

type pluginOption struct {
type PluginOption struct {
config *Config
KubeClient clientset.Interface
KoordClient koordclientset.Interface
TopoClient topologyclientset.Interface
NodeName string
}

type pluginState struct {
type PluginState struct {
metricCache metriccache.MetricCache
callbackRunner *callbackRunner
informerPlugins map[pluginName]informerPlugin
informerPlugins map[PluginName]informerPlugin
}

type GetGPUDriverAndModelFunc func() (string, string)
Expand All @@ -85,31 +85,31 @@ type statesInformer struct {
unhealthyGPU map[string]struct{}
gpuMutex sync.RWMutex

option *pluginOption
states *pluginState
option *PluginOption
states *PluginState
started *atomic.Bool

getGPUDriverAndModelFunc GetGPUDriverAndModelFunc
}

type informerPlugin interface {
Setup(ctx *pluginOption, state *pluginState)
Setup(ctx *PluginOption, state *PluginState)
Start(stopCh <-chan struct{})
HasSynced() bool
}

// 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) StatesInformer {
opt := &pluginOption{
opt := &PluginOption{
config: config,
KubeClient: kubeClient,
KoordClient: crdClient,
TopoClient: topologyClient,
NodeName: nodeName,
}
stat := &pluginState{
stat := &PluginState{
metricCache: metricsCache,
informerPlugins: map[pluginName]informerPlugin{},
informerPlugins: map[PluginName]informerPlugin{},
callbackRunner: NewCallbackRunner(),
}
s := &statesInformer{
Expand Down
20 changes: 10 additions & 10 deletions pkg/koordlet/statesinformer/states_informer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ func Test_statesInformer_GetNode(t *testing.T) {
node: tt.fields.node,
}
s := &statesInformer{
states: &pluginState{
informerPlugins: map[pluginName]informerPlugin{
states: &PluginState{
informerPlugins: map[PluginName]informerPlugin{
nodeInformerName: nodeInformer,
},
},
Expand Down Expand Up @@ -116,8 +116,8 @@ func Test_statesInformer_GetNodeSLO(t *testing.T) {
nodeSLO: tt.fields.nodeSLO,
}
s := &statesInformer{
states: &pluginState{
informerPlugins: map[pluginName]informerPlugin{
states: &PluginState{
informerPlugins: map[PluginName]informerPlugin{
nodeSLOInformerName: nodeSLOInformer,
},
},
Expand Down Expand Up @@ -162,8 +162,8 @@ func Test_statesInformer_GetNodeTopo(t *testing.T) {
nodeTopology: tt.fields.nodeTopo,
}
s := &statesInformer{
states: &pluginState{
informerPlugins: map[pluginName]informerPlugin{
states: &PluginState{
informerPlugins: map[PluginName]informerPlugin{
nodeTopoInformerName: nodeTopoInformer,
},
},
Expand Down Expand Up @@ -218,8 +218,8 @@ func Test_statesInformer_GetAllPods(t *testing.T) {
podMap: tt.fields.podMap,
}
s := &statesInformer{
states: &pluginState{
informerPlugins: map[pluginName]informerPlugin{
states: &PluginState{
informerPlugins: map[PluginName]informerPlugin{
podsInformerName: podsInformer,
},
},
Expand All @@ -235,7 +235,7 @@ func Test_statesInformer_Run(t *testing.T) {
type fields struct {
config *Config
node corev1.Node
pluginRegistry map[pluginName]informerPlugin
pluginRegistry map[PluginName]informerPlugin
}
tests := []struct {
name string
Expand All @@ -259,7 +259,7 @@ func Test_statesInformer_Run(t *testing.T) {
},
},
},
pluginRegistry: map[pluginName]informerPlugin{
pluginRegistry: map[PluginName]informerPlugin{
nodeSLOInformerName: NewNodeSLOInformer(),
nodeInformerName: NewNodeInformer(),
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/koordlet/statesinformer/states_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
)

const (
nodeInformerName pluginName = "nodeInformer"
nodeInformerName PluginName = "nodeInformer"
)

type nodeInformer struct {
Expand All @@ -59,7 +59,7 @@ func (s *nodeInformer) GetNode() *corev1.Node {
return s.node.DeepCopy()
}

func (s *nodeInformer) Setup(ctx *pluginOption, state *pluginState) {
func (s *nodeInformer) Setup(ctx *PluginOption, state *PluginState) {
s.nodeInformer = newNodeInformer(ctx.KubeClient, ctx.NodeName)
s.nodeInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/koordlet/statesinformer/states_nodemetric.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import (
)

const (
nodeMetricInformerName pluginName = "nodeMetricInformer"
nodeMetricInformerName PluginName = "nodeMetricInformer"

// defaultAggregateDurationSeconds is the default metric aggregate duration by seconds
minAggregateDurationSeconds = 60
Expand Down Expand Up @@ -113,7 +113,7 @@ func (r *nodeMetricInformer) HasSynced() bool {
return synced
}

func (r *nodeMetricInformer) Setup(ctx *pluginOption, state *pluginState) {
func (r *nodeMetricInformer) Setup(ctx *PluginOption, state *PluginState) {
r.reportEnabled = ctx.config.EnableNodeMetricReport
r.nodeName = ctx.NodeName
r.nodeMetricInformer = newNodeMetricInformer(ctx.KoordClient, ctx.NodeName)
Expand Down
10 changes: 5 additions & 5 deletions pkg/koordlet/statesinformer/states_nodemetric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -749,8 +749,8 @@ func Test_nodeMetricInformer_NewAndSetup(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
type args struct {
ctx *pluginOption
state *pluginState
ctx *PluginOption
state *PluginState
}
tests := []struct {
name string
Expand All @@ -759,16 +759,16 @@ func Test_nodeMetricInformer_NewAndSetup(t *testing.T) {
{
name: "new and setup node metric",
args: args{
ctx: &pluginOption{
ctx: &PluginOption{
config: NewDefaultConfig(),
KubeClient: fakeclientset.NewSimpleClientset(),
KoordClient: fakekoordclientset.NewSimpleClientset(),
TopoClient: faketopologyclientset.NewSimpleClientset(),
NodeName: "test-node",
},
state: &pluginState{
state: &PluginState{
metricCache: mockmetriccache.NewMockMetricCache(ctrl),
informerPlugins: map[pluginName]informerPlugin{
informerPlugins: map[PluginName]informerPlugin{
podsInformerName: NewPodsInformer(),
},
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/koordlet/statesinformer/states_noderesourcetopology.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import (
)

const (
nodeTopoInformerName pluginName = "nodeTopoInformer"
nodeTopoInformerName PluginName = "nodeTopoInformer"
)

type nodeTopoInformer struct {
Expand Down Expand Up @@ -83,7 +83,7 @@ func (s *nodeTopoInformer) GetNodeTopo() *topov1alpha1.NodeResourceTopology {
return s.nodeTopology.DeepCopy()
}

func (s *nodeTopoInformer) Setup(ctx *pluginOption, state *pluginState) {
func (s *nodeTopoInformer) Setup(ctx *PluginOption, state *PluginState) {
s.config = ctx.config
s.topologyClient = ctx.TopoClient
s.metricCache = state.metricCache
Expand Down