fix: accept all docker memory units in resource values

Memory values with uppercase or other docker-supported units such as `1G`, `512M` or `1GiB` are now passed to docker unchanged instead of having an extra `m` appended, and the k3s scheduler interprets memory values with the same binary units so a value means the same thing on both schedulers. Invalid `--memory` and `--memory-swap` values are now rejected by `resource:limit` and `resource:reserve`. Closes #9153.
This commit is contained in:
Jose Diaz-Gonzalez committed 2026-10-21 14:07:00 -04:00
1 parent fa0f031560
commit c8e28c2445
13 files changed
+382 -30

No files matched your search

+5 -8
View File
@@ -1946,7 +1946,7 @@ func getProcessResources(appName string, processType string) (ProcessResourcesMa
if err != nil {
return ProcessResourcesMap{}, fmt.Errorf("Error parsing memory limit: %w", err)
}
if quantity != "0Mi" {
if quantity != "0" {
processResources.Limits.Memory = quantity
} else {
processResources.Limits.Memory = ""
@@ -1977,7 +1977,7 @@ func getProcessResources(appName string, processType string) (ProcessResourcesMa
if err != nil {
return ProcessResourcesMap{}, fmt.Errorf("Error parsing memory request: %w", err)
}
if quantity != "0Mi" {
if quantity != "0" {
processResources.Requests.Memory = quantity
} else {
processResources.Requests.Memory = ""
@@ -2720,17 +2720,14 @@ func cronIDLabelValue(cronID string) string {
return hex.EncodeToString(sum[:])
}
// parseMemoryQuantity parses a string into a valid memory quantity
// parseMemoryQuantity parses a docker-compatible memory value into a binary memory quantity
func parseMemoryQuantity(input string) (string, error) {
if _, err := strconv.ParseInt(input, 10, 64); err == nil {
input = fmt.Sprintf("%sMi", input)
}
quantity, err := resource.ParseQuantity(input)
bytes, err := common.ParseMemoryBytes(input)
if err != nil {
return "", err
}
return quantity.String(), nil
return resource.NewQuantity(bytes, resource.BinarySI).String(), nil
}
func uninstallHelperCommands(ctx context.Context) error {