Skip to content

Commit 9cb294f

Browse files
committed
DO_NOT_RESOLVE_ADDR
1 parent 2b98745 commit 9cb294f

File tree

5 files changed

+39
-5
lines changed

5 files changed

+39
-5
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ ENV CERTS="" \
2020
CONNECTION_MODE="http-keep-alive" \
2121
DEBUG="false" \
2222
DEFAULT_PORTS="80,443:ssl" \
23+
DO_NOT_RESOLVE_ADDR="true" \
2324
EXTRA_FRONTEND="" \
2425
LISTENER_ADDRESS="" \
2526
MODE="default" \

docs/blocking.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ chmod +x swarm-cluster.sh
3030
eval $(docker-machine env node-1)
3131
```
3232

33-
# Deploying Services
33+
## Deploying Services
3434

3535
Now we're ready to deploy the services that form the proxy stack and the demo services.
3636

docs/config.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ The following environment variables can be used to configure the *Docker Flow Pr
2525
|DEBUG_HTTP_FORMAT |Logging format that will be used with HTTP requests. Please consult [Custom log format](https://cbonte.github.io/haproxy-dconv/1.7/configuration.html#8.2.4) for more info about the available options.|
2626
|DEBUG_TCP_FORMAT |Logging format that will be used with TCP requests. Please consult [Custom log format](https://cbonte.github.io/haproxy-dconv/1.7/configuration.html#8.2.4) for more info about the available options.|
2727
|DEFAULT_PORTS     |The default ports used by the proxy. Multiple values can be separated with comma (`,`). If a port should be for SSL connections, append it with `:ssl`. Additional binding options can be added after a port. For example, `80 accept-proxy,443 accept-proxy:ssl` adds `accept-proxy` to the defalt binding options.<br>**Default value:** `80,443:ssl`|
28+
|DO_NOT_RESOLVE_ADDR|Whether not to resolve addresses. If set to `true`, the proxy will NOT fail if the service is not available.<br>**Default value:** `true`|
2829
|EXTRA_FRONTEND |Value will be added to the default `frontend` configuration. Multiple lines should be separated with comma (*,*).|
2930
|EXTRA_GLOBAL |Value will be added to the default `global` configuration. Multiple lines should be separated with comma (*,*).|
3031
|LISTENER_ADDRESS |The address of the [Docker Flow: Swarm Listener](https://github.com/vfarcic/docker-flow-swarm-listener) used for automatic proxy configuration.<br>**Example:** swarm-listener|

proxy/ha_proxy.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,7 @@ func (m HaProxy) getConfigData() configData {
234234
if len(d.ExtraFrontend) > 0 {
235235
d.ExtraFrontend = fmt.Sprintf(" %s", d.ExtraFrontend)
236236
}
237-
if value, err := strconv.ParseBool(os.Getenv("CHECK_RESOLVERS")); err == nil && value {
238-
d.ExtraDefaults += `
239-
default-server init-addr last,libc,none`
240-
}
237+
m.addDefaultServer(&d)
241238
m.addCompression(&d)
242239
m.addDebug(&d)
243240

@@ -317,6 +314,15 @@ func (m *HaProxy) addCompression(data *configData) {
317314
}
318315
}
319316

317+
func (m *HaProxy) addDefaultServer(data *configData) {
318+
checkResolvers, _ := strconv.ParseBool(os.Getenv("CHECK_RESOLVERS"))
319+
doNotResolveAddr, _ := strconv.ParseBool(os.Getenv("DO_NOT_RESOLVE_ADDR"))
320+
if checkResolvers || doNotResolveAddr {
321+
data.ExtraDefaults += `
322+
default-server init-addr last,libc,none`
323+
}
324+
}
325+
320326
func (m *HaProxy) addDebug(data *configData) {
321327
if strings.EqualFold(getSecretOrEnvVar("DEBUG", ""), "true") {
322328
data.ExtraGlobal += `

proxy/ha_proxy_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,32 @@ func (s HaProxyTestSuite) Test_CreateConfigFromTemplates_AddsDefaultServer_WhenC
382382
s.Equal(expectedData, actualData)
383383
}
384384

385+
func (s HaProxyTestSuite) Test_CreateConfigFromTemplates_AddsDefaultServer_WhenDoNotResolveAddrIsSetToTrue() {
386+
orig := os.Getenv("DO_NOT_RESOLVE_ADDR")
387+
defer func() { os.Setenv("DO_NOT_RESOLVE_ADDR", orig) }()
388+
os.Setenv("DO_NOT_RESOLVE_ADDR", "true")
389+
var actualData string
390+
tmpl := strings.Replace(
391+
s.TemplateContent,
392+
"balance roundrobin\n",
393+
"balance roundrobin\n\n default-server init-addr last,libc,none",
394+
-1,
395+
)
396+
expectedData := fmt.Sprintf(
397+
"%s%s",
398+
tmpl,
399+
s.ServicesContent,
400+
)
401+
writeFile = func(filename string, data []byte, perm os.FileMode) error {
402+
actualData = string(data)
403+
return nil
404+
}
405+
406+
NewHaProxy(s.TemplatesPath, s.ConfigsPath).CreateConfigFromTemplates()
407+
408+
s.Equal(expectedData, actualData)
409+
}
410+
385411
func (s HaProxyTestSuite) Test_CreateConfigFromTemplates_AddsCompressionAlgo_WhenSet() {
386412
compressionAlgoOrig := os.Getenv("COMPRESSION_ALGO")
387413
defer func() { os.Setenv("COMPRESSION_ALGO", compressionAlgoOrig) }()

0 commit comments

Comments
 (0)