def main(): path = os.path.dirname(__file__) + '/../../templates' output = kadet.BaseObj() for file in inventory.parameters.dockerfiles: contents = jinja2_render_file([path], 'Dockerfile', json.dumps(file)) output.root['Dockerfile.' + file.name] = contents return output
def main(): output = kadet.BaseObj() output.root.nginx_deployment = kubelib.Deployment(name=name, labels=labels, containers=[nginx_container]) output.root.nginx_service = kubelib.Service( name=name, labels=labels, ports=[svc_port], selector=svc_selector ) return output
def main(): path = os.path.dirname(__file__) + "/../../templates" output = kadet.BaseObj() variables = { k: v for d in inventory.parameters.nginx for k, v in d.items() } nginx_conf = jinja2_render_file([path], "nginx.conf", json.dumps(variables)) output.root["manifests/default.conf"] = nginx_conf index_html = jinja2_render_file([path], "index.html", json.dumps(variables)) output.root["manifests/html/index.html"] = index_html start_script = jinja2_render_file([path], "scripts/script.sh", json.dumps(variables)) output.root["run.sh"] = start_script readme = jinja2_render_file([path], "docs/README.md", json.dumps(variables)) output.root["README.md"] = readme if "server_errors" in variables.keys(): for error in variables["server_errors"]: error_page = jinja2_render_file([path], "error.html", json.dumps(error)) output.root[ f"manifests/html/{error.status_code}.html"] = error_page return output
def main(input_params): team_name = input_params.get("team_name", "no-owner") if "namespace" in input_params: namespace = input_params.get("namespace") else: raise ValueError("'namespace' key not found in 'input_params'") if "post_process_inputs" in input_params: post_process_inputs = input_params.get("post_process_inputs") else: raise ValueError( "'post_process_inputs' key not found in 'input_params'") # get path where files have been compiled on this run target_name = inventory.parameters.kapitan.vars.target compile_path = input_params.get("compile_path") root_path = get_root_path(compile_path, target_name) all_objects = {} for post_process_input in post_process_inputs: output = kadet.BaseObj() p = get_post_process_input_output_path(post_process_input) dir_file_path = os.path.join(root_path, target_name, p) for file in glob.glob(dir_file_path + "/*.yaml", recursive=True): # remove file extension file_name = os.path.basename(file).replace(".yaml", "") with open(file) as fp: yaml_stream = yaml.safe_load_all(fp) objects_for_file = [] for obj in yaml_stream: o = kadet.BaseObj.from_dict(obj) o = set_team_name(o, team_name) o = set_namespace(o, namespace) objects_for_file.append(o) all_objects.update({file_name: objects_for_file}) fp.close() output = kadet.BaseObj() for file_name, obj in all_objects.items(): output.root[file_name] = obj return output
from kapitan.inputs import kadet kubelib = kadet.load_from_search_paths("kubelib") inv = kadet.inventory() name = "nginx" labels = kadet.BaseObj.from_dict({"app": name}) nginx_container = kubelib.Container(name=name, image=inv.parameters.nginx.image, ports=[{ "containerPort": 80 }]) svc_selector = {"app": name} svc_port = kadet.BaseObj() svc_port.root.name = "http" svc_port.root.port = 80 svc_port.root.targetPort = 80 def main(): return { "nginx_deployment": kubelib.Deployment(name=name, labels=labels, containers=[nginx_container]), "nginx_service": kubelib.Service(name=name, labels=labels, ports=[svc_port], selector=svc_selector),
def main(): output = kadet.BaseObj() output.root.my_kadet_component = name output.root.labels = labels return output