Add Kubernetes configuration provider which writes config to a secret

Fixes #145
This commit is contained in:
Joseph Schorr 2015-07-27 11:17:44 -04:00
parent 88a04441de
commit fd3a21fba9
10 changed files with 179 additions and 44 deletions

View file

@ -16,6 +16,10 @@ class FileConfigProvider(BaseProvider):
self.yaml_path = os.path.join(config_volume, yaml_filename)
self.py_path = os.path.join(config_volume, py_filename)
@property
def provider_id(self):
return 'file'
def update_app_config(self, app_config):
if os.path.exists(self.py_path):
logger.debug('Applying config file: %s', self.py_path)
@ -25,7 +29,7 @@ class FileConfigProvider(BaseProvider):
logger.debug('Applying config file: %s', self.yaml_path)
import_yaml(app_config, self.yaml_path)
def get_yaml(self):
def get_config(self):
if not os.path.exists(self.yaml_path):
return None
@ -33,10 +37,10 @@ class FileConfigProvider(BaseProvider):
import_yaml(config_obj, self.yaml_path)
return config_obj
def save_yaml(self, config_obj):
def save_config(self, config_obj):
export_yaml(config_obj, self.yaml_path)
def yaml_exists(self):
def config_exists(self):
return self.volume_file_exists(self.yaml_filename)
def volume_exists(self):
@ -49,13 +53,16 @@ class FileConfigProvider(BaseProvider):
return open(os.path.join(self.config_volume, filename), mode)
def save_volume_file(self, filename, flask_file):
filepath = os.path.join(self.config_volume, filename)
try:
flask_file.save(os.path.join(self.config_volume, filename))
flask_file.save(filepath)
except IOError as ioe:
raise CannotWriteConfigException(str(ioe))
return filepath
def requires_restart(self, app_config):
file_config = self.get_yaml()
file_config = self.get_config()
if not file_config:
return False