Allow multiple publish status addresses

This commit is contained in:
AnaClaudia 2021-02-26 16:57:54 -05:00
parent a7fb791132
commit ef714ae52f
5 changed files with 52 additions and 4 deletions

2
TAG
View file

@ -1 +1 @@
v0.44.0
v0.45.0-dev.0

View file

@ -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,

View file

@ -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 |

View file

@ -20,6 +20,7 @@ import (
"context"
"fmt"
"net"
"regexp"
"sort"
"strings"
"time"
@ -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 != "" {

View file

@ -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",