Resource manager: add service lister and remove unused lock. (#559)

* Remove unused lock from the resource manager.

* Add service lister to the resource manager.

This change adds a service lister in the
resource manager.
This will be used to set the service env vars.
Also added a List method to the resource manager
and a simple test to confirm it's a pass through.
This commit is contained in:
Yash Desai
2019-04-03 11:19:30 -07:00
committed by Brian Goff
parent 85292ef4ef
commit 750de3195d
6 changed files with 63 additions and 13 deletions

View File

@@ -29,7 +29,7 @@ func TestGetPods(t *testing.T) {
podLister := corev1listers.NewPodLister(indexer)
// Create a new instance of the resource manager based on the pod lister.
rm, err := manager.NewResourceManager(podLister, nil, nil)
rm, err := manager.NewResourceManager(podLister, nil, nil, nil)
if err != nil {
t.Fatal(err)
}
@@ -58,7 +58,7 @@ func TestGetSecret(t *testing.T) {
secretLister := corev1listers.NewSecretLister(indexer)
// Create a new instance of the resource manager based on the secret lister.
rm, err := manager.NewResourceManager(nil, secretLister, nil)
rm, err := manager.NewResourceManager(nil, secretLister, nil, nil)
if err != nil {
t.Fatal(err)
}
@@ -97,7 +97,7 @@ func TestGetConfigMap(t *testing.T) {
configMapLister := corev1listers.NewConfigMapLister(indexer)
// Create a new instance of the resource manager based on the config map lister.
rm, err := manager.NewResourceManager(nil, nil, configMapLister)
rm, err := manager.NewResourceManager(nil, nil, configMapLister, nil)
if err != nil {
t.Fatal(err)
}
@@ -118,3 +118,35 @@ func TestGetConfigMap(t *testing.T) {
t.Fatalf("expected a 'not found' error, got %v", err)
}
}
// TestListServices verifies that the resource manager acts as a passthrough to a service lister.
func TestListServices(t *testing.T) {
var (
lsServices = []*v1.Service{
testutil.FakeService("namespace-0", "service-0"),
testutil.FakeService("namespace-1", "service-1"),
}
)
// Create a pod lister that will list the pods defined above.
indexer := cache.NewIndexer(cache.MetaNamespaceKeyFunc, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc})
for _, service := range lsServices {
indexer.Add(service)
}
serviceLister := corev1listers.NewServiceLister(indexer)
// Create a new instance of the resource manager based on the pod lister.
rm, err := manager.NewResourceManager(nil, nil, nil, serviceLister)
if err != nil {
t.Fatal(err)
}
// Check that the resource manager returns two pods in the call to "GetPods".
services, err := rm.ListServices()
if err != nil {
t.Fatal(err)
}
if len(lsServices) != len(services) {
t.Fatalf("expected %d services, found %d", len(lsServices), len(services))
}
}