diff --git a/cmd/nginx/flags.go b/cmd/nginx/flags.go index d62e579c1..c732fe30c 100644 --- a/cmd/nginx/flags.go +++ b/cmd/nginx/flags.go @@ -127,6 +127,10 @@ func parseFlags() (bool, *controller.Configuration, error) { syncRateLimit = flags.Float32("sync-rate-limit", 0.3, `Define the sync frequency upper limit`) + + publishStatusAddress = flags.String("publish-status-address", "", + `User customized address to be set in the status of ingress resources. The controller will set the + endpoint records on the ingress using this address.`) ) flag.Set("logtostderr", "true") @@ -204,6 +208,7 @@ func parseFlags() (bool, *controller.Configuration, error) { DefaultSSLCertificate: *defSSLCertificate, DefaultHealthzURL: *defHealthzURL, PublishService: *publishSvc, + PublishStatusAddress: *publishStatusAddress, ForceNamespaceIsolation: *forceIsolation, UpdateStatusOnShutdown: *updateStatusOnShutdown, SortBackends: *sortBackends, diff --git a/docs/user-guide/cli-arguments.md b/docs/user-guide/cli-arguments.md index b4ec882a6..1aa63df07 100644 --- a/docs/user-guide/cli-arguments.md +++ b/docs/user-guide/cli-arguments.md @@ -32,8 +32,10 @@ Usage of : --log_dir string If non-empty, write log files in this directory --logtostderr log to standard error instead of files (default true) --profiling Enable profiling via web interface host:port/debug/pprof/ (default true) - --publish-service string Service fronting the ingress controllers. Takes the form namespace/name. + --publish-service string Service fronting the ingress controllers. Takes the form namespace/name. The controller will set the endpoint records on the ingress objects to reflect those on the service. + --publish-status-address string User customized address to be set in the status of ingress resources. + The controller will set the endpoint records on the ingress using this address. --report-node-internal-ip-address Defines if the nodes IP address to be returned in the ingress status should be the internal instead of the external IP address --sort-backends Defines if backends and it's endpoints should be sorted --ssl-passtrough-proxy-port int Default port to use internally for SSL when SSL Passthgough is enabled (default 442) diff --git a/internal/ingress/controller/controller.go b/internal/ingress/controller/controller.go index 9f3c7c004..879cf3a26 100644 --- a/internal/ingress/controller/controller.go +++ b/internal/ingress/controller/controller.go @@ -73,7 +73,8 @@ type Configuration struct { DefaultSSLCertificate string // optional - PublishService string + PublishService string + PublishStatusAddress string UpdateStatus bool UseNodeInternalIP bool diff --git a/internal/ingress/controller/nginx.go b/internal/ingress/controller/nginx.go index 00534a568..686748750 100644 --- a/internal/ingress/controller/nginx.go +++ b/internal/ingress/controller/nginx.go @@ -144,6 +144,7 @@ func NewNGINXController(config *Configuration, fs file.Filesystem) *NGINXControl n.syncStatus = status.NewStatusSyncer(status.Config{ Client: config.Client, PublishService: config.PublishService, + PublishStatusAddress: config.PublishStatusAddress, IngressLister: n.store, ElectionID: config.ElectionID, IngressClass: class.IngressClass, diff --git a/internal/ingress/status/status.go b/internal/ingress/status/status.go index 91f6edcd6..69bea83ce 100644 --- a/internal/ingress/status/status.go +++ b/internal/ingress/status/status.go @@ -65,6 +65,8 @@ type Config struct { PublishService string + PublishStatusAddress string + ElectionID string UpdateStatusOnShutdown bool @@ -81,7 +83,9 @@ type Config struct { // in all the defined rules. To simplify the process leader election is used so the update // is executed only in one node (Ingress controllers can be scaled to more than one) // If the controller is running with the flag --publish-service (with a valid service) -// the IP address behind the service is used, if not the source is the IP/s of the node/s +// the IP address behind the service is used, if it is running with the flag +// --publish-status-address, the address specified in the flag is used, if neither of the +// two flags are set, the source is the IP/s of the node/s type statusSync struct { Config // pod contains runtime information about this pod @@ -251,6 +255,11 @@ func (s *statusSync) runningAddresses() ([]string, error) { return addrs, nil } + if s.PublishStatusAddress != "" { + addrs = append(addrs, s.PublishStatusAddress) + return addrs, nil + } + // get information about all the pods running the ingress controller pods, err := s.Client.CoreV1().Pods(s.pod.Namespace).List(metav1.ListOptions{ LabelSelector: labels.SelectorFromSet(s.pod.Labels).String(), diff --git a/internal/ingress/status/status_test.go b/internal/ingress/status/status_test.go index 70bac53b1..c4f223ec5 100644 --- a/internal/ingress/status/status_test.go +++ b/internal/ingress/status/status_test.go @@ -389,6 +389,25 @@ func TestRunningAddresessWithPods(t *testing.T) { } } +func TestRunningAddresessWithPublishStatusAddress(t *testing.T) { + fk := buildStatusSync() + fk.PublishService = "" + fk.PublishStatusAddress = "127.0.0.1" + + r, _ := fk.runningAddresses() + if r == nil { + t.Fatalf("returned nil but expected valid []string") + } + rl := len(r) + if len(r) != 1 { + t.Errorf("returned %v but expected %v", rl, 1) + } + rv := r[0] + if rv != "127.0.0.1" { + t.Errorf("returned %v but expected %v", rv, "127.0.0.1") + } +} + /* TODO: this test requires a refactoring func TestUpdateStatus(t *testing.T) {