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

+19 -6
View File
@@ -71,22 +71,30 @@ func TriggerDockerArgsProcessDeploy(appName string, processType string) error {
}
}
var args strings.Builder
for key, value := range limits {
if value == "" {
continue
}
value = addMemorySuffixForDocker(key, value)
fmt.Printf(" --%s=%s ", key, value)
value, err := formatResourceValueForDocker(key, value)
if err != nil {
return fmt.Errorf("Unable to apply resource limits for %s: %w", appName, err)
}
fmt.Fprintf(&args, " --%s=%s ", key, value)
}
for key, value := range reservations {
if value == "" {
continue
}
value = addMemorySuffixForDocker(key, value)
fmt.Printf(" --%s-reservation=%s ", key, value)
value, err := formatResourceValueForDocker(key, value)
if err != nil {
return fmt.Errorf("Unable to apply resource reservations for %s: %w", appName, err)
}
fmt.Fprintf(&args, " --%s-reservation=%s ", key, value)
}
fmt.Print(args.String())
fmt.Print(string(stdin))
return nil
}
@@ -136,14 +144,19 @@ func TriggerDockerArgsProcessBuild(appName string, builderType string) error {
limits[flagName] = value
}
var args strings.Builder
for key, value := range limits {
if value == "" {
continue
}
value = addMemorySuffixForDocker(key, value)
fmt.Printf(" --%s=%s ", key, value)
value, err := formatResourceValueForDocker(key, value)
if err != nil {
return fmt.Errorf("Unable to apply build resource limits for %s: %w", appName, err)
}
fmt.Fprintf(&args, " --%s=%s ", key, value)
}
fmt.Print(args.String())
fmt.Print(string(stdin))
return nil
}