mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-12-18 02:50:30 +00:00
util/cachepersister: check and return CacheEntryNotFound error in Get()
This commit is contained in:
parent
e627a6166c
commit
e5dbea15d3
@ -23,13 +23,19 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
//PluginFolder defines location of plugins
|
// PluginFolder defines location of plugins
|
||||||
PluginFolder = "/var/lib/kubelet/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
|
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
|
// CachePersister interface implemented for store
|
||||||
type CachePersister interface {
|
type CachePersister interface {
|
||||||
Create(identifier string, data interface{}) error
|
Create(identifier string, data interface{}) error
|
||||||
|
@ -159,6 +159,10 @@ func (k8scm *K8sCMCache) Create(identifier string, data interface{}) error {
|
|||||||
func (k8scm *K8sCMCache) Get(identifier string, data interface{}) error {
|
func (k8scm *K8sCMCache) Get(identifier string, data interface{}) error {
|
||||||
cm, err := k8scm.getMetadataCM(identifier)
|
cm, err := k8scm.getMetadataCM(identifier)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if apierrs.IsNotFound(err) {
|
||||||
|
return &CacheEntryNotFound{err}
|
||||||
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = json.Unmarshal([]byte(cm.Data[cmDataKey]), data)
|
err = json.Unmarshal([]byte(cm.Data[cmDataKey]), data)
|
||||||
|
@ -130,6 +130,10 @@ func (nc *NodeCache) Get(identifier string, data interface{}) error {
|
|||||||
// #nosec
|
// #nosec
|
||||||
fp, err := os.Open(file)
|
fp, err := os.Open(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if os.IsNotExist(errors.Cause(err)) {
|
||||||
|
return &CacheEntryNotFound{err}
|
||||||
|
}
|
||||||
|
|
||||||
return errors.Wrapf(err, "node-cache: open error for %s", file)
|
return errors.Wrapf(err, "node-cache: open error for %s", file)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user