def from_dict(self, configkey, literal_dict):
"""Turn a dict into a configmap."""
tdir = tempfile.mkdtemp()
for key in literal_dict:
with open(os.path.join(tdir, key), 'w') as h:
h.write(literal_dict[key])
max_timeout = 120
retry_delay = 1
success = False
start = time.time()
now = time.time()
while success is False and now < start + max_timeout:
try:
self.kubectl.create.configmap(
configkey,
"--from-file={}".format(tdir),
'--context={}'.format(self.config.context),
'--namespace={}'.format(self.config.namespace)
)
success = True
except sh.ErrorReturnCode_1 as err:
LOG.error(
"Error creating configmap %s (%s remaining)",
err, (start + max_timeout) - now
)
time.sleep(
min(
retry_delay,
(max_timeout - (time.time() - start))
)
)
retry_delay = retry_delay * 2
now = time.time()
shutil.rmtree(tdir)
评论列表
文章目录