-
Notifications
You must be signed in to change notification settings - Fork 949
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: cli supports --memory-reservation
Signed-off-by: KevinBetterQ <1093850932@qq.com>
- Loading branch information
1 parent
7235f82
commit 41c9d02
Showing
11 changed files
with
241 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package opts | ||
|
||
import units "github.com/docker/go-units" | ||
|
||
// ParseMemoryReservation parses the memory-reservation param of container. | ||
func ParseMemoryReservation(memoryReservation string) (int64, error) { | ||
if memoryReservation == "" { | ||
return 0, nil | ||
} | ||
return units.RAMInBytes(memoryReservation) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package opts | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestParseMemoryReservation(t *testing.T) { | ||
type result struct { | ||
memoryReservation int64 | ||
err error | ||
} | ||
type TestCase struct { | ||
input string | ||
expected result | ||
} | ||
|
||
testCases := []TestCase{ | ||
{ | ||
input: "", | ||
expected: result{ | ||
memoryReservation: 0, | ||
err: nil, | ||
}, | ||
}, | ||
{ | ||
input: "0", | ||
expected: result{ | ||
memoryReservation: 0, | ||
err: nil, | ||
}, | ||
}, | ||
{ | ||
input: "100m", | ||
expected: result{ | ||
memoryReservation: 104857600, | ||
err: nil, | ||
}, | ||
}, | ||
{ | ||
input: "10invalid", | ||
expected: result{ | ||
memoryReservation: -1, | ||
err: fmt.Errorf("invalid size: '%s'", "10invalid"), | ||
}, | ||
}, | ||
} | ||
|
||
for _, testCase := range testCases { | ||
memoryReservation, err := ParseMemoryReservation(testCase.input) | ||
assert.Equal(t, testCase.expected.err, err) | ||
assert.Equal(t, testCase.expected.memoryReservation, memoryReservation) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters