Add admission controller e2e test
This commit is contained in:
parent
4e3e5ebb94
commit
7722fa38aa
15 changed files with 295 additions and 53 deletions
|
|
@ -19,6 +19,7 @@ package store
|
|||
import (
|
||||
networking "k8s.io/api/networking/v1beta1"
|
||||
"k8s.io/client-go/tools/cache"
|
||||
"k8s.io/ingress-nginx/internal/ingress"
|
||||
)
|
||||
|
||||
// IngressLister makes a Store that lists Ingress.
|
||||
|
|
@ -37,3 +38,16 @@ func (il IngressLister) ByKey(key string) (*networking.Ingress, error) {
|
|||
}
|
||||
return i.(*networking.Ingress), nil
|
||||
}
|
||||
|
||||
// FilterIngresses returns the list of Ingresses
|
||||
func FilterIngresses(ingresses []*ingress.Ingress, filterFunc IngressFilterFunc) []*ingress.Ingress {
|
||||
afterFilter := make([]*ingress.Ingress, 0)
|
||||
for _, ingress := range ingresses {
|
||||
if !filterFunc(ingress) {
|
||||
afterFilter = append(afterFilter, ingress)
|
||||
}
|
||||
}
|
||||
|
||||
sortIngressSlice(afterFilter)
|
||||
return afterFilter
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ type Storer interface {
|
|||
GetServiceEndpoints(key string) (*corev1.Endpoints, error)
|
||||
|
||||
// ListIngresses returns a list of all Ingresses in the store.
|
||||
ListIngresses(IngressFilterFunc) []*ingress.Ingress
|
||||
ListIngresses() []*ingress.Ingress
|
||||
|
||||
// GetRunningControllerPodsCount returns the number of Running ingress-nginx controller Pods.
|
||||
GetRunningControllerPodsCount() int
|
||||
|
|
@ -804,20 +804,7 @@ func (s *k8sStore) getIngress(key string) (*networkingv1beta1.Ingress, error) {
|
|||
return &ing.Ingress, nil
|
||||
}
|
||||
|
||||
// ListIngresses returns the list of Ingresses
|
||||
func (s *k8sStore) ListIngresses(filter IngressFilterFunc) []*ingress.Ingress {
|
||||
// filter ingress rules
|
||||
ingresses := make([]*ingress.Ingress, 0)
|
||||
for _, item := range s.listers.IngressWithAnnotation.List() {
|
||||
ing := item.(*ingress.Ingress)
|
||||
|
||||
if filter != nil && filter(ing) {
|
||||
continue
|
||||
}
|
||||
|
||||
ingresses = append(ingresses, ing)
|
||||
}
|
||||
|
||||
func sortIngressSlice(ingresses []*ingress.Ingress) {
|
||||
// sort Ingresses using the CreationTimestamp field
|
||||
sort.SliceStable(ingresses, func(i, j int) bool {
|
||||
ir := ingresses[i].CreationTimestamp
|
||||
|
|
@ -830,6 +817,18 @@ func (s *k8sStore) ListIngresses(filter IngressFilterFunc) []*ingress.Ingress {
|
|||
}
|
||||
return ir.Before(&jr)
|
||||
})
|
||||
}
|
||||
|
||||
// ListIngresses returns the list of Ingresses
|
||||
func (s *k8sStore) ListIngresses() []*ingress.Ingress {
|
||||
// filter ingress rules
|
||||
ingresses := make([]*ingress.Ingress, 0)
|
||||
for _, item := range s.listers.IngressWithAnnotation.List() {
|
||||
ing := item.(*ingress.Ingress)
|
||||
ingresses = append(ingresses, ing)
|
||||
}
|
||||
|
||||
sortIngressSlice(ingresses)
|
||||
|
||||
return ingresses
|
||||
}
|
||||
|
|
|
|||
|
|
@ -952,7 +952,7 @@ func TestListIngresses(t *testing.T) {
|
|||
}
|
||||
s.listers.IngressWithAnnotation.Add(ingressWithNginxClass)
|
||||
|
||||
ingresses := s.ListIngresses(nil)
|
||||
ingresses := s.ListIngresses()
|
||||
|
||||
if s := len(ingresses); s != 3 {
|
||||
t.Errorf("Expected 3 Ingresses but got %v", s)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue