diff --git a/pkg/util/cachepersister.go b/pkg/util/cachepersister.go index e72c28f16..ba8918587 100644 --- a/pkg/util/cachepersister.go +++ b/pkg/util/cachepersister.go @@ -23,13 +23,19 @@ import ( ) const ( - //PluginFolder defines location of plugins + // PluginFolder defines location of plugins PluginFolder = "/var/lib/kubelet/plugins" ) -// ForAllFunc stores metadata with identifier +// ForAllFunc is a unary predicate for visiting all cache entries +// matching the `pattern' in CachePersister's ForAll function. type ForAllFunc func(identifier string) error +// CacheEntryNotFound is an error type for "Not Found" cache errors +type CacheEntryNotFound struct { + error +} + // CachePersister interface implemented for store type CachePersister interface { Create(identifier string, data interface{}) error diff --git a/pkg/util/k8scmcache.go b/pkg/util/k8scmcache.go index 9ba1f9de5..10a6d7ef5 100644 --- a/pkg/util/k8scmcache.go +++ b/pkg/util/k8scmcache.go @@ -159,6 +159,10 @@ func (k8scm *K8sCMCache) Create(identifier string, data interface{}) error { func (k8scm *K8sCMCache) Get(identifier string, data interface{}) error { cm, err := k8scm.getMetadataCM(identifier) if err != nil { + if apierrs.IsNotFound(err) { + return &CacheEntryNotFound{err} + } + return err } err = json.Unmarshal([]byte(cm.Data[cmDataKey]), data) diff --git a/pkg/util/nodecache.go b/pkg/util/nodecache.go index 510ffa246..5659d4eaa 100644 --- a/pkg/util/nodecache.go +++ b/pkg/util/nodecache.go @@ -130,6 +130,10 @@ func (nc *NodeCache) Get(identifier string, data interface{}) error { // #nosec fp, err := os.Open(file) if err != nil { + if os.IsNotExist(errors.Cause(err)) { + return &CacheEntryNotFound{err} + } + return errors.Wrapf(err, "node-cache: open error for %s", file) }