Skip to content

Commit

Permalink
Allow multiple publish status addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
AnaClaudia committed Feb 26, 2021
1 parent a7fb791 commit ef714ae
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 4 deletions.
2 changes: 1 addition & 1 deletion TAG
@@ -1 +1 @@
v0.44.0
v0.45.0-dev.0
2 changes: 1 addition & 1 deletion cmd/nginx/flags.go
Expand Up @@ -138,7 +138,7 @@ extension for this to succeed.`)
`Define the sync frequency upper limit`)

publishStatusAddress = flags.String("publish-status-address", "",
`Customized address to set as the load-balancer status of Ingress objects this controller satisfies.
`Customized address (or addresses, separated by comma) to set as the load-balancer status of Ingress objects this controller satisfies.
Requires the update-status parameter.`)

enableMetrics = flags.Bool("enable-metrics", true,
Expand Down
2 changes: 1 addition & 1 deletion docs/user-guide/cli-arguments.md
Expand Up @@ -38,7 +38,7 @@ They are set in the container spec of the `nginx-ingress-controller` Deployment
| `--profiler-port` | Port to use for expose the ingress controller Go profiler when it is enabled. (default 10245) |
| `--profiling` | Enable profiling via web interface host:port/debug/pprof/ (default true) |
| `--publish-service` | Service fronting the Ingress controller. Takes the form "namespace/name". When used together with update-status, the controller mirrors the address of this service's endpoints to the load-balancer status of all Ingress objects it satisfies. |
| `--publish-status-address` | Customized address to set as the load-balancer status of Ingress objects this controller satisfies. Requires the update-status parameter. |
| `--publish-status-address` | Customized address (or addresses, separated by comma) to set as the load-balancer status of Ingress objects this controller satisfies. Requires the update-status parameter. |
| `--report-node-internal-ip-address`| Set the load-balancer status of Ingress objects to internal Node addresses instead of external. Requires the update-status parameter. |
| `--skip_headers` | If true, avoid header prefixes in the log messages |
| `--skip_log_headers` | If true, avoid headers when opening log files |
Expand Down
5 changes: 4 additions & 1 deletion internal/ingress/status/status.go
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"fmt"
"net"
"regexp"
"sort"
"strings"
"time"
Expand Down Expand Up @@ -165,7 +166,9 @@ func NewStatusSyncer(config Config) Syncer {
// ingress controller is currently running
func (s *statusSync) runningAddresses() ([]string, error) {
if s.PublishStatusAddress != "" {
return []string{s.PublishStatusAddress}, nil
re := regexp.MustCompile(`,\s*`)
multipleAddrs := re.Split(s.PublishStatusAddress, -1)
return multipleAddrs, nil
}

if s.PublishService != "" {
Expand Down
45 changes: 45 additions & 0 deletions internal/ingress/status/status_test.go
Expand Up @@ -594,6 +594,51 @@ func TestRunningAddressesWithPublishStatusAddress(t *testing.T) {
t.Errorf("returned %v but expected %v", rv, "127.0.0.1")
}
}

func TestRunningAddressesWithPublishStatusAddresses(t *testing.T) {
fk := buildStatusSync()
fk.PublishStatusAddress = "127.0.0.1,1.1.1.1"

ra, _ := fk.runningAddresses()
if ra == nil {
t.Fatalf("returned nil but expected valid []string")
}
rl := len(ra)
if len(ra) != 2 {
t.Errorf("returned %v but expected %v", rl, 2)
}
rv := ra[0]
rv2 := ra[1]
if rv != "127.0.0.1" {
t.Errorf("returned %v but expected %v", rv, "127.0.0.1")
}
if rv2 != "1.1.1.1" {
t.Errorf("returned %v but expected %v", rv2, "1.1.1.1")
}
}

func TestRunningAddressesWithPublishStatusAddressesAndSpaces(t *testing.T) {
fk := buildStatusSync()
fk.PublishStatusAddress = "127.0.0.1, 1.1.1.1"

ra, _ := fk.runningAddresses()
if ra == nil {
t.Fatalf("returned nil but expected valid []string")
}
rl := len(ra)
if len(ra) != 2 {
t.Errorf("returned %v but expected %v", rl, 2)
}
rv := ra[0]
rv2 := ra[1]
if rv != "127.0.0.1" {
t.Errorf("returned %v but expected %v", rv, "127.0.0.1")
}
if rv2 != "1.1.1.1" {
t.Errorf("returned %v but expected %v", rv2, "1.1.1.1")
}
}

func TestSliceToStatus(t *testing.T) {
fkEndpoints := []string{
"10.0.0.1",
Expand Down

0 comments on commit ef714ae

Please sign in to comment.