#!/bin/bash
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
BASE_DIR=$(cd "${SCRIPT_DIR}/.." && pwd)
COMPONENT_BASE_DIR=$(cd "${BASE_DIR}/../component" && pwd)
CRDS_DIR="${BASE_DIR}/app-crds/charts"
APP_DIR="${BASE_DIR}/app/charts"
process_resource() {
local doc=$1
local component_name=$2
local variant=$3
local kind
local name
kind=$(echo "$doc" | yq eval '.kind' -)
name=$(echo "$doc" | yq eval '.metadata.name' -)
if [[ -z "${kind}" || "${kind}" == "null" || -z "${name}" || "${name}" == "null" ]]; then
echo "Warning: skipping resource with kind='${kind}', name='${name}'"
return
fi
local filename="${kind}-${name}.yaml"
local target_dir
if [[ "${kind}" == "CustomResourceDefinition" ]]; then
target_dir="${CRDS_DIR}/${component_name}-crds/yamls"
if [[ -n "${variant}" ]]; then
target_dir="${target_dir}/${variant}"
fi
else
target_dir="${APP_DIR}/${component_name}/yamls"
if [[ -n "${variant}" ]]; then
target_dir="${target_dir}/${variant}"
fi
fi
mkdir -p "${target_dir}"
local filepath="${target_dir}/${filename}"
echo "$doc" > "${filepath}"
echo "Created: ${filepath}"
}
process_component() {
local source_yaml=$1
local component_name=$2
local variant=$3
if [[ ! -f "${source_yaml}" ]]; then
echo "Warning: source YAML file not found: ${source_yaml}, skipping"
return
fi
if [[ -n "${variant}" ]]; then
echo "========== Processing: ${source_yaml} -> ${component_name} (variant: ${variant}) =========="
else
echo "========== Processing: ${source_yaml} -> ${component_name} =========="
fi
local i=0
local doc
while true; do
doc=$(yq eval "select(documentIndex == $i)" "$source_yaml")
if [[ -z "$doc" || "$doc" == "null" ]]; then
break
fi
process_resource "$doc" "$component_name" "$variant"
((i++))
done
if [[ $i -eq 0 ]]; then
echo "Warning: no documents found in ${source_yaml}"
fi
}
declare -A COMPONENT_YAML_PREFIX=(
["infer-operator"]="infer-operator"
["ascend-device-plugin"]="ascendplugin"
["clusterd"]="clusterd"
["noded"]="noded"
["ascend-operator"]="ascend-operator"
["npu-exporter"]="npu-exporter"
["ascend-for-volcano"]="volcano"
["k8s-rdma-shared-dev-plugin"]="k8s-rdma-shared-dp"
)
for component in "${!COMPONENT_YAML_PREFIX[@]}"; do
pattern="${COMPONENT_YAML_PREFIX[$component]}*.yaml"
build_dir="${COMPONENT_BASE_DIR}/${component}/build"
shopt -s nullglob
files=("${build_dir}"/${pattern})
shopt -u nullglob
for yaml_file in "${files[@]}"; do
base=$(basename "${yaml_file}" .yaml)
variant="default"
if [[ "${COMPONENT_YAML_PREFIX[$component]}" != "${base}" ]]; then
variant="${base#${COMPONENT_YAML_PREFIX[$component]}-}"
fi
process_component "${yaml_file}" "${component}" "${variant}"
done
done
echo "========== Done =========="