Add publish-status-address flag (#2148)

* Add publish-status-address flag

If this flag is set, status of ingress resources will be updated
with this address.

* Address aledbf's comment
This commit is contained in:
Qiu Jian 2018-02-27 11:02:19 +08:00 committed by Manuel Alejandro de Brito Fontes
parent 3c67976969
commit 56036ddc57
6 changed files with 40 additions and 3 deletions

View file

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

View file

@ -34,6 +34,8 @@ Usage of :
--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.
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)

View file

@ -73,7 +73,8 @@ type Configuration struct {
DefaultSSLCertificate string
// optional
PublishService string
PublishService string
PublishStatusAddress string
UpdateStatus bool
UseNodeInternalIP bool

View file

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

View file

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

View file

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