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

+41
View File
@@ -487,6 +487,47 @@ func TestDomainSlug(t *testing.T) {
}
}
func TestParseMemoryQuantity(t *testing.T) {
cases := []struct {
name string
input string
want string
wantErr bool
}{
{name: "unitless value defaults to megabytes", input: "512", want: "512Mi"},
{name: "lowercase megabytes are not millibytes", input: "256m", want: "256Mi"},
{name: "uppercase gigabytes are binary", input: "1G", want: "1Gi"},
{name: "lowercase gigabytes", input: "1g", want: "1Gi"},
{name: "kubernetes binary unit", input: "1Gi", want: "1Gi"},
{name: "two letter unit", input: "512MB", want: "512Mi"},
{name: "decimal value", input: "1.5g", want: "1536Mi"},
{name: "bytes", input: "100b", want: "100"},
{name: "zero", input: "0Mi", want: "0"},
{name: "invalid unit", input: "1x", wantErr: true},
{name: "kubernetes exponent", input: "1e9", wantErr: true},
}
for _, tc := range cases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
got, err := parseMemoryQuantity(tc.input)
if tc.wantErr {
if err == nil {
t.Fatalf("parseMemoryQuantity(%q) = %q, want error", tc.input, got)
}
return
}
if err != nil {
t.Fatalf("parseMemoryQuantity(%q) unexpected error: %v", tc.input, err)
}
if got != tc.want {
t.Errorf("parseMemoryQuantity(%q) = %q, want %q", tc.input, got, tc.want)
}
})
}
}
func TestDomainSlugDistinguishesWildcardFromApex(t *testing.T) {
// A kubernetes wildcard host matches exactly one label, so *.example.com does not
// cover example.com and both are commonly added to the same app. The generated