volcano.sh/volcano@v1.9.0/hack/generate-yaml.sh (about)

     1  #!/bin/bash
     2  
     3  #
     4  # Copyright 2021 The Volcano Authors.
     5  #
     6  # Licensed under the Apache License, Version 2.0 (the "License");
     7  # you may not use this file except in compliance with the License.
     8  # You may obtain a copy of the License at
     9  #
    10  #     http://www.apache.org/licenses/LICENSE-2.0
    11  #
    12  # Unless required by applicable law or agreed to in writing, software
    13  # distributed under the License is distributed on an "AS IS" BASIS,
    14  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    15  # See the License for the specific language governing permissions and
    16  # limitations under the License.
    17  #
    18  
    19  set -o errexit
    20  set -o nounset
    21  set -o pipefail
    22  
    23  VK_ROOT=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/..
    24  export HELM_BIN_DIR=${VK_ROOT}/${BIN_DIR}
    25  export RELEASE_FOLDER=${VK_ROOT}/${RELEASE_DIR}
    26  
    27  export HELM_VER=${HELM_VER:-v3.6.3}
    28  export VOLCANO_IMAGE_TAG=${TAG:-"latest"}
    29  export YAML_FILENAME=volcano-${VOLCANO_IMAGE_TAG}.yaml
    30  export MONITOR_YAML_FILENAME=volcano-monitoring-${VOLCANO_IMAGE_TAG}.yaml
    31  export CRD_VERSION=${CRD_VERSION:-v1}
    32  
    33  case $CRD_VERSION in
    34    bases)
    35      ;;
    36    v1)
    37      CRD_VERSION="bases"
    38      ;;
    39    v1beta1)
    40      ;;
    41    *)
    42      echo Invaild CRD_VERSION $CRD_VERSION !!!
    43      echo CRD_VERSION only support \"bases\", \"v1\" and \"v1beta1\"
    44      exit 1
    45      ;;
    46  esac
    47  
    48  LOCAL_OS=${OSTYPE}
    49  case $LOCAL_OS in
    50    "linux"*)
    51      LOCAL_OS='linux'
    52      ;;
    53    "darwin"*)
    54      LOCAL_OS='darwin'
    55      ;;
    56    *)
    57      echo "This system's OS ${LOCAL_OS} isn't recognized/supported"
    58      exit 1
    59      ;;
    60  esac
    61  
    62  ARCH=$(go env GOARCH)
    63  
    64  # Step1. install helm binary
    65  if [[ ! -f "${HELM_BIN_DIR}/version.helm.${HELM_VER}" ]] || [[ ! -f "${HELM_BIN_DIR}/helm" ]] ; then
    66      TD=$(mktemp -d)
    67      cd "${TD}" && \
    68          curl -Lo "${TD}/helm.tgz" "https://get.helm.sh/helm-${HELM_VER}-${LOCAL_OS}-${ARCH}.tar.gz" && \
    69          tar xfz helm.tgz && \
    70          mv ${LOCAL_OS}-${ARCH}/helm "${HELM_BIN_DIR}/helm-${HELM_VER}" && \
    71          cp "${HELM_BIN_DIR}/helm-${HELM_VER}" "${HELM_BIN_DIR}/helm" && \
    72          chmod +x ${HELM_BIN_DIR}/helm
    73          rm -rf "${TD}"
    74  
    75          if [[ ! -f "${HELM_BIN_DIR}/version.helm.${HELM_VER}" ]] ; then
    76            touch "${HELM_BIN_DIR}/version.helm.${HELM_VER}"
    77          fi
    78  fi
    79  
    80  # Step2. update helm templates from config dir
    81  HELM_TEMPLATES_DIR=${VK_ROOT}/installer/helm/chart/volcano/templates
    82  HELM_VOLCANO_CRD_DIR=${VK_ROOT}/installer/helm/chart/volcano/crd
    83  HELM_JOBFLOW_CRD_DIR=${VK_ROOT}/installer/helm/chart/volcano/charts/jobflow/crd
    84  VOLCANO_CRD_DIR=${VK_ROOT}/config/crd/volcano
    85  JOBFLOW_CRD_DIR=${VK_ROOT}/config/crd/jobflow
    86  echo Updating templates in $HELM_TEMPLATES_DIR
    87  # use tail because we should skip top two line
    88  # sync volcano bases
    89  tail -n +3 ${VOLCANO_CRD_DIR}/bases/batch.volcano.sh_jobs.yaml > ${HELM_VOLCANO_CRD_DIR}/bases/batch.volcano.sh_jobs.yaml
    90  tail -n +3 ${VOLCANO_CRD_DIR}/bases/bus.volcano.sh_commands.yaml > ${HELM_VOLCANO_CRD_DIR}/bases/bus.volcano.sh_commands.yaml
    91  tail -n +3 ${VOLCANO_CRD_DIR}/bases/scheduling.volcano.sh_podgroups.yaml > ${HELM_VOLCANO_CRD_DIR}/bases/scheduling.volcano.sh_podgroups.yaml
    92  tail -n +3 ${VOLCANO_CRD_DIR}/bases/scheduling.volcano.sh_queues.yaml > ${HELM_VOLCANO_CRD_DIR}/bases/scheduling.volcano.sh_queues.yaml
    93  tail -n +3 ${VOLCANO_CRD_DIR}/bases/nodeinfo.volcano.sh_numatopologies.yaml > ${HELM_VOLCANO_CRD_DIR}/bases/nodeinfo.volcano.sh_numatopologies.yaml
    94  
    95  # sync v1beta1
    96  tail -n +3 ${VOLCANO_CRD_DIR}/v1beta1/batch.volcano.sh_jobs.yaml > ${HELM_VOLCANO_CRD_DIR}/v1beta1/batch.volcano.sh_jobs.yaml
    97  tail -n +3 ${VOLCANO_CRD_DIR}/v1beta1/bus.volcano.sh_commands.yaml > ${HELM_VOLCANO_CRD_DIR}/v1beta1/bus.volcano.sh_commands.yaml
    98  tail -n +3 ${VOLCANO_CRD_DIR}/v1beta1/scheduling.volcano.sh_podgroups.yaml > ${HELM_VOLCANO_CRD_DIR}/v1beta1/scheduling.volcano.sh_podgroups.yaml
    99  tail -n +3 ${VOLCANO_CRD_DIR}/v1beta1/scheduling.volcano.sh_queues.yaml > ${HELM_VOLCANO_CRD_DIR}/v1beta1/scheduling.volcano.sh_queues.yaml
   100  tail -n +3 ${VOLCANO_CRD_DIR}/v1beta1/nodeinfo.volcano.sh_numatopologies.yaml > ${HELM_VOLCANO_CRD_DIR}/v1beta1/nodeinfo.volcano.sh_numatopologies.yaml
   101  
   102  # sync jobflow bases
   103  tail -n +3 ${JOBFLOW_CRD_DIR}/bases/flow.volcano.sh_jobflows.yaml > ${HELM_JOBFLOW_CRD_DIR}/bases/flow.volcano.sh_jobflows.yaml
   104  tail -n +3 ${JOBFLOW_CRD_DIR}/bases/flow.volcano.sh_jobtemplates.yaml > ${HELM_JOBFLOW_CRD_DIR}/bases/flow.volcano.sh_jobtemplates.yaml
   105  
   106  # Step3. generate yaml in folder
   107  if [[ ! -d ${RELEASE_FOLDER} ]];then
   108      mkdir ${RELEASE_FOLDER}
   109  fi
   110  
   111  DEPLOYMENT_FILE=${RELEASE_FOLDER}/${YAML_FILENAME}
   112  MONITOR_DEPLOYMENT_YAML_FILENAME=${RELEASE_FOLDER}/${MONITOR_YAML_FILENAME}
   113  echo "Generating volcano yaml file into ${DEPLOYMENT_FILE}"
   114  
   115  if [[ -f ${DEPLOYMENT_FILE} ]];then
   116      rm ${DEPLOYMENT_FILE}
   117  fi
   118  
   119  if [[ -f ${MONITOR_DEPLOYMENT_YAML_FILENAME} ]];then
   120      rm ${MONITOR_DEPLOYMENT_YAML_FILENAME}
   121  fi
   122  
   123  # Namespace
   124  cat ${VK_ROOT}/installer/namespace.yaml > ${DEPLOYMENT_FILE}
   125  
   126  # Volcano
   127  ${HELM_BIN_DIR}/helm template ${VK_ROOT}/installer/helm/chart/volcano --namespace volcano-system \
   128        --name-template volcano --set basic.image_tag_version=${VOLCANO_IMAGE_TAG} --set basic.crd_version=${CRD_VERSION}\
   129        -s templates/admission.yaml \
   130        -s templates/batch_v1alpha1_job.yaml \
   131        -s templates/bus_v1alpha1_command.yaml \
   132        -s templates/controllers.yaml \
   133        -s templates/scheduler.yaml \
   134        -s templates/scheduling_v1beta1_podgroup.yaml \
   135        -s templates/scheduling_v1beta1_queue.yaml \
   136        -s templates/nodeinfo_v1alpha1_numatopologies.yaml \
   137        -s templates/webhooks.yaml \
   138        >> ${DEPLOYMENT_FILE}
   139  
   140  # JobFlow
   141  ${HELM_BIN_DIR}/helm template ${VK_ROOT}/installer/helm/chart/volcano/charts/jobflow --namespace volcano-system \
   142        --name-template volcano --set basic.image_tag_version=${VOLCANO_IMAGE_TAG} --set basic.crd_version=${CRD_VERSION}\
   143        -s templates/flow_v1alpha1_jobflows.yaml \
   144        -s templates/flow_v1alpha1_jobtemplates.yaml \
   145        >> ${DEPLOYMENT_FILE}
   146  
   147  # Monitoring
   148  ${HELM_BIN_DIR}/helm template ${VK_ROOT}/installer/helm/chart/volcano --namespace volcano-monitoring \
   149        --name-template volcano --set basic.image_tag_version=${VOLCANO_IMAGE_TAG} --set custom.metrics_enable=true \
   150        -s templates/prometheus.yaml \
   151        -s templates/kubestatemetrics.yaml \
   152        -s templates/grafana.yaml \
   153        >> ${MONITOR_DEPLOYMENT_YAML_FILENAME}