Skip to content
New issue

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

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

Already on GitHub? # to your account

add support container runtime use systemd cgroups #1302

Merged
merged 1 commit into from
Dec 6, 2023
Merged
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
add support container runtime use systemd cgroups
Signed-off-by: lengrongfu <lenronfu@gmail.com>
  • Loading branch information
lengrongfu committed Dec 5, 2023
commit 8643906ddfa55d8da2f4305d5465dde7d0254b54
8 changes: 5 additions & 3 deletions pkg/benchmark/pod.go
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@ import (
"path"
"time"

"github.com/kubernetes-sigs/cri-tools/pkg/common"
"github.com/kubernetes-sigs/cri-tools/pkg/framework"
"github.com/sirupsen/logrus"
internalapi "k8s.io/cri-api/pkg/apis"
@@ -85,11 +86,12 @@ var _ = framework.KubeDescribe("PodSandbox", func() {
podSandboxName := "PodSandbox-for-creating-performance-test-" + framework.NewUUID()
uid := framework.DefaultUIDPrefix + framework.NewUUID()
namespace := framework.DefaultNamespacePrefix + framework.NewUUID()

config := &runtimeapi.PodSandboxConfig{
Metadata: framework.BuildPodSandboxMetadata(podSandboxName, uid, namespace, framework.DefaultAttempt),
Linux: &runtimeapi.LinuxPodSandboxConfig{},
Labels: framework.DefaultPodLabels,
Linux: &runtimeapi.LinuxPodSandboxConfig{
CgroupParent: common.GetCgroupParent(context.TODO(), c),
},
Labels: framework.DefaultPodLabels,
}

By(fmt.Sprintf("Creating a pod %d", idx))
6 changes: 4 additions & 2 deletions pkg/benchmark/pod_container.go
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@ package benchmark
import (
"context"

"github.com/kubernetes-sigs/cri-tools/pkg/common"
"github.com/kubernetes-sigs/cri-tools/pkg/framework"
internalapi "k8s.io/cri-api/pkg/apis"
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
@@ -62,10 +63,11 @@ var _ = framework.KubeDescribe("PodSandbox", func() {
podSandboxName := "PodSandbox-for-creating-pod-and-container-performance-test-" + framework.NewUUID()
uid := framework.DefaultUIDPrefix + framework.NewUUID()
namespace := framework.DefaultNamespacePrefix + framework.NewUUID()

config := &runtimeapi.PodSandboxConfig{
Metadata: framework.BuildPodSandboxMetadata(podSandboxName, uid, namespace, framework.DefaultAttempt),
Linux: &runtimeapi.LinuxPodSandboxConfig{},
Linux: &runtimeapi.LinuxPodSandboxConfig{
CgroupParent: common.GetCgroupParent(context.TODO(), rc),
},
}

benchmark := func() {
43 changes: 43 additions & 0 deletions pkg/common/pod_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
Copyright 2023 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package common

import (
"context"

internalapi "k8s.io/cri-api/pkg/apis"
runtimev1 "k8s.io/cri-api/pkg/apis/runtime/v1"
)

const (
DefaultSystemdCgroupSlice = "/test.slice"
)

func GetCgroupParent(ctx context.Context, c internalapi.RuntimeService) string {
runtimeConfig, err := c.RuntimeConfig(ctx)
if err != nil {
return DefaultSystemdCgroupSlice
}
if runtimeConfig == nil || runtimeConfig.Linux == nil {
return DefaultSystemdCgroupSlice
}
cgroupDriver := runtimeConfig.Linux.GetCgroupDriver()
if cgroupDriver == runtimev1.CgroupDriver_CGROUPFS {
return ""
}
return DefaultSystemdCgroupSlice
}
14 changes: 9 additions & 5 deletions pkg/framework/util.go
Original file line number Diff line number Diff line change
@@ -26,6 +26,7 @@ import (

"github.com/distribution/reference"
"github.com/google/uuid"
"github.com/kubernetes-sigs/cri-tools/pkg/common"
"gopkg.in/yaml.v3"
internalapi "k8s.io/cri-api/pkg/apis"
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
@@ -192,11 +193,12 @@ func RunDefaultPodSandbox(c internalapi.RuntimeService, prefix string) string {
podSandboxName := prefix + NewUUID()
uid := DefaultUIDPrefix + NewUUID()
namespace := DefaultNamespacePrefix + NewUUID()

config := &runtimeapi.PodSandboxConfig{
Metadata: BuildPodSandboxMetadata(podSandboxName, uid, namespace, DefaultAttempt),
Linux: &runtimeapi.LinuxPodSandboxConfig{},
Labels: DefaultPodLabels,
Linux: &runtimeapi.LinuxPodSandboxConfig{
CgroupParent: common.GetCgroupParent(context.TODO(), c),
},
Labels: DefaultPodLabels,
}
return RunPodSandbox(c, config)
}
@@ -225,8 +227,10 @@ func CreatePodSandboxForContainer(c internalapi.RuntimeService) (string, *runtim
namespace := DefaultNamespacePrefix + NewUUID()
config := &runtimeapi.PodSandboxConfig{
Metadata: BuildPodSandboxMetadata(podSandboxName, uid, namespace, DefaultAttempt),
Linux: &runtimeapi.LinuxPodSandboxConfig{},
Labels: DefaultPodLabels,
Linux: &runtimeapi.LinuxPodSandboxConfig{
CgroupParent: common.GetCgroupParent(context.TODO(), c),
},
Labels: DefaultPodLabels,
}

podID := RunPodSandbox(c, config)
4 changes: 4 additions & 0 deletions pkg/validate/multi_container_linux.go
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@ import (
"strings"
"time"

"github.com/kubernetes-sigs/cri-tools/pkg/common"
"github.com/kubernetes-sigs/cri-tools/pkg/framework"
internalapi "k8s.io/cri-api/pkg/apis"
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
@@ -122,6 +123,9 @@ func createMultiContainerTestPodSandbox(c internalapi.RuntimeService) (string, *
},
},
Labels: framework.DefaultPodLabels,
Linux: &runtimeapi.LinuxPodSandboxConfig{
CgroupParent: common.GetCgroupParent(context.TODO(), c),
},
}
return framework.RunPodSandbox(c, podConfig), podConfig, logDir
}
14 changes: 11 additions & 3 deletions pkg/validate/networking.go
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@ import (
"strings"
"time"

"github.com/kubernetes-sigs/cri-tools/pkg/common"
"github.com/kubernetes-sigs/cri-tools/pkg/framework"
internalapi "k8s.io/cri-api/pkg/apis"
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
@@ -136,6 +137,9 @@ func createPodSandWithHostname(c internalapi.RuntimeService, hostname string) (s
Metadata: framework.BuildPodSandboxMetadata(podSandboxName, uid, namespace, framework.DefaultAttempt),
Hostname: hostname,
Labels: framework.DefaultPodLabels,
Linux: &runtimeapi.LinuxPodSandboxConfig{
CgroupParent: common.GetCgroupParent(context.TODO(), c),
},
}

podID := framework.RunPodSandbox(c, config)
@@ -154,7 +158,9 @@ func createPodSandWithDNSConfig(c internalapi.RuntimeService) (string, *runtimea
Searches: []string{defaultDNSSearch},
Options: []string{defaultDNSOption},
},
Linux: &runtimeapi.LinuxPodSandboxConfig{},
Linux: &runtimeapi.LinuxPodSandboxConfig{
CgroupParent: common.GetCgroupParent(context.TODO(), c),
},
Labels: framework.DefaultPodLabels,
}

@@ -170,8 +176,10 @@ func createPodSandboxWithPortMapping(c internalapi.RuntimeService, portMappings
config := &runtimeapi.PodSandboxConfig{
Metadata: framework.BuildPodSandboxMetadata(podSandboxName, uid, namespace, framework.DefaultAttempt),
PortMappings: portMappings,
Linux: &runtimeapi.LinuxPodSandboxConfig{},
Labels: framework.DefaultPodLabels,
Linux: &runtimeapi.LinuxPodSandboxConfig{
CgroupParent: common.GetCgroupParent(context.TODO(), c),
},
Labels: framework.DefaultPodLabels,
}
if hostNet {
config.Linux.SecurityContext = &runtimeapi.LinuxSandboxSecurityContext{
5 changes: 4 additions & 1 deletion pkg/validate/pod.go
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@ import (
"os"
"path/filepath"

"github.com/kubernetes-sigs/cri-tools/pkg/common"
"github.com/kubernetes-sigs/cri-tools/pkg/framework"
internalapi "k8s.io/cri-api/pkg/apis"
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
@@ -175,10 +176,12 @@ func createPodSandboxWithLogDirectory(c internalapi.RuntimeService) (string, *ru
namespace := framework.DefaultNamespacePrefix + framework.NewUUID()

hostPath, podLogPath := createLogTempDir(podSandboxName)

podConfig := &runtimeapi.PodSandboxConfig{
Metadata: framework.BuildPodSandboxMetadata(podSandboxName, uid, namespace, framework.DefaultAttempt),
LogDirectory: podLogPath,
Linux: &runtimeapi.LinuxPodSandboxConfig{
CgroupParent: common.GetCgroupParent(context.TODO(), c),
},
}
return framework.RunPodSandbox(c, podConfig), podConfig, hostPath
}
5 changes: 3 additions & 2 deletions pkg/validate/pod_linux.go
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@ import (
"strings"
"time"

"github.com/kubernetes-sigs/cri-tools/pkg/common"
"github.com/kubernetes-sigs/cri-tools/pkg/framework"
internalapi "k8s.io/cri-api/pkg/apis"
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
@@ -89,11 +90,11 @@ func createSandboxWithSysctls(rc internalapi.RuntimeService, sysctls map[string]
podSandboxName := "pod-sandbox-with-sysctls-" + framework.NewUUID()
uid := framework.DefaultUIDPrefix + framework.NewUUID()
namespace := framework.DefaultNamespacePrefix + framework.NewUUID()

podConfig := &runtimeapi.PodSandboxConfig{
Metadata: framework.BuildPodSandboxMetadata(podSandboxName, uid, namespace, framework.DefaultAttempt),
Linux: &runtimeapi.LinuxPodSandboxConfig{
Sysctls: sysctls,
CgroupParent: common.GetCgroupParent(context.TODO(), rc),
Sysctls: sysctls,
},
}
return framework.RunPodSandbox(rc, podConfig), podConfig
4 changes: 4 additions & 0 deletions pkg/validate/security_context_linux.go
Original file line number Diff line number Diff line change
@@ -26,6 +26,7 @@ import (
"strings"
"time"

"github.com/kubernetes-sigs/cri-tools/pkg/common"
"github.com/kubernetes-sigs/cri-tools/pkg/framework"
internalapi "k8s.io/cri-api/pkg/apis"
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
@@ -950,6 +951,7 @@ func createNamespacePodSandbox(rc internalapi.RuntimeService, podSandboxNamespac
SecurityContext: &runtimeapi.LinuxSandboxSecurityContext{
NamespaceOptions: podSandboxNamespace,
},
CgroupParent: common.GetCgroupParent(context.TODO(), rc),
},
LogDirectory: podLogPath,
Labels: framework.DefaultPodLabels,
@@ -1022,6 +1024,7 @@ func createPrivilegedPodSandbox(rc internalapi.RuntimeService, privileged bool)
SecurityContext: &runtimeapi.LinuxSandboxSecurityContext{
Privileged: privileged,
},
CgroupParent: common.GetCgroupParent(context.TODO(), rc),
},
Labels: framework.DefaultPodLabels,
}
@@ -1158,6 +1161,7 @@ func seccompTestContainer(rc internalapi.RuntimeService, ic internalapi.ImageMan
SecurityContext: &runtimeapi.LinuxSandboxSecurityContext{
Seccomp: profile,
},
CgroupParent: common.GetCgroupParent(context.TODO(), rc),
},
Labels: framework.DefaultPodLabels,
}