feat: first pass at implement resource limitation on a pre-process basis
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
)
|
||||
|
||||
// outputs the process-specific docker options
|
||||
func main() {
|
||||
stdin, err := ioutil.ReadAll(os.Stdin)
|
||||
if err != nil {
|
||||
common.LogFail(err.Error())
|
||||
}
|
||||
|
||||
flag.Parse()
|
||||
appName := flag.Arg(0)
|
||||
procType := flag.Arg(3)
|
||||
|
||||
resources, err := common.PropertyGetAll("resource", appName)
|
||||
if err != nil {
|
||||
fmt.Print(string(stdin))
|
||||
common.LogFail(err.Error())
|
||||
}
|
||||
|
||||
limits := make(map[string]string)
|
||||
reservations := make(map[string]string)
|
||||
|
||||
validLimits := map[string]bool{
|
||||
"cpu": true,
|
||||
"memory": true,
|
||||
"memory-swap": true,
|
||||
}
|
||||
validReservations := map[string]bool{
|
||||
"memory": true,
|
||||
}
|
||||
validPrefixes := []string{"_default_.", fmt.Sprintf("%s.", procType)}
|
||||
for _, validPrefix := range validPrefixes {
|
||||
for key, value := range resources {
|
||||
if !strings.HasPrefix(key, validPrefix) {
|
||||
continue
|
||||
}
|
||||
parts := strings.SplitN(strings.TrimPrefix(key, validPrefix), ".", 2)
|
||||
if parts[0] == "limit" {
|
||||
if !validLimits[parts[1]] {
|
||||
continue
|
||||
}
|
||||
|
||||
limits[parts[1]] = value
|
||||
}
|
||||
if parts[0] == "reserve" {
|
||||
if !validReservations[parts[1]] {
|
||||
continue
|
||||
}
|
||||
|
||||
reservations[parts[1]] = value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for key, value := range limits {
|
||||
fmt.Print(" --%s=%s ", key, value)
|
||||
}
|
||||
|
||||
for key, value := range reservations {
|
||||
fmt.Print(" --%s-reservation=%s ", key, value)
|
||||
}
|
||||
|
||||
fmt.Print(string(stdin))
|
||||
}
|
||||
Reference in New Issue
Block a user