import lib.constant as C
from lib.utils import load_yaml, write_yaml, logger
from lib.generator import k8s_utils
def generate_yaml_mf_store(input_yaml, output_file, user_config):
logger.info(f"Generating YAML from {input_yaml} to {output_file}")
deploy_config = user_config[C.MOTOR_DEPLOY_CONFIG]
data = load_yaml(input_yaml, False)
deployment_data = data[0]
deployment_data[C.METADATA][C.NAMESPACE] = deploy_config[C.CONFIG_JOB_ID]
container = deployment_data[C.SPEC][C.TEMPLATE][C.SPEC][C.CONTAINERS][0]
container[C.IMAGE] = deploy_config[C.IMAGE_NAME]
if C.ENV not in container:
container[C.ENV] = []
container[C.ENV].append(
{C.NAME: C.ENV_ASCEND_MF_STORE_PORT, C.VALUE: str(C.DEFAULT_MF_STORE_PORT)}
)
service_data = data[1]
service_data[C.METADATA][C.NAMESPACE] = deploy_config[C.CONFIG_JOB_ID]
ports = service_data.get(C.SPEC, {}).get(C.PORTS, [])
if not ports:
raise ValueError(f"Missing required service ports in {input_yaml}.")
ports[0][C.PORT] = C.DEFAULT_MF_STORE_PORT
ports[0][C.TARGET_PORT] = C.DEFAULT_MF_STORE_PORT
write_yaml(data, output_file, False)
k8s_utils.g_generate_yaml_list.append(output_file)