mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-24 09:18:31 +02:00
refactor(docker): streamline idlewatcher label handling
- Introduced a map for idlewatcher labels to simplify the loading of configuration values. - Simplify logic to check for the presence of an idle timeout and handle dependencies.
This commit is contained in:
@@ -237,23 +237,25 @@ func setPrivateHostname(c *types.Container, helper containerHelper) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func loadDeleteIdlewatcherLabels(c *types.Container, helper containerHelper) {
|
func loadDeleteIdlewatcherLabels(c *types.Container, helper containerHelper) {
|
||||||
cfg := map[string]any{
|
hasIdleTimeout := false
|
||||||
"idle_timeout": helper.getDeleteLabel(LabelIdleTimeout),
|
cfg := make(map[string]any, len(idlewatcherLabels))
|
||||||
"wake_timeout": helper.getDeleteLabel(LabelWakeTimeout),
|
for lbl, key := range idlewatcherLabels {
|
||||||
"stop_method": helper.getDeleteLabel(LabelStopMethod),
|
if value := helper.getDeleteLabel(lbl); value != "" {
|
||||||
"stop_timeout": helper.getDeleteLabel(LabelStopTimeout),
|
cfg[key] = value
|
||||||
"stop_signal": helper.getDeleteLabel(LabelStopSignal),
|
}
|
||||||
"start_endpoint": helper.getDeleteLabel(LabelStartEndpoint),
|
switch lbl {
|
||||||
"depends_on": Dependencies(c),
|
case LabelIdleTimeout:
|
||||||
"no_loading_page": helper.getDeleteLabel(LabelNoLoadingPage),
|
hasIdleTimeout = true
|
||||||
|
case LabelDependsOn:
|
||||||
|
cfg[key] = Dependencies(c)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensure it's deleted from labels
|
// ensure it's deleted from labels
|
||||||
helper.getDeleteLabel(LabelDependsOn)
|
helper.getDeleteLabel(LabelDependsOn)
|
||||||
|
|
||||||
// set only if idlewatcher is enabled
|
// set only if idlewatcher is enabled
|
||||||
idleTimeout := cfg["idle_timeout"]
|
if hasIdleTimeout {
|
||||||
if idleTimeout != "" {
|
|
||||||
idwCfg := new(types.IdlewatcherConfig)
|
idwCfg := new(types.IdlewatcherConfig)
|
||||||
idwCfg.Docker = &types.DockerConfig{
|
idwCfg.Docker = &types.DockerConfig{
|
||||||
DockerHost: c.DockerHost,
|
DockerHost: c.DockerHost,
|
||||||
|
|||||||
@@ -17,3 +17,15 @@ const (
|
|||||||
LabelNoLoadingPage = NSProxy + ".no_loading_page" // No loading page when using idlewatcher
|
LabelNoLoadingPage = NSProxy + ".no_loading_page" // No loading page when using idlewatcher
|
||||||
LabelNetwork = NSProxy + ".network"
|
LabelNetwork = NSProxy + ".network"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// key: label, value: key in IdlewatcherConfig
|
||||||
|
var idlewatcherLabels = map[string]string{
|
||||||
|
LabelIdleTimeout: "idle_timeout",
|
||||||
|
LabelWakeTimeout: "wake_timeout",
|
||||||
|
LabelStopMethod: "stop_method",
|
||||||
|
LabelStopTimeout: "stop_timeout",
|
||||||
|
LabelStopSignal: "stop_signal",
|
||||||
|
LabelStartEndpoint: "start_endpoint",
|
||||||
|
LabelDependsOn: "depends_on",
|
||||||
|
LabelNoLoadingPage: "no_loading_page",
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user