Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions validators/cgroup_validator_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ package system

var _ Validator = &CgroupsValidator{}

const mountsFilePath = ""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not needed? the definition of mountsFilePath is only required in the linux file, as far as i can tell.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

never mind, it's referenced in validators/kernel_validator.go


// CgroupsValidator validates cgroup configuration.
type CgroupsValidator struct {
Reporter Reporter
Expand All @@ -37,3 +39,8 @@ func (c *CgroupsValidator) Validate(spec SysSpec) (warns, errs []error) {
func (c *CgroupsValidator) Name() string {
return "cgroups"
}

// getUnifiedMountpoint is a no-op for non-Linux OSes.
func getUnifiedMountpoint(path string) (string, bool, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, how did this compile before?
weren't we supposed to get an error if this function was missing on non-Linux?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getUnifiedMountpoint is implemented in linux only and was only used in that linux go as well.
However, we want to use it in validators/kernel_validator.go in this PR.

  • Adding new validators/kernel_validator_linux.go and validators/kernel_validator_other.go is too complex. So I added this here.

return "", false, nil
}
17 changes: 16 additions & 1 deletion validators/kernel_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ func (k *KernelValidator) Validate(spec SysSpec) ([]error, []error) {
warns = append(warns, warn)
}
// only validate kernel config when necessary (currently no kernel config for windows)
if len(spec.KernelSpec.Required) > 0 || len(spec.KernelSpec.Forbidden) > 0 || len(spec.KernelSpec.Optional) > 0 {
if len(spec.KernelSpec.Required) > 0 || len(spec.KernelSpec.Forbidden) > 0 || len(spec.KernelSpec.Optional) > 0 ||
len(spec.KernelSpec.RequiredCgroupsV1) > 0 || len(spec.KernelSpec.RequiredCgroupsV2) > 0 {
if err = k.validateKernelConfig(spec.KernelSpec); err != nil {
errs = append(errs, err)
}
Expand Down Expand Up @@ -158,6 +159,20 @@ func (k *KernelValidator) validateCachedKernelConfig(allConfig map[string]kConfi
for _, config := range kSpec.Required {
validateOpt(config, required)
}
_, isCgroupsV2, err := getUnifiedMountpoint(mountsFilePath)
if err != nil {
return fmt.Errorf("failed to get unified mountpoint: %w", err)
}
if isCgroupsV2 {
for _, config := range kSpec.RequiredCgroupsV2 {
validateOpt(config, required)
}
} else {
for _, config := range kSpec.RequiredCgroupsV1 {
validateOpt(config, required)
}
}

for _, config := range kSpec.Optional {
validateOpt(config, optional)
}
Expand Down
5 changes: 5 additions & 0 deletions validators/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ type KernelSpec struct {
VersionsNote string `json:"versionsNote,omitempty"`
// Required contains all kernel configurations required to be enabled
// (built in or as module).
// RequiredCgroupsV1 and RequiredCgroupsV2 are mutually exclusive.
Required []KernelConfig `json:"required,omitempty"`
// RequiredCgroupsV1 contains all kernel configurations required to be enabled for cgroups v1.
RequiredCgroupsV1 []KernelConfig `json:"requiredCgroupsV1,omitempty"`
// RequiredCgroupsV2 contains all kernel configurations required to be enabled for cgroups v2.
RequiredCgroupsV2 []KernelConfig `json:"requiredCgroupsV2,omitempty"`
// Optional contains all kernel configurations are required for optional
// features.
Optional []KernelConfig `json:"optional,omitempty"`
Expand Down
15 changes: 14 additions & 1 deletion validators/types_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ var DefaultSysSpec = SysSpec{
{Name: "PID_NS"},
{Name: "IPC_NS"},
{Name: "UTS_NS"},
{Name: "CGROUPS"},
{Name: "CPUSETS"},
{Name: "MEMCG"},
{Name: "INET"},
Expand All @@ -51,6 +50,20 @@ var DefaultSysSpec = SysSpec{
{Name: "NETFILTER_XT_MATCH_COMMENT"},
{Name: "FAIR_GROUP_SCHED"},
},
RequiredCgroupsV1: []KernelConfig{
{Name: "CGROUPS", Description: "Required for cgroups."},
{Name: "CGROUP_CPUACCT", Description: "Required for cpuacct controller, used in simple CPU accounting controller."},
{Name: "CGROUP_DEVICE", Description: "Required for device controller."},
{Name: "CGROUP_FREEZER", Description: "Required for freezer controller."},
{Name: "CGROUP_PIDS", Description: "Required for PIDs controller."},
{Name: "CGROUP_SCHED", Description: "Required for CPU controller."},
},
RequiredCgroupsV2: []KernelConfig{
{Name: "CGROUPS", Description: "Required for cgroups."},
{Name: "CGROUP_BPF", Description: "Required for eBPF programs attached to cgroups, used in device controller."},
{Name: "CGROUP_PIDS", Description: "Required for PIDs controller."},
{Name: "CGROUP_SCHED", Description: "Required for CPU controller."},
},
Optional: []KernelConfig{
{Name: "OVERLAY_FS", Aliases: []string{"OVERLAYFS_FS"}, Description: "Required for overlayfs."},
{Name: "AUFS_FS", Description: "Required for aufs."},
Expand Down