stork resourcecollector to handle the cases where cache is not present.
@@ -3,12 +3,14 @@ package resourcecollector
import (
"context"
"fmt"
- storkcache "github.com/libopenstorage/stork/pkg/cache"
- rbacv1 "k8s.io/api/rbac/v1"
+ "reflect"
"strconv"
"strings"
"time"
+ storkcache "github.com/libopenstorage/stork/pkg/cache"
+ rbacv1 "k8s.io/api/rbac/v1"
+
"github.com/go-openapi/inflect"
"github.com/heptio/ark/pkg/discovery"
"github.com/libopenstorage/stork/drivers/volume"
@@ -217,7 +219,13 @@ func (r *ResourceCollector) GetResourceTypes(
return nil, err
}
var crdResources []metav1.GroupVersionKind
- crdList, err := storkcache.Instance().ListApplicationRegistrations()
+ var crdList *stork_api.ApplicationRegistrationList
+ storkcache.Instance()
+ if !reflect.ValueOf(storage.Instance()).IsNil() {
+ crdList, err = storkcache.Instance().ListApplicationRegistrations()
+ } else {
+ crdList, err = r.storkOps.ListApplicationRegistrations()
+ }
if err != nil {
logrus.Warnf("Unable to get registered crds, err %v", err)
} else {
@@ -330,7 +338,12 @@ func (r *ResourceCollector) GetResourcesForType(
if err != nil {
return nil, err
}
- crdList, err := storkcache.Instance().ListApplicationRegistrations()
+ var crdList *stork_api.ApplicationRegistrationList
+ if !reflect.ValueOf(storage.Instance()).IsNil() {
+ crdList, err = storkcache.Instance().ListApplicationRegistrations()
+ } else {
+ crdList, err = r.storkOps.ListApplicationRegistrations()
+ }
if err != nil {
logrus.Warnf("Unable to get registered crds, err %v", err)
}
@@ -359,7 +372,12 @@ func (r *ResourceCollector) GetResources(
// Map to prevent collection of duplicate objects
resourceMap := make(map[types.UID]bool)
var crdResources []metav1.GroupVersionKind
- crdList, err := storkcache.Instance().ListApplicationRegistrations()
+ var crdList *stork_api.ApplicationRegistrationList
+ if !reflect.ValueOf(storage.Instance()).IsNil() {
+ crdList, err = storkcache.Instance().ListApplicationRegistrations()
+ } else {
+ crdList, err = r.storkOps.ListApplicationRegistrations()
+ }
if err != nil {
logrus.Warnf("Unable to get registered crds, err %v", err)
} else {
