Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
Shawn Hurley committed Jan 22, 2019
1 parent bbb3b9c commit 2f6a0b3
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 76 deletions.
8 changes: 8 additions & 0 deletions pkg/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (

const testNamespaceOne = "test-namespace-1"
const testNamespaceTwo = "test-namespace-2"
const testNamespaceThree = "test-namespace-3"

// TODO(community): Pull these helper functions into testenv.
// Restart policy is included to allow indexing on that field.
Expand Down Expand Up @@ -74,6 +75,9 @@ func deletePod(pod runtime.Object) {
var _ = Describe("Informer Cache", func() {
CacheTest(cache.New)
})
var _ = Describe("Multi-Namesapce Informer Cache", func() {
CacheTest(cache.MultiNamespacedCacheBuilder([]string{testNamespaceOne, testNamespaceTwo, "default"}))
})

// nolint: gocyclo
func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (cache.Cache, error)) {
Expand All @@ -84,6 +88,7 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
knownPod1 runtime.Object
knownPod2 runtime.Object
knownPod3 runtime.Object
knownPod4 runtime.Object
)

BeforeEach(func() {
Expand All @@ -95,13 +100,15 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
knownPod1 = createPod("test-pod-1", testNamespaceOne, kcorev1.RestartPolicyNever)
knownPod2 = createPod("test-pod-2", testNamespaceTwo, kcorev1.RestartPolicyAlways)
knownPod3 = createPod("test-pod-3", testNamespaceTwo, kcorev1.RestartPolicyOnFailure)
knownPod4 = createPod("test-pod-4", testNamespaceThree, kcorev1.RestartPolicyNever)
podGVK := schema.GroupVersionKind{
Kind: "Pod",
Version: "v1",
}
knownPod1.GetObjectKind().SetGroupVersionKind(podGVK)
knownPod2.GetObjectKind().SetGroupVersionKind(podGVK)
knownPod3.GetObjectKind().SetGroupVersionKind(podGVK)
knownPod4.GetObjectKind().SetGroupVersionKind(podGVK)

By("creating the informer cache")
var err error
Expand All @@ -120,6 +127,7 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
deletePod(knownPod1)
deletePod(knownPod2)
deletePod(knownPod3)
deletePod(knownPod4)

close(stop)
})
Expand Down
30 changes: 0 additions & 30 deletions pkg/cache/example_test.go

This file was deleted.

23 changes: 13 additions & 10 deletions pkg/cache/multi_namespace_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,11 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
)

// multiNamespaceCache knows how to handle multiple namespaced caches
// You may want to use this feature when scoping permissions for your
// operator to a list of namespaces instead of watching every namespace
// in the cluster.
type multiNamespaceCache struct {
namespaceToCache map[string]Cache
Scheme *runtime.Scheme
}
// NewCacheFunc - Function for creating a new cache from the options and a rest config
type NewCacheFunc func(config *rest.Config, opts Options) (Cache, error)

// NewMultiNamespacedCacheBuilder - Builder function to create a new multi-namespaced cache.
func NewMultiNamespacedCacheBuilder(namespaces []string) func(config *rest.Config, opts Options) (Cache, error) {
// MultiNamespacedCacheBuilder - Builder function to create a new multi-namespaced cache.
func MultiNamespacedCacheBuilder(namespaces []string) NewCacheFunc {
return func(config *rest.Config, opts Options) (Cache, error) {
opts, err := defaultOpts(config, opts)
if err != nil {
Expand All @@ -61,6 +55,15 @@ func NewMultiNamespacedCacheBuilder(namespaces []string) func(config *rest.Confi
}
}

// multiNamespaceCache knows how to handle multiple namespaced caches
// You may want to use this feature when scoping permissions for your
// operator to a list of namespaces instead of watching every namespace
// in the cluster.
type multiNamespaceCache struct {
namespaceToCache map[string]Cache
Scheme *runtime.Scheme
}

var _ Cache = &multiNamespaceCache{}

// Methods for multiNamespaceCache to conform to the Informers interface
Expand Down
32 changes: 0 additions & 32 deletions pkg/cache/multi_namespace_cache_test.go

This file was deleted.

5 changes: 1 addition & 4 deletions pkg/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ type Options struct {

// NewCache is the function that will create the cache to be used
// by the manager. If not set this will use the default new cache function.
NewCache NewCacheFunc
NewCache cache.NewCacheFunc

// NewClient will create the client to be used by the manager.
// If not set this will create the default DelegatingClient that will
Expand All @@ -136,9 +136,6 @@ type Options struct {
newMetricsListener func(addr string) (net.Listener, error)
}

// NewCacheFunc allows a user to define how to create a cache
type NewCacheFunc func(config *rest.Config, opts cache.Options) (cache.Cache, error)

// NewClientFunc allows a user to define how to create a client
type NewClientFunc func(cache cache.Cache, config *rest.Config, options client.Options) (client.Client, error)

Expand Down

0 comments on commit 2f6a0b3

Please sign in to comment.