Update lua configuration_data when number of controller pod change

This commit is contained in:
Maxime Ginters 2018-11-27 09:53:51 -05:00
parent 55b4f00368
commit f90881b367
10 changed files with 113 additions and 19 deletions

View file

@ -76,8 +76,8 @@ type Storer interface {
// ListIngresses returns a list of all Ingresses in the store.
ListIngresses() []*ingress.Ingress
// ListControllerPods returns a list of ingress-nginx controller Pods.
ListControllerPods() []*corev1.Pod
// GetRunningControllerPodsCount returns the number of Running ingress-nginx controller Pods.
GetRunningControllerPodsCount() int
// GetLocalSSLCert returns the local copy of a SSLCert
GetLocalSSLCert(name string) (*ingress.SSLCert, error)
@ -288,12 +288,10 @@ func New(checkOCSP bool,
store.informers.Pod = cache.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options metav1.ListOptions) (k8sruntime.Object, error) {
options.LabelSelector = labelSelector.String()
return client.CoreV1().Pods(store.pod.Namespace).List(options)
},
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
options.LabelSelector = labelSelector.String()
return client.CoreV1().Pods(store.pod.Namespace).Watch(options)
},
@ -832,9 +830,9 @@ func (s *k8sStore) Run(stopCh chan struct{}) {
}
}
// ListControllerPods returns a list of ingress-nginx controller Pods
func (s *k8sStore) ListControllerPods() []*corev1.Pod {
var pods []*corev1.Pod
// GetRunningControllerPodsCount returns the number of Running ingress-nginx controller Pods
func (s k8sStore) GetRunningControllerPodsCount() int {
count := 0
for _, i := range s.listers.Pod.List() {
pod := i.(*corev1.Pod)
@ -843,8 +841,8 @@ func (s *k8sStore) ListControllerPods() []*corev1.Pod {
continue
}
pods = append(pods, pod)
count++
}
return pods
return count
}

View file

@ -1062,7 +1062,7 @@ func TestWriteSSLSessionTicketKey(t *testing.T) {
}
}
func TestListControllerPods(t *testing.T) {
func TestGetRunningControllerPodsCount(t *testing.T) {
os.Setenv("POD_NAMESPACE", "testns")
os.Setenv("POD_NAME", "ingress-1")
@ -1117,8 +1117,8 @@ func TestListControllerPods(t *testing.T) {
}
s.listers.Pod.Add(pod)
pods := s.ListControllerPods()
if s := len(pods); s != 2 {
podsCount := s.GetRunningControllerPodsCount()
if podsCount != 2 {
t.Errorf("Expected 1 controller Pods but got %v", s)
}
}