mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-19 20:32:35 +02:00
fixed container being excluded in host network_mode
This commit is contained in:
parent
71e8e4a462
commit
109c2460fa
5 changed files with 36 additions and 49 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -15,4 +15,6 @@ go.work.sum
|
|||
|
||||
!src/**/
|
||||
|
||||
todo.md
|
||||
todo.md
|
||||
|
||||
.*.swp
|
|
@ -1,39 +0,0 @@
|
|||
From 6728bc39d2d7ded19c1ca288691ec787c02ff666 Mon Sep 17 00:00:00 2001
|
||||
From: yusing <yusing@6uo.me>
|
||||
Date: Mon, 23 Sep 2024 07:19:47 +0800
|
||||
Subject: [PATCH] fixed nil dereferencing
|
||||
|
||||
---
|
||||
frontend | 2 +-
|
||||
src/error/builder.go | 6 ++++--
|
||||
2 files changed, 5 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/frontend b/frontend
|
||||
index d0e5963..441fd70 160000
|
||||
--- a/frontend
|
||||
+++ b/frontend
|
||||
@@ -1 +1 @@
|
||||
-Subproject commit d0e59630d6e0beb1c22d2f242f556464a5056c1f
|
||||
+Subproject commit 441fd708dbed89c59bf72a742431a78ff2f02bc3
|
||||
diff --git a/src/error/builder.go b/src/error/builder.go
|
||||
index 38a1bf2..16d2816 100644
|
||||
--- a/src/error/builder.go
|
||||
+++ b/src/error/builder.go
|
||||
@@ -60,10 +60,12 @@ func (b Builder) Build() NestedError {
|
||||
}
|
||||
|
||||
func (b Builder) To(ptr *NestedError) {
|
||||
- if *ptr == nil {
|
||||
+ if ptr == nil {
|
||||
+ return
|
||||
+ } else if *ptr == nil {
|
||||
*ptr = b.Build()
|
||||
} else {
|
||||
- **ptr = *b.Build()
|
||||
+ (*ptr).With(b.Build())
|
||||
}
|
||||
}
|
||||
|
||||
--
|
||||
2.46.1
|
||||
|
|
@ -15,14 +15,16 @@ type ProxyProperties struct {
|
|||
ImageName string `yaml:"-" json:"image_name"`
|
||||
PublicPortMapping PortMapping `yaml:"-" json:"public_port_mapping"` // non-zero publicPort:types.Port
|
||||
PrivatePortMapping PortMapping `yaml:"-" json:"private_port_mapping"` // privatePort:types.Port
|
||||
Aliases []string `yaml:"-" json:"aliases"`
|
||||
IsExcluded bool `yaml:"-" json:"is_excluded"`
|
||||
IdleTimeout string `yaml:"-" json:"idle_timeout"`
|
||||
WakeTimeout string `yaml:"-" json:"wake_timeout"`
|
||||
StopMethod string `yaml:"-" json:"stop_method"`
|
||||
StopTimeout string `yaml:"-" json:"stop_timeout"` // stop_method = "stop" only
|
||||
StopSignal string `yaml:"-" json:"stop_signal"` // stop_method = "stop" | "kill" only
|
||||
Running bool `yaml:"-" json:"running"`
|
||||
NetworkMode string `yaml:"-" json:"network_mode"`
|
||||
|
||||
Aliases []string `yaml:"-" json:"aliases"`
|
||||
IsExcluded bool `yaml:"-" json:"is_excluded"`
|
||||
IdleTimeout string `yaml:"-" json:"idle_timeout"`
|
||||
WakeTimeout string `yaml:"-" json:"wake_timeout"`
|
||||
StopMethod string `yaml:"-" json:"stop_method"`
|
||||
StopTimeout string `yaml:"-" json:"stop_timeout"` // stop_method = "stop" only
|
||||
StopSignal string `yaml:"-" json:"stop_signal"` // stop_method = "stop" | "kill" only
|
||||
Running bool `yaml:"-" json:"running"`
|
||||
}
|
||||
|
||||
type Container struct {
|
||||
|
@ -40,6 +42,7 @@ func FromDocker(c *types.Container, dockerHost string) (res Container) {
|
|||
ImageName: res.getImageName(),
|
||||
PublicPortMapping: res.getPublicPortMapping(),
|
||||
PrivatePortMapping: res.getPrivatePortMapping(),
|
||||
NetworkMode: c.HostConfig.NetworkMode,
|
||||
Aliases: res.getAliases(),
|
||||
IsExcluded: U.ParseBool(res.getDeleteLabel(LabelExclude)),
|
||||
IdleTimeout: res.getDeleteLabel(LabelIdleTimeout),
|
||||
|
|
|
@ -54,7 +54,7 @@ func (e *RawEntry) FillMissingFields() bool {
|
|||
}
|
||||
}
|
||||
|
||||
if e.PublicPortMapping != nil {
|
||||
if e.PublicPortMapping != nil && e.NetworkMode != "host" {
|
||||
if _, ok := e.PublicPortMapping[e.Port]; !ok { // port is not exposed, but specified
|
||||
// try to fallback to first public port
|
||||
if len(e.PublicPortMapping) == 0 {
|
||||
|
|
|
@ -288,3 +288,24 @@ func TestExcludeNonExposedPort(t *testing.T) {
|
|||
_, ok := entries.Load("redis")
|
||||
ExpectFalse(t, ok)
|
||||
}
|
||||
|
||||
func TestNotExcludeNonExposedPortHostNetwork(t *testing.T) {
|
||||
var p DockerProvider
|
||||
cont := &types.Container{
|
||||
Image: "redis",
|
||||
Names: []string{"redis"},
|
||||
Ports: []types.Port{
|
||||
{Type: "tcp", PrivatePort: 6379, PublicPort: 0}, // not exposed
|
||||
},
|
||||
Labels: map[string]string{
|
||||
"proxy.redis.port": "6379:6379", // should be excluded even specified
|
||||
},
|
||||
}
|
||||
cont.HostConfig.NetworkMode = "host"
|
||||
|
||||
entries, err := p.entriesFromContainerLabels(D.FromDocker(cont, ""))
|
||||
ExpectNoError(t, err.Error())
|
||||
|
||||
_, ok := entries.Load("redis")
|
||||
ExpectTrue(t, ok)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue