Adds ability to upload config dir to k8s in config
This commit is contained in:
parent
3d4e43c8d1
commit
d387ba171f
10 changed files with 138 additions and 84 deletions
|
@ -2,19 +2,20 @@ import os
|
|||
from backports.tempfile import TemporaryDirectory
|
||||
|
||||
from config_app.config_util.config.fileprovider import FileConfigProvider
|
||||
from config_app.config_util.k8sinterface import kubernetes_access_instance
|
||||
|
||||
|
||||
class TransientDirectoryProvider(FileConfigProvider):
|
||||
""" Implementation of the config provider that reads and writes the data
|
||||
from/to the file system, only using temporary directories,
|
||||
deleting old dirs and creating new ones as requested.
|
||||
"""
|
||||
def __init__(self, config_volume, yaml_filename, py_filename, kubernetes=False):
|
||||
def __init__(self, config_volume, yaml_filename, py_filename):
|
||||
# Create a temp directory that will be cleaned up when we change the config path
|
||||
# This should ensure we have no "pollution" of different configs:
|
||||
# no uploaded config should ever affect subsequent config modifications/creations
|
||||
temp_dir = TemporaryDirectory()
|
||||
self.temp_dir = temp_dir
|
||||
self.kubernetes = kubernetes
|
||||
super(TransientDirectoryProvider, self).__init__(temp_dir.name, yaml_filename, py_filename)
|
||||
|
||||
@property
|
||||
|
@ -36,7 +37,10 @@ class TransientDirectoryProvider(FileConfigProvider):
|
|||
return self.config_volume
|
||||
|
||||
def save_configuration_to_kubernetes(self):
|
||||
if not self.kubernetes:
|
||||
raise Exception("Not on kubernetes, cannot save configuration.")
|
||||
config_path = self.get_config_dir_path()
|
||||
|
||||
print('do stuf')
|
||||
for name in os.listdir(config_path):
|
||||
file_path = os.path.join(self.config_volume, name)
|
||||
kubernetes_access_instance.save_file_as_secret(name, file_path)
|
||||
|
||||
return 200
|
||||
|
|
Reference in a new issue