Skip to content

Commit b568049

Browse files
committed
router: BindOnlyWhenReady -> BindPortsAfterSync
1 parent 8aa698e commit b568049

File tree

5 files changed

+20
-20
lines changed

5 files changed

+20
-20
lines changed

images/router/haproxy/conf/haproxy-config.template

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ listen stats :1936
9898
stats auth {{.StatsUser}}:{{.StatsPassword}}
9999
{{ end }}
100100

101-
{{ if (and .BindOnlyWhenReady (not .SyncedAtLeastOnce)) }}
101+
{{ if (and .BindPortsAfterSync (not .SyncedAtLeastOnce)) }}
102102
# Avoiding binding ports until routing configuration has been synchronized.
103103
{{ else }}
104104
frontend public
@@ -530,7 +530,7 @@ backend be_secure_{{$cfgIdx}}
530530
{{ end }}{{/* end range over serviceUnitNames */}}
531531
{{ end }}{{/* end tls==reencrypt */}}
532532
{{ end }}{{/* end loop over routes */}}
533-
{{ end }}{{/* end bind only when ready */}}
533+
{{ end }}{{/* end bind ports after sync */}}
534534
{{ end }}{{/* end haproxy config template */}}
535535

536536
{{/*--------------------------------- END OF HAPROXY CONFIG, BELOW ARE MAPPING FILES ------------------------*/}}

pkg/cmd/infra/router/template.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ type TemplateRouter struct {
6262
DefaultCertificateDir string
6363
ExtendedValidation bool
6464
RouterService *ktypes.NamespacedName
65-
BindOnlyWhenReady bool
65+
BindPortsAfterSync bool
6666
}
6767

6868
// reloadInterval returns how often to run the router reloads. The interval
@@ -87,7 +87,7 @@ func (o *TemplateRouter) Bind(flag *pflag.FlagSet) {
8787
flag.StringVar(&o.ReloadScript, "reload", util.Env("RELOAD_SCRIPT", ""), "The path to the reload script to use")
8888
flag.DurationVar(&o.ReloadInterval, "interval", reloadInterval(), "Controls how often router reloads are invoked. Mutiple router reload requests are coalesced for the duration of this interval since the last reload time.")
8989
flag.BoolVar(&o.ExtendedValidation, "extended-validation", util.Env("EXTENDED_VALIDATION", "true") == "true", "If set, then an additional extended validation step is performed on all routes admitted in by this router. Defaults to true and enables the extended validation checks.")
90-
flag.BoolVar(&o.BindOnlyWhenReady, "bind-only-when-ready", util.Env("BIND_ONLY_WHEN_READY", "") == "true", "Only bind ports when route state has been synchronized")
90+
flag.BoolVar(&o.BindPortsAfterSync, "bind-ports-after-sync", util.Env("ROUTER_BIND_PORTS_AFTER_SYNC", "") == "true", "Bind ports only after route state has been synchronized")
9191
}
9292

9393
type RouterStats struct {
@@ -190,7 +190,7 @@ func (o *TemplateRouterOptions) Run() error {
190190
StatsUsername: o.StatsUsername,
191191
StatsPassword: o.StatsPassword,
192192
PeerService: o.RouterService,
193-
BindOnlyWhenReady: o.BindOnlyWhenReady,
193+
BindPortsAfterSync: o.BindPortsAfterSync,
194194
IncludeUDP: o.RouterSelection.IncludeUDP,
195195
AllowWildcardRoutes: o.RouterSelection.AllowWildcardRoutes,
196196
}

pkg/router/template/plugin.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ type TemplatePluginConfig struct {
5050
IncludeUDP bool
5151
AllowWildcardRoutes bool
5252
PeerService *ktypes.NamespacedName
53-
BindOnlyWhenReady bool
53+
BindPortsAfterSync bool
5454
}
5555

5656
// routerInterface controls the interaction of the plugin with the underlying router implementation
@@ -147,7 +147,7 @@ func NewTemplatePlugin(cfg TemplatePluginConfig, lookupSvc ServiceLookup) (*Temp
147147
statsPort: cfg.StatsPort,
148148
allowWildcardRoutes: cfg.AllowWildcardRoutes,
149149
peerEndpointsKey: peerKey,
150-
bindOnlyWhenReady: cfg.BindOnlyWhenReady,
150+
bindPortsAfterSync: cfg.BindPortsAfterSync,
151151
}
152152
router, err := newTemplateRouter(templateRouterCfg)
153153
return newDefaultTemplatePlugin(router, cfg.IncludeUDP, lookupSvc), err

pkg/router/template/router.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ type templateRouter struct {
8787
// the router should only reload when the value is false
8888
skipCommit bool
8989
// If true, haproxy should only bind ports when it has route and endpoint state
90-
bindOnlyWhenReady bool
90+
bindPortsAfterSync bool
9191
// whether the router state has been read from the api at least once
9292
syncedAtLeastOnce bool
9393
}
@@ -107,7 +107,7 @@ type templateRouterCfg struct {
107107
allowWildcardRoutes bool
108108
peerEndpointsKey string
109109
includeUDP bool
110-
bindOnlyWhenReady bool
110+
bindPortsAfterSync bool
111111
}
112112

113113
// templateConfig is a subset of the templateRouter information that should be passed to the template for generating
@@ -130,7 +130,7 @@ type templateData struct {
130130
//port to expose stats with (if the template supports it)
131131
StatsPort int
132132
// whether the router should bind the default ports only when ready
133-
BindOnlyWhenReady bool
133+
BindPortsAfterSync bool
134134
// whether the router state has been read from the api at least once
135135
SyncedAtLeastOnce bool
136136
}
@@ -171,7 +171,7 @@ func newTemplateRouter(cfg templateRouterCfg) (*templateRouter, error) {
171171
allowWildcardRoutes: cfg.allowWildcardRoutes,
172172
peerEndpointsKey: cfg.peerEndpointsKey,
173173
peerEndpoints: []Endpoint{},
174-
bindOnlyWhenReady: cfg.bindOnlyWhenReady,
174+
bindPortsAfterSync: cfg.bindPortsAfterSync,
175175

176176
rateLimitedCommitFunction: nil,
177177
rateLimitedCommitStopChannel: make(chan struct{}),
@@ -404,7 +404,7 @@ func (r *templateRouter) writeConfig() error {
404404
StatsUser: r.statsUser,
405405
StatsPassword: r.statsPassword,
406406
StatsPort: r.statsPort,
407-
BindOnlyWhenReady: r.bindOnlyWhenReady,
407+
BindPortsAfterSync: r.bindPortsAfterSync,
408408
SyncedAtLeastOnce: r.syncedAtLeastOnce,
409409
}
410410
if err := template.Execute(file, data); err != nil {

test/integration/router_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -1256,10 +1256,10 @@ u3YLAbyW/lHhOCiZu2iAI8AbmXem9lW6Tr7p/97s0w==
12561256
// createAndStartRouterContainer is responsible for deploying the router image in docker. It assumes that all router images
12571257
// will use a command line flag that can take --master which points to the master url
12581258
func createAndStartRouterContainer(dockerCli *dockerClient.Client, masterIp string, routerStatsPort int, reloadInterval int) (containerId string, err error) {
1259-
return createAndStartRouterContainerBindWhenReady(dockerCli, masterIp, routerStatsPort, reloadInterval, false)
1259+
return createAndStartRouterContainerBindAfterSync(dockerCli, masterIp, routerStatsPort, reloadInterval, false)
12601260
}
12611261

1262-
func createAndStartRouterContainerBindWhenReady(dockerCli *dockerClient.Client, masterIp string, routerStatsPort int, reloadInterval int, bindOnlyWhenReady bool) (containerId string, err error) {
1262+
func createAndStartRouterContainerBindAfterSync(dockerCli *dockerClient.Client, masterIp string, routerStatsPort int, reloadInterval int, bindPortsAfterSync bool) (containerId string, err error) {
12631263
ports := []string{"80", "443"}
12641264
if routerStatsPort > 0 {
12651265
ports = append(ports, fmt.Sprintf("%d", routerStatsPort))
@@ -1295,7 +1295,7 @@ func createAndStartRouterContainerBindWhenReady(dockerCli *dockerClient.Client,
12951295
fmt.Sprintf("STATS_USERNAME=%s", statsUser),
12961296
fmt.Sprintf("STATS_PASSWORD=%s", statsPassword),
12971297
fmt.Sprintf("DEFAULT_CERTIFICATE=%s", defaultCert),
1298-
fmt.Sprintf("BIND_ONLY_WHEN_READY=%s", strconv.FormatBool(bindOnlyWhenReady)),
1298+
fmt.Sprintf("ROUTER_BIND_PORTS_AFTER_SYNC=%s", strconv.FormatBool(bindPortsAfterSync)),
12991299
}
13001300

13011301
reloadIntVar := fmt.Sprintf("RELOAD_INTERVAL=%ds", reloadInterval)
@@ -1624,9 +1624,9 @@ func makeRouterRequest(t *testing.T, scheme string) (*http.Response, error) {
16241624
return httpClient.Do(req)
16251625
}
16261626

1627-
// Ensure that when configured with BIND_ONLY_WHEN_READY=true, haproxy
1628-
// binds ports only when it has routes and endpoints to expose.
1629-
func TestRouterBindsPortsOnlyWhenReady(t *testing.T) {
1627+
// Ensure that when configured with ROUTER_BIND_PORTS_AFTER_SYNC=true,
1628+
// haproxy binds ports only when an initial sync has been performed.
1629+
func TestRouterBindsPortsAfterSync(t *testing.T) {
16301630
// Create a new master but do not start it yet to simulate a router without api access.
16311631
fakeMasterAndPod := tr.NewTestHttpService()
16321632

@@ -1635,8 +1635,8 @@ func TestRouterBindsPortsOnlyWhenReady(t *testing.T) {
16351635
t.Fatalf("Unable to get docker client: %v", err)
16361636
}
16371637

1638-
bindOnlyWhenReady := true
1639-
routerId, err := createAndStartRouterContainerBindWhenReady(dockerCli, fakeMasterAndPod.MasterHttpAddr, statsPort, 1, bindOnlyWhenReady)
1638+
bindPortsAfterSync := true
1639+
routerId, err := createAndStartRouterContainerBindAfterSync(dockerCli, fakeMasterAndPod.MasterHttpAddr, statsPort, 1, bindPortsAfterSync)
16401640
if err != nil {
16411641
t.Fatalf("Error starting container %s : %v", getRouterImage(), err)
16421642
}

0 commit comments

Comments
 (0)