Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add unlink/rmdir. Fixes #7 #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions kubefuse/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@ def get(self, key):
return None

def delete(self, key):
del(self._timestamps[key])
del(self._cache[key])
try:
del(self._timestamps[key])
del(self._cache[key])
except KeyError:
pass
19 changes: 18 additions & 1 deletion kubefuse/client.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import logging
import subprocess
import yaml
import tempfile

from cache import ExpiringCache

LOGGER = logging.getLogger(__name__)

class KubernetesClient(object):
def __init__(self):
self._cache = ExpiringCache(30)
Expand All @@ -24,17 +27,31 @@ def _load_from_cache_or_do(self, key, func):
result = func()
self._cache.set(key, result)
return result

def get_namespaces(self):
key = "namespaces"
cb = self._get_namespaces
return self._load_from_cache_or_do(key, cb)

def delete_namespace(self, namespace):
LOGGER.info(self._run_command(('delete namespace ' + namespace).split()))
self._cache.delete('namespaces')

def get_entities(self, ns, entity):
key = "%s.%s" % (ns, entity)
cb = lambda: self._get_entities(ns,entity)
return self._load_from_cache_or_do(key, cb)

def delete_entities(self, ns, entity_type):
key = "%s.%s" % (ns, entity_type)
LOGGER.info(self._run_command(("delete %s --all " % entity_type).split() + self._namespace(ns)))
self._cache.delete(key)

def delete_entity(self, ns, entity_type, object_name):
key = "%s.%s" % (ns, entity_type)
LOGGER.info(self._run_command(("delete %s %s " % (entity_type, object_name)).split() + self._namespace(ns)))
self._cache.delete(key)

def get_object_in_format(self, ns, entity_type, object, format):
key = "%s.%s.%s.%s" % (ns, entity_type, object, format)
cb = lambda: self._get_object_in_format(ns, entity_type, object, format)
Expand Down
31 changes: 31 additions & 0 deletions kubefuse/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,37 @@ def list_files(self, path):
return p.SUPPORTED_RESOURCE_TYPES
return self.client.get_namespaces() # + ['all']

def rmdir(self, path):
p = KubePath().parse_path(path)
if not p.exists(self.client):
logging.info("path doesn't exist")
raise FuseOSError(errno.ENOENT)
if not p.is_dir():
logging.info("not a directory")
raise FuseOSError(errno.ENOTDIR)

if p.action:
raise FuseOSError(errno.EROFS)
if p.object_id:
return self.client.delete_entity(p.namespace, p.resource_type, p.object_id)
if p.resource_type:
return self.client.delete_entities(p.namespace, p.resource_type)
if p.namespace:
return self.client.delete_namespace(p.namespace)
raise FuseOSError(errno.EROFS)

def unlink(self, path):
p = KubePath().parse_path(path)
if not p.exists(self.client):
logging.info("path doesn't exist")
raise FuseOSError(errno.ENOENT)
if p.is_dir():
logging.info("is a directory")
raise FuseOSError(errno.EISDIR)
# We just let unlinks succeed, though the files will remain
# This is for compatibility with `rm -rf` - though just using rmdir
# will have the same effect in this implementation

def getattr(self, path):
p = KubePath().parse_path(path)
if path in self.open_files:
Expand Down
6 changes: 6 additions & 0 deletions kubefuse/kubefuse.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ def readdir(self, path, fh):
def getattr(self, path, fh=None):
return self.fs.getattr(path)

def rmdir(self, path):
return self.fs.rmdir(path)

def unlink(self, path):
return self.fs.unlink(path)

def open(self, path, fh):
self.fd += 1
self.fs.open(path, fh)
Expand Down