def createTemplate(data, path): templater = Template() templater.template = open('./template.adoc.in').read() tdata = { "template": data['labels']['template'], } # Fill in the template description, if supplied if 'annotations' in data['metadata'] and 'description' in data['metadata']['annotations']: tdata['description'] = data['metadata']['annotations']['description'] # special case: AMQ SSL templates have additional description global amq_ssl_desc if re.match('amq', path) and re.match('.*ssl\.json$', path): if not amq_ssl_desc: with open('amq-ssl.adoc.in','r') as tmp: amq_ssl_desc = tmp.read() tdata['description'] += "\n\n" + amq_ssl_desc # special case: JDG templates have additional description if re.match('datagrid', path): with open('datagrid.adoc.in','r') as tmp: datagrid_desc = tmp.read() tdata['description'] += "\n\n" + datagrid_desc # special case: JDG templates have additional description if re.match('sso', path): with open('sso.adoc.in','r') as tmp: sso_desc = tmp.read() tdata['description'] += "\n\n" + sso_desc # Fill in template parameters table, if there are any if ("parameters" in data and "objects" in data) and len(data["parameters"]) > 0: tdata['parameters'] = [{ 'parametertable': createParameterTable(data) }] if "objects" in data: tdata['objects'] = [{}] # Fill in sections if they are present in the JSON (createObjectTable version) for kind in ['Service', 'Route', 'BuildConfig', 'PersistentVolumeClaim']: if 0 >= len([ x for x in data["objects"] if kind == x["kind"] ]): continue tdata['objects'][0][kind] = [{ "table": createObjectTable(data, kind) }] # Fill in sections if they are present in the JSON (createContainerTable version) for kind in ['image', 'readinessProbe', 'ports', 'env']: if 0 >= len([obj for obj in data["objects"] if obj["kind"] == "DeploymentConfig"]): continue tdata['objects'][0][kind] = [{ "table": createContainerTable(data, kind) }] # Fill in sections if they are present in the JSON (createDeployConfigTable version) for kind in ['triggers', 'replicas', 'volumes', 'serviceAccountName']: if 0 >= len([obj for obj in data["objects"] if obj["kind"] == "DeploymentConfig"]): continue if kind in ['volumes', 'serviceAccountName']: specs = [d["spec"]["template"]["spec"] for d in data["objects"] if d["kind"] == "DeploymentConfig"] matches = [spec[kind] for spec in specs if spec.get(kind) is not None] if len(matches) <= 0: continue tdata['objects'][0][kind] = [{ "table": createDeployConfigTable(data, kind) }] # the 'secrets' section is not relevant to the secrets templates if not re.match('^secrets', path): specs = [d["spec"]["template"]["spec"] for d in data["objects"] if d["kind"] == "DeploymentConfig"] serviceAccountName = [spec["serviceAccountName"] for spec in specs if spec.get("serviceAccountName") is not None] # our 'secrets' are always attached to a service account # only include the secrets section if we have defined serviceAccount(s) if len(serviceAccountName) > 0: if re.match('^datavirt', path): tdata['objects'][0]['secrets'] = [{ "secretName": "datavirt-app-secret", "secretFile": "datavirt-app-secret.yaml" }] else: secretName = [param["value"] for param in data["parameters"] if "value" in param and param["value"].endswith("-app-secret")] if len(secretName) > 0: tdata['objects'][0]['secrets'] = [{ "secretName": secretName[0], "secretFile": secretName[0] + ".json" }] # currently the clustering section applies only to EAP templates if re.match('^eap', path): tdata['objects'][0]['clustering'] = [{}] return templater.render(tdata)
def create_template(data, path): templater = Template() templater.template = open('./template.adoc.in').read() tdata = { "template": data['labels']['template'], } # Fill in the template description, if supplied if 'annotations' in data['metadata'] and 'description' in data['metadata'][ 'annotations']: tdata['description'] = data['metadata']['annotations']['description'] # Fill in template parameters table, if there are any if ("parameters" in data and "objects" in data) and len(data["parameters"]) > 0: tdata['parameters'] = [{ 'parametertable': create_parameter_table(data) }] if "objects" in data: tdata['objects'] = [{}] # Fill in sections if they are present in the JSON (create_object_table version) for kind in [ 'Service', 'Route', 'BuildConfig', 'PersistentVolumeClaim' ]: if 0 >= len([x for x in data["objects"] if kind == x["kind"]]): continue tdata['objects'][0][kind] = [{ "table": create_object_table(data, kind) }] # Fill in sections if they are present in the JSON (create_container_table version) for kind in [ 'image', 'readinessProbe', 'livenessProbe', 'ports', 'env' ]: if 0 >= len([ obj for obj in data["objects"] if obj["kind"] == "DeploymentConfig" ]): continue tdata['objects'][0][kind] = [{ "table": create_container_table(data, kind) }] # Fill in sections if they are present in the JSON (create_deploy_config_table version) for kind in ['triggers', 'replicas', 'volumes', 'serviceAccountName']: if 0 >= len([ obj for obj in data["objects"] if obj["kind"] == "DeploymentConfig" ]): continue if kind in ['volumes', 'serviceAccountName']: specs = [ d["spec"]["template"]["spec"] for d in data["objects"] if d["kind"] == "DeploymentConfig" ] matches = [ spec[kind] for spec in specs if spec.get(kind) is not None ] if len(matches) <= 0: continue tdata['objects'][0][kind] = [{ "table": create_deploy_config_table(data, kind) }] # the 'secrets' section is not relevant to the secrets templates if not re.match('^secrets', path): specs = [ d["spec"]["template"]["spec"] for d in data["objects"] if d["kind"] == "DeploymentConfig" ] service_account_name = [ spec["serviceAccountName"] for spec in specs if spec.get("serviceAccountName") is not None ] # only include the secrets section if we have defined serviceAccount(s) secret_name = "" if len(service_account_name) > 0: for param in data["parameters"]: if "example" in param: if not isinstance(param["example"], int) and param["example"].endswith( "app-secret"): secret_name += ' * ' + param["example"] + '\n' elif "value" in param and param["value"].endswith( "app-secret"): secret_name += ' * ' + param["value"] + '\n' tdata['objects'][0]['secrets'] = [{"secretNames": secret_name}] # Any template that supports clustering needs to be added in the clusteringTemplates var. # TODO: improve it to not use full template name clustering_templates = [ 'rhpam70-authoring-ha.yaml', 'rhpam71-authoring-ha.yaml', 'rhdm71-authoring-ha.yaml', 'rhpam72-authoring-ha.yaml', 'rhdm72-authoring-ha.yaml', 'rhpam73-authoring-ha.yaml', 'rhdm73-authoring-ha.yaml', 'rhpam74-authoring-ha.yaml', 'rhdm74-authoring-ha.yaml', 'rhpam75-authoring-ha.yaml', 'rhdm75-authoring-ha.yaml', 'rhpam76-authoring-ha.yaml', 'rhdm76-authoring-ha.yaml', 'rhpam77-authoring-ha.yaml', 'rhdm77-authoring-ha.yaml', 'rhpam78-authoring-ha.yaml', 'rhdm78-authoring-ha.yaml', 'rhpam79-authoring-ha.yaml', 'rhdm79-authoring-ha.yaml', 'rhpam710-authoring-ha.yaml', 'rhdm710-authoring-ha.yaml', 'rhpam711-authoring-ha.yaml', 'rhdm711-authoring-ha.yaml', 'rhpam712-authoring-ha.yaml', 'rhdm712-authoring-ha.yaml', 'rhpam713-authoring-ha.yaml', 'rhdm713-authoring-ha.yaml' ] for template in clustering_templates: if str(path).rsplit('/', 1)[-1] == template: tdata['objects'][0]['clustering'] = [{}] return templater.render(tdata)
def createTemplate(data, path): templater = Template() templater.template = open('./template.adoc.in').read() tdata = { "template": data['labels']['template'], } # Fill in the template description, if supplied if 'annotations' in data['metadata'] and 'description' in data['metadata'][ 'annotations']: tdata['description'] = data['metadata']['annotations']['description'] # special case: AMQ SSL templates have additional description global amq_ssl_desc if re.match('amq', path) and re.match('.*ssl\.json$', path): if not amq_ssl_desc: with open('amq-ssl.adoc.in', 'r') as tmp: amq_ssl_desc = tmp.read() tdata['description'] += "\n\n" + amq_ssl_desc # Fill in template parameters table, if there are any if ("parameters" in data and "objects" in data) and len(data["parameters"]) > 0: tdata['parameters'] = [{'parametertable': createParameterTable(data)}] if "objects" in data: tdata['objects'] = [{}] # Fill in sections if they are present in the JSON (createObjectTable version) for kind in [ 'Service', 'Route', 'BuildConfig', 'PersistentVolumeClaim' ]: if 0 >= len([x for x in data["objects"] if kind == x["kind"]]): continue tdata['objects'][0][kind] = [{ "table": createObjectTable(data, kind) }] # Fill in sections if they are present in the JSON (createContainerTable version) for kind in ['image', 'readinessProbe', 'ports', 'env']: if 0 >= len([ obj for obj in data["objects"] if obj["kind"] == "DeploymentConfig" ]): continue tdata['objects'][0][kind] = [{ "table": createContainerTable(data, kind) }] # Fill in sections if they are present in the JSON (createDeployConfigTable version) for kind in ['triggers', 'replicas', 'volumes', 'serviceAccount']: if 0 >= len([ obj for obj in data["objects"] if obj["kind"] == "DeploymentConfig" ]): continue tdata['objects'][0][kind] = [{ "table": createDeployConfigTable(data, kind) }] # the 'secrets' section is not relevant to the secrets templates if not re.match('^secrets', path): tdata['objects'][0]['secrets'] = [{ "templateabbrev": data['labels']['template'][0:3] }] # currently the clustering section applies only to EAP templates if re.match('^eap', path): tdata['objects'][0]['clustering'] = [{}] return templater.render(tdata)