Skip to content

Commit

Permalink
koordlet: revise cgroupRoot param in podsInformer (koordinator-sh#1928)
Browse files Browse the repository at this point in the history
Signed-off-by: saintube <saintube@foxmail.com>
  • Loading branch information
saintube authored and ls-2018 committed Mar 25, 2024
1 parent 46daef8 commit 1eb4b6b
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 6 deletions.
12 changes: 6 additions & 6 deletions pkg/koordlet/statesinformer/impl/states_pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,21 @@ type podsInformer struct {
}

func NewPodsInformer() *podsInformer {
p, err := pleg.NewPLEG(system.Conf.CgroupRootDir)
if err != nil {
klog.Fatalf("failed to create PLEG, %v", err)
}

podsInformer := &podsInformer{
podMap: map[string]*statesinformer.PodMeta{},
podHasSynced: atomic.NewBool(false),
pleg: p,
podCreated: make(chan string, 1),
}
return podsInformer
}

func (s *podsInformer) Setup(ctx *PluginOption, states *PluginState) {
p, err := pleg.NewPLEG(system.Conf.CgroupRootDir)
if err != nil {
klog.Fatalf("failed to create PLEG, %v", err)
}
s.pleg = p

s.config = ctx.config

nodeInformerIf := states.informerPlugins[nodeInformerName]
Expand Down
82 changes: 82 additions & 0 deletions pkg/koordlet/statesinformer/impl/states_pods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,19 @@ import (
"testing"
"time"

faketopologyclientset "github.com/k8stopologyawareschedwg/noderesourcetopology-api/pkg/generated/clientset/versioned/fake"
"github.com/stretchr/testify/assert"
"go.uber.org/atomic"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
fakeclientset "k8s.io/client-go/kubernetes/fake"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
kubeletconfiginternal "k8s.io/kubernetes/pkg/kubelet/apis/config"

apiext "github.com/koordinator-sh/koordinator/apis/extension"
fakekoordclientset "github.com/koordinator-sh/koordinator/pkg/client/clientset/versioned/fake"
"github.com/koordinator-sh/koordinator/pkg/koordlet/metrics"
"github.com/koordinator-sh/koordinator/pkg/koordlet/statesinformer"
"github.com/koordinator-sh/koordinator/pkg/koordlet/util/system"
Expand Down Expand Up @@ -119,6 +122,85 @@ func (t *testErrorKubeletStub) GetKubeletConfiguration() (*kubeletconfiginternal
return nil, errors.New("test error")
}

func Test_podsInformer(t *testing.T) {
tempCgroupDir := t.TempDir()
type fields struct {
GetCgroupDirFn func(helper *system.FileTestUtil) string
}
type args struct {
ctx *PluginOption
states *PluginState
}
tests := []struct {
name string
fields fields
args args
}{
{
name: "default config",
fields: fields{
GetCgroupDirFn: nil,
},
args: args{
ctx: &PluginOption{
config: NewDefaultConfig(),
KubeClient: fakeclientset.NewSimpleClientset(),
KoordClient: fakekoordclientset.NewSimpleClientset(),
TopoClient: faketopologyclientset.NewSimpleClientset(),
NodeName: "test-node",
},
states: &PluginState{
informerPlugins: map[PluginName]informerPlugin{
nodeInformerName: NewNodeInformer(),
},
},
},
},
{
name: "change cgroup root",
fields: fields{
GetCgroupDirFn: func(helper *system.FileTestUtil) string {
return tempCgroupDir
},
},
args: args{
ctx: &PluginOption{
config: NewDefaultConfig(),
KubeClient: fakeclientset.NewSimpleClientset(),
KoordClient: fakekoordclientset.NewSimpleClientset(),
TopoClient: faketopologyclientset.NewSimpleClientset(),
NodeName: "test-node",
},
states: &PluginState{
informerPlugins: map[PluginName]informerPlugin{
nodeInformerName: NewNodeInformer(),
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
helper := system.NewFileTestUtil(t)
oldCgroupRoot := system.Conf.CgroupRootDir
if tt.fields.GetCgroupDirFn != nil {
helper.SetConf(func(conf *system.Config) {
conf.CgroupRootDir = tt.fields.GetCgroupDirFn(helper)
}, func(conf *system.Config) {
conf.CgroupRootDir = oldCgroupRoot
})
}
defer helper.Cleanup()
pi := NewPodsInformer()
assert.NotNil(t, pi)
assert.NotPanics(t, func() {
pi.Setup(tt.args.ctx, tt.args.states)
})
assert.NotNil(t, pi.pleg)
})
}
}

func Test_statesInformer_syncPods(t *testing.T) {
stopCh := make(chan struct{}, 1)
defer close(stopCh)
Expand Down

0 comments on commit 1eb4b6b

Please sign in to comment.