Handle signals, code cleanup, easier labels

This commit is contained in:
Christopher LaPointe
2023-05-26 19:52:17 -04:00
parent af94d29dd3
commit ebb45b55c3
10 changed files with 123 additions and 124 deletions

View File

@@ -1,19 +1,19 @@
package service
import (
"strconv"
"strings"
"time"
"traefik-lazyload/pkg/config"
"github.com/docker/docker/api/types"
"github.com/sirupsen/logrus"
)
type containerSettings struct {
stopDelay time.Duration
waitForCode int
waitForPath string
stopDelay time.Duration
waitForCode int
waitForPath string
waitForMethod string
needs []string
}
type ContainerState struct {
@@ -34,26 +34,11 @@ func newStateFromContainer(ct *types.Container) *ContainerState {
}
func extractContainerLabels(ct *types.Container) (target containerSettings) {
{ // Parse stop delay
stopDelay, _ := labelOrDefault(ct, "stopdelay", config.Model.StopDelay.String())
if dur, stopErr := time.ParseDuration(stopDelay); stopErr != nil {
target.stopDelay = config.Model.StopDelay
logrus.Warnf("Unable to parse stopdelay for %s of %s, defaulting to %s", containerShort(ct), stopDelay, target.stopDelay.String())
} else {
target.stopDelay = dur
}
}
{ // WaitForCode
codeStr, _ := labelOrDefault(ct, "waitforcode", "200")
if code, err := strconv.Atoi(codeStr); err != nil {
target.waitForCode = 200
logrus.Warnf("Unable to parse WaitForCode of %s, defaulting to %d", containerShort(ct), target.waitForCode)
} else {
target.waitForCode = code
}
}
target.stopDelay, _ = labelOrDefaultDuration(ct, "stopdelay", config.Model.StopDelay)
target.waitForCode, _ = labelOrDefaultInt(ct, "waitforcode", 200)
target.waitForPath, _ = labelOrDefault(ct, "waitforpath", "/")
target.waitForMethod, _ = labelOrDefault(ct, "waitformethod", "HEAD")
target.needs, _ = labelOrDefaultArr(ct, "needs")
return
}
@@ -85,6 +70,19 @@ func (s *containerSettings) StopDelay() string {
return s.stopDelay.String()
}
func (s *ContainerState) WaitForCode() int {
return s.waitForCode
}
func (s *ContainerState) WaitForPath() string {
return s.waitForPath
}
func (s *ContainerState) WaitForMethod() string {
return s.waitForMethod
}
// Wrapper for container results that opaques and adds some methods to that data
type ContainerWrapper struct {
types.Container
}