Skip to content

Commit

Permalink
Merge pull request #10575 from hetong07/issue_10519
Browse files Browse the repository at this point in the history
Improve the error message of setting cgroup memory limit.
  • Loading branch information
medyagh authored Feb 24, 2021
2 parents 5a6ff99 + 56cf965 commit 460342a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
25 changes: 17 additions & 8 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -1076,14 +1076,7 @@ func validateFlags(cmd *cobra.Command, drvName string) {
validateCPUCount(drvName)

if cmd.Flags().Changed(memory) {
if !driver.HasResourceLimits(drvName) {
out.WarningT("The '{{.name}}' driver does not respect the --memory flag", out.V{"name": drvName})
}
req, err := util.CalculateSizeInMB(viper.GetString(memory))
if err != nil {
exitIfNotForced(reason.Usage, "Unable to parse memory '{{.memory}}': {{.error}}", out.V{"memory": viper.GetString(memory), "error": err})
}
validateRequestedMemorySize(req, drvName)
validateChangedMemoryFlags(drvName)
}

if cmd.Flags().Changed(containerRuntime) {
Expand Down Expand Up @@ -1173,6 +1166,22 @@ func validateFlags(cmd *cobra.Command, drvName string) {

}

// validateChangedMemoryFlags validates memory related flags.
func validateChangedMemoryFlags(drvName string) {
if driver.IsKIC(drvName) && !oci.HasMemoryCgroup() {
out.WarningT("Your cgroup does not allow setting memory.")
out.Infof("More information: https://docs.doInfo.com/engine/install/linux-postinstall/#your-kernel-does-not-support-cgroup-swap-limit-capabilities")
}
if !driver.HasResourceLimits(drvName) {
out.WarningT("The '{{.name}}' driver does not respect the --memory flag", out.V{"name": drvName})
}
req, err := util.CalculateSizeInMB(viper.GetString(memory))
if err != nil {
exitIfNotForced(reason.Usage, "Unable to parse memory '{{.memory}}': {{.error}}", out.V{"memory": viper.GetString(memory), "error": err})
}
validateRequestedMemorySize(req, drvName)
}

// This function validates if the --registry-mirror
// args match the format of http://localhost
func validateRegistryMirror() {
Expand Down
6 changes: 3 additions & 3 deletions pkg/drivers/kic/oci/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ func PrepareContainerNode(p CreateParams) error {
return nil
}

func hasMemoryCgroup() bool {
// HasMemoryCgroup checks whether it is possible to set memory limit for cgroup.
func HasMemoryCgroup() bool {
memcg := true
if runtime.GOOS == "linux" {
var memory string
Expand All @@ -116,7 +117,6 @@ func hasMemoryCgroup() bool {
}
if _, err := os.Stat(memory); os.IsNotExist(err) {
klog.Warning("Your kernel does not support memory limit capabilities or the cgroup is not mounted.")
out.WarningT("Cgroup v2 does not allow setting memory, if you want to set memory, please modify your Grub as instructed in https://docs.docker.com/engine/install/linux-postinstall/#your-kernel-does-not-support-cgroup-swap-limit-capabilities")
memcg = false
}
}
Expand Down Expand Up @@ -185,7 +185,7 @@ func CreateContainerNode(p CreateParams) error {
}

memcgSwap := hasMemorySwapCgroup()
memcg := hasMemoryCgroup()
memcg := HasMemoryCgroup()

// https://www.freedesktop.org/wiki/Software/systemd/ContainerInterface/
var virtualization string
Expand Down

0 comments on commit 460342a

Please sign in to comment.