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, syncRateLimit = flags.Float32("sync-rate-limit", 0.3,
`Define the sync frequency upper limit`) `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") flag.Set("logtostderr", "true")
@ -204,6 +208,7 @@ func parseFlags() (bool, *controller.Configuration, error) {
DefaultSSLCertificate: *defSSLCertificate, DefaultSSLCertificate: *defSSLCertificate,
DefaultHealthzURL: *defHealthzURL, DefaultHealthzURL: *defHealthzURL,
PublishService: *publishSvc, PublishService: *publishSvc,
PublishStatusAddress: *publishStatusAddress,
ForceNamespaceIsolation: *forceIsolation, ForceNamespaceIsolation: *forceIsolation,
UpdateStatusOnShutdown: *updateStatusOnShutdown, UpdateStatusOnShutdown: *updateStatusOnShutdown,
SortBackends: *sortBackends, SortBackends: *sortBackends,

View file

@ -32,8 +32,10 @@ Usage of :
--log_dir string If non-empty, write log files in this directory --log_dir string If non-empty, write log files in this directory
--logtostderr log to standard error instead of files (default true) --logtostderr log to standard error instead of files (default true)
--profiling Enable profiling via web interface host:port/debug/pprof/ (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. 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 --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 --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) --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 DefaultSSLCertificate string
// optional // optional
PublishService string PublishService string
PublishStatusAddress string
UpdateStatus bool UpdateStatus bool
UseNodeInternalIP bool UseNodeInternalIP bool

View file

@ -144,6 +144,7 @@ func NewNGINXController(config *Configuration, fs file.Filesystem) *NGINXControl
n.syncStatus = status.NewStatusSyncer(status.Config{ n.syncStatus = status.NewStatusSyncer(status.Config{
Client: config.Client, Client: config.Client,
PublishService: config.PublishService, PublishService: config.PublishService,
PublishStatusAddress: config.PublishStatusAddress,
IngressLister: n.store, IngressLister: n.store,
ElectionID: config.ElectionID, ElectionID: config.ElectionID,
IngressClass: class.IngressClass, IngressClass: class.IngressClass,

View file

@ -65,6 +65,8 @@ type Config struct {
PublishService string PublishService string
PublishStatusAddress string
ElectionID string ElectionID string
UpdateStatusOnShutdown bool 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 // 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) // 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) // 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 { type statusSync struct {
Config Config
// pod contains runtime information about this pod // pod contains runtime information about this pod
@ -251,6 +255,11 @@ func (s *statusSync) runningAddresses() ([]string, error) {
return addrs, nil return addrs, nil
} }
if s.PublishStatusAddress != "" {
addrs = append(addrs, s.PublishStatusAddress)
return addrs, nil
}
// get information about all the pods running the ingress controller // get information about all the pods running the ingress controller
pods, err := s.Client.CoreV1().Pods(s.pod.Namespace).List(metav1.ListOptions{ pods, err := s.Client.CoreV1().Pods(s.pod.Namespace).List(metav1.ListOptions{
LabelSelector: labels.SelectorFromSet(s.pod.Labels).String(), 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 TODO: this test requires a refactoring
func TestUpdateStatus(t *testing.T) { func TestUpdateStatus(t *testing.T) {