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:
parent
3c67976969
commit
56036ddc57
6 changed files with 40 additions and 3 deletions
|
|
@ -73,7 +73,8 @@ type Configuration struct {
|
|||
DefaultSSLCertificate string
|
||||
|
||||
// optional
|
||||
PublishService string
|
||||
PublishService string
|
||||
PublishStatusAddress string
|
||||
|
||||
UpdateStatus bool
|
||||
UseNodeInternalIP bool
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue