feat: first pass at implement resource limitation on a pre-process basis

This commit is contained in:
Jose Diaz-Gonzalez
2019-03-18 18:21:44 -04:00
parent e8134f9c2c
commit 00c9e5a5e9
7 changed files with 138 additions and 3 deletions

View File

@@ -4,3 +4,5 @@
/install
/post-delete
/report
/docker-args-process-deploy
/docker-args-process-run

View File

@@ -3,7 +3,7 @@ include ../../common.mk
GO_ARGS ?= -a
SUBCOMMANDS = subcommands/limit subcommands/limit-clear subcommands/report subcommands/reserve subcommands/reserve-clear
TRIGGERS = triggers/install triggers/post-delete triggers/report
TRIGGERS = triggers/docker-args-process-deploy triggers/install triggers/post-delete triggers/report
build-in-docker: clean
docker run --rm \
-v $$PWD/../..:$(GO_REPO_ROOT) \
@@ -23,7 +23,7 @@ subcommands/%: src/subcommands/*/%.go
go build $(GO_ARGS) -o $@ $<
clean:
rm -rf commands subcommands triggers install post-delete report
rm -rf commands subcommands triggers docker-args-process-deploy docker-args-process-run install post-delete report
src-clean:
rm -rf .gitignore src triggers vendor Makefile *.go
@@ -35,3 +35,4 @@ triggers/%: src/triggers/*/%.go
triggers-copy:
cp triggers/* .
ln -s docker-args-process-deploy docker-args-process-run

View File

@@ -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))
}

View File

@@ -6,7 +6,7 @@ import (
"github.com/dokku/dokku/plugins/resource"
)
// displays a buildpacks report for one or more apps
// displays a resource report for one or more apps
func main() {
flag.Parse()
appName := flag.Arg(0)