def createTemplate(data, path): templater = Template() templater.template = open('./docs/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': 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")] 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 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)
def createTemplate(data, directory, template_file): 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': 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 "secrets" != directory: tdata['objects'][0]['secrets'] = [{ "templateabbrev": data['labels']['template'][0:3] }] # currently the clustering section applies only to EAP templates if "eap" == directory: 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'] # 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', 'livenessProbe', '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] # only include the secrets section if we have defined serviceAccount(s) secretName = "" if len(serviceAccountName) > 0: for param in data["parameters"]: if "example" in param: if not isinstance(param["example"], int) and param["example"].endswith("app-secret"): secretName += param["example"] + '\n' elif "value" in param and param["value"].endswith("app-secret"): secretName += param["value"] + '\n' tdata['objects'][0]['secrets'] = [{"secretNames": secretName}] # Any template that supports clustering needs to be added in the clusteringTemplates var. clusteringTemplates = [ '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' ] for template in clusteringTemplates: 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 # 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 # 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): specs = [ d["spec"]["template"]["spec"] for d in data["objects"] if d["kind"] == "DeploymentConfig" ] serviceAccount = [ spec["serviceAccount"] for spec in specs if spec.get("serviceAccount") is not None ] # our 'secrets' are always attached to a service account if len(serviceAccount) > 0: 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)
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)