Skip to content

Commit

Permalink
koordlet: support pouch container
Browse files Browse the repository at this point in the history
Signed-off-by: 佑祎 <[email protected]>
  • Loading branch information
zwzhang0107 committed Nov 29, 2023
1 parent 661dd71 commit 8f835d5
Show file tree
Hide file tree
Showing 14 changed files with 1,613 additions and 14 deletions.
5 changes: 5 additions & 0 deletions hack/mock-gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,8 @@ mockgen -source vendor/k8s.io/cri-api/pkg/apis/runtime/v1/api.pb.go \
-imports github.com/koordinator-sh/koordinator/vendor/k8s.io/cri-api/pkg/apis/runtime/v1=k8s.io/cri-api/pkg/apis/runtime/v1 \
-copyright_file ${LICENSE_HEADER_PATH} \
-package mock_client RuntimeServiceClient
mockgen -source vendor/k8s.io/cri-api/pkg/apis/runtime/v1alpha2/api.pb.go \
-destination pkg/koordlet/util/runtime/handler/mockv1alpha2client/mock.go \
-imports github.com/koordinator-sh/koordinator/vendor/k8s.io/cri-api/pkg/apis/runtime/v1alpha2=k8s.io/cri-api/pkg/apis/runtime/v1alpha2 \
-copyright_file ${LICENSE_HEADER_PATH} \
-package mockv1alpha2_client RuntimeServiceClient
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (h *hostAppCollector) collectHostAppResUsed() {
}

metrics = append(metrics, cpuUsageMetric, memUsageMetric)
klog.V(6).Infof("collect host application %v finished, metric %+v", hostApp.Name, metrics)
klog.V(6).Infof("collect host application %v finished, metric cpu=%v, memory=%v", hostApp.Name, cpuUsageValue, memoryUsageValue)
count++
allCPUUsageCores.Value += cpuUsageValue
allMemoryUsage.Value += float64(memoryUsageValue)
Expand Down
8 changes: 4 additions & 4 deletions pkg/koordlet/runtimehooks/protocol/container_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"strings"

"github.com/containerd/nri/pkg/api"

"k8s.io/klog/v2"

apiext "github.com/koordinator-sh/koordinator/apis/extension"
Expand All @@ -30,6 +29,7 @@ import (
"github.com/koordinator-sh/koordinator/pkg/koordlet/resourceexecutor"
"github.com/koordinator-sh/koordinator/pkg/koordlet/statesinformer"
koordletutil "github.com/koordinator-sh/koordinator/pkg/koordlet/util"
"github.com/koordinator-sh/koordinator/pkg/koordlet/util/system"
"github.com/koordinator-sh/koordinator/pkg/util"
)

Expand Down Expand Up @@ -372,10 +372,10 @@ func (c *ContainerContext) injectForExt() {
}

func getContainerID(podAnnotations map[string]string, containerUID string) string {
// TODO parse from runtime hook request directly
runtimeType := "containerd"
// TODO parse from runtime hook request directly such as cgroup path format
runtimeType := system.Conf.DefaultRuntimeType
if _, exist := podAnnotations["io.kubernetes.docker.type"]; exist {
runtimeType = "docker"
runtimeType = system.RuntimeTypeDocker
}
return fmt.Sprintf("%s://%s", runtimeType, containerUID)
}
63 changes: 63 additions & 0 deletions pkg/koordlet/runtimehooks/protocol/container_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

"github.com/koordinator-sh/koordinator/apis/extension"
"github.com/koordinator-sh/koordinator/pkg/koordlet/resourceexecutor"
"github.com/koordinator-sh/koordinator/pkg/koordlet/util/system"
)

func TestContainerContext_FromNri(t *testing.T) {
Expand Down Expand Up @@ -209,3 +210,65 @@ func TestContainerContext_NriDone(t *testing.T) {
})
}
}

func Test_getContainerID(t *testing.T) {
type args struct {
podAnnotations map[string]string
containerUID string
systemConfDefaultRuntime string
}
tests := []struct {
name string
args args
want string
}{
{
name: "default is containerd",
args: args{
podAnnotations: nil,
containerUID: "testContainerID",
systemConfDefaultRuntime: system.RuntimeTypeContainerd,
},
want: "containerd://testContainerID",
},
{
name: "default is pouch",
args: args{
podAnnotations: nil,
containerUID: "testContainerID",
systemConfDefaultRuntime: system.RuntimeTypePouch,
},
want: "pouch://testContainerID",
},
{
name: "default is docker",
args: args{
podAnnotations: nil,
containerUID: "testContainerID",
systemConfDefaultRuntime: system.RuntimeTypeDocker,
},
want: "docker://testContainerID",
},
{
name: "docker in pod annotation",
args: args{
podAnnotations: map[string]string{
"io.kubernetes.docker.type": "true",
},
containerUID: "testContainerID",
systemConfDefaultRuntime: system.RuntimeTypePouch,
},
want: "docker://testContainerID",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
system.Conf = &system.Config{
DefaultRuntimeType: tt.args.systemConfDefaultRuntime,
}
if got := getContainerID(tt.args.podAnnotations, tt.args.containerUID); got != tt.want {
t.Errorf("getContainerID() = %v, want %v", got, tt.want)
}
})
}
}
5 changes: 3 additions & 2 deletions pkg/koordlet/util/runtime/handler/mockclient/mock.go

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

Loading

0 comments on commit 8f835d5

Please sign in to comment.