def apply(self, desc, filename, force=False):
"""Read, Merge then Apply."""
changes = self.apply_secrets(desc, filename)
if self.exists(desc.metadata.name):
# pull from the server
remote = munch.Munch()
try:
remote = self.get(desc.metadata.name)
except Exception as err:
LOG.error(
'%s failure to retrieve existing resource %s',
err,
filename
)
# merge our file on top of it
remote.update(desc)
# write to disk
with open(filename, 'w') as h:
h.write(remote.toJSON())
try:
if force or len(changes):
if changes:
LOG.info(
'Secret changes detected: %s -- Replacing pod',
changes
)
if desc.kind in ['Deployment']:
# even with force=true replacing
# a deployment doesn't cleanup and
# redeploy pods.
self.delete_path(filename)
self.create_path(filename)
else:
self.replace_path(filename, force=force)
else:
self.apply_file(filename)
except sh.ErrorReturnCode_1:
LOG.error('apply_file failed (forcing)')
if self.exists(desc.metadata.name):
self.delete_path(filename)
self.create_path(filename)
return changes
评论列表
文章目录