Fix uploading of rendered templates, support jinja user-data

This commit is contained in:
Stefan Reimer 2020-12-29 00:12:55 +01:00
parent 381091ec6a
commit 2b2c8e2ea8
4 changed files with 17 additions and 7 deletions

View File

@ -1,5 +1,10 @@
# Changelog
## 0.9.6
- only upload templates if render is successful
- support for jinja user-data
- tweak for kubezero output template
## 0.9.5
### New Features
Support for uploading and retrieving rendered templates from S3!

View File

@ -61,10 +61,13 @@ def include_raw_gz(context, files=None, gz=True, remove_comments=False):
# Remove full line comments but not shebang
_re_comment = re.compile(r'^\s*#[^!]')
_re_blank = re.compile(r'^\s*$')
_re_keep = re.compile(r'^## template: jinja$')
stripped_output = ''
for curline in output.splitlines():
if re.match(_re_blank, curline):
continue
elif re.match(_re_keep, curline):
stripped_output = stripped_output + curline + '\n'
elif re.match(_re_comment, curline):
logger.debug("Removed {}".format(curline))
else:

View File

@ -296,16 +296,17 @@ class Stack(object):
profile=self.profile, region=self.region)
logger.debug("Got template from s3://{}/{}".format(bucket, path))
self.cfn_template = template['Body'].read().decode('utf-8')
# Overwrite local copy
yaml_file = os.path.join(self.ctx['template_path'], self.rel_path, self.stackname + ".yaml")
ensure_dir(os.path.join(self.ctx['template_path'], self.rel_path))
with open(yaml_file, 'w') as yaml_contents:
yaml_contents.write(self.cfn_template)
except ClientError as e:
logger.error("Could not find template file on S3: {}/{}, {}".format(bucket, path, e))
self.cfn_template = template['Body'].read().decode('utf-8')
# Overwrite local copy
yaml_file = os.path.join(self.ctx['template_path'], self.rel_path, self.stackname + ".yaml")
ensure_dir(os.path.join(self.ctx['template_path'], self.rel_path))
with open(yaml_file, 'w') as yaml_contents:
yaml_contents.write(self.cfn_template)
else:
yaml_file = os.path.join(self.ctx['template_path'], self.rel_path, self.stackname + ".yaml")

View File

@ -2,6 +2,7 @@
# Source: CloudBender for stack {{ stackname }} at {{ timestamp }}
ClusterName: {{ parameters.ClusterName }}
Domain: {{ parameters.DnsZone }}
HighAvailableControlplane: {{ parameters.HighAvailable }}
cert-manager:
IamArn: {{ outputs.CertManagerRoleArn }}