QoS-class resource configuration

Problem:
Configuring qos-class features in containerd requres a custom containerd configuration template.

Solution:
Look for configuration files in default locations and configure containerd to use them if they exist.

Signed-off-by: Oliver Larsson <larsson.e.oliver@gmail.com>
pull/8861/head
Oliver Larsson 2023-10-26 11:51:25 +02:00 committed by Brad Davidson
parent 32a1efa408
commit 30c8ad926d
5 changed files with 45 additions and 9 deletions

View File

@ -558,6 +558,7 @@ func get(ctx context.Context, envInfo *cmds.Agent, proxy proxy.Proxy) (*config.N
nodeConfig.Containerd.Debug = envInfo.Debug nodeConfig.Containerd.Debug = envInfo.Debug
applyContainerdStateAndAddress(nodeConfig) applyContainerdStateAndAddress(nodeConfig)
applyCRIDockerdAddress(nodeConfig) applyCRIDockerdAddress(nodeConfig)
applyContainerdQoSClassConfigFileIfPresent(envInfo, nodeConfig)
nodeConfig.Containerd.Template = filepath.Join(envInfo.DataDir, "agent", "etc", "containerd", "config.toml.tmpl") nodeConfig.Containerd.Template = filepath.Join(envInfo.DataDir, "agent", "etc", "containerd", "config.toml.tmpl")
nodeConfig.Certificate = servingCert nodeConfig.Certificate = servingCert

View File

@ -4,9 +4,13 @@
package config package config
import ( import (
"errors"
"os"
"path/filepath" "path/filepath"
"github.com/k3s-io/k3s/pkg/cli/cmds"
"github.com/k3s-io/k3s/pkg/daemons/config" "github.com/k3s-io/k3s/pkg/daemons/config"
"github.com/sirupsen/logrus"
) )
func applyContainerdStateAndAddress(nodeConfig *config.Node) { func applyContainerdStateAndAddress(nodeConfig *config.Node) {
@ -17,3 +21,21 @@ func applyContainerdStateAndAddress(nodeConfig *config.Node) {
func applyCRIDockerdAddress(nodeConfig *config.Node) { func applyCRIDockerdAddress(nodeConfig *config.Node) {
nodeConfig.CRIDockerd.Address = "unix:///run/k3s/cri-dockerd/cri-dockerd.sock" nodeConfig.CRIDockerd.Address = "unix:///run/k3s/cri-dockerd/cri-dockerd.sock"
} }
func applyContainerdQoSClassConfigFileIfPresent(envInfo *cmds.Agent, nodeConfig *config.Node) {
blockioPath := filepath.Join(envInfo.DataDir, "agent", "etc", "containerd", "blockio_config.yaml")
// Set containerd config if file exists
if _, err := os.Stat(blockioPath); !errors.Is(err, os.ErrNotExist) {
logrus.Infof("BlockIO configuration file found")
nodeConfig.Containerd.BlockIOConfig = blockioPath
}
rdtPath := filepath.Join(envInfo.DataDir, "agent", "etc", "containerd", "rdt_config.yaml")
// Set containerd config if file exists
if _, err := os.Stat(rdtPath); !errors.Is(err, os.ErrNotExist) {
logrus.Infof("RDT configuration file found")
nodeConfig.Containerd.RDTConfig = rdtPath
}
}

View File

@ -6,6 +6,7 @@ package config
import ( import (
"path/filepath" "path/filepath"
"github.com/k3s-io/k3s/pkg/cli/cmds"
"github.com/k3s-io/k3s/pkg/daemons/config" "github.com/k3s-io/k3s/pkg/daemons/config"
) )
@ -17,3 +18,7 @@ func applyContainerdStateAndAddress(nodeConfig *config.Node) {
func applyCRIDockerdAddress(nodeConfig *config.Node) { func applyCRIDockerdAddress(nodeConfig *config.Node) {
nodeConfig.CRIDockerd.Address = "npipe:////.pipe/cri-dockerd" nodeConfig.CRIDockerd.Address = "npipe:////.pipe/cri-dockerd"
} }
func applyContainerdQoSClassConfigFileIfPresent(envInfo *cmds.Agent, nodeConfig *config.Node) {
// QoS-class resource management not supported on windows.
}

View File

@ -82,6 +82,12 @@ enable_keychain = true
conf_dir = "{{ .NodeConfig.AgentConfig.CNIConfDir }}" conf_dir = "{{ .NodeConfig.AgentConfig.CNIConfDir }}"
{{end}} {{end}}
{{- if or .NodeConfig.Containerd.BlockIOConfig .NodeConfig.Containerd.RDTConfig }}
[plugins."io.containerd.service.v1.tasks-service"]
{{ if .NodeConfig.Containerd.BlockIOConfig }}blockio_config_file = "{{ .NodeConfig.Containerd.BlockIOConfig }}"{{end}}
{{ if .NodeConfig.Containerd.RDTConfig }}rdt_config_file = "{{ .NodeConfig.Containerd.RDTConfig }}"{{end}}
{{end}}
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc] [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc]
runtime_type = "io.containerd.runc.v2" runtime_type = "io.containerd.runc.v2"

View File

@ -58,15 +58,17 @@ type Node struct {
} }
type Containerd struct { type Containerd struct {
Address string Address string
Log string Log string
Root string Root string
State string State string
Config string Config string
Opt string Opt string
Template string Template string
SELinux bool BlockIOConfig string
Debug bool RDTConfig string
SELinux bool
Debug bool
} }
type CRIDockerd struct { type CRIDockerd struct {