k8s.io/test-infra@v0.0.0-20240520184403-27c6b4c223d8/jobs/e2e_node/crio/templates/generate (about)

     1  #!/usr/bin/env bash
     2  # Copyright 2023 The Kubernetes Authors.
     3  #
     4  # Licensed under the Apache License, Version 2.0 (the "License");
     5  # you may not use this file except in compliance with the License.
     6  # You may obtain a copy of the License at
     7  #
     8  #     http://www.apache.org/licenses/LICENSE-2.0
     9  #
    10  # Unless required by applicable law or agreed to in writing, software
    11  # distributed under the License is distributed on an "AS IS" BASIS,
    12  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  # See the License for the specific language governing permissions and
    14  # limitations under the License.
    15  
    16  set -euo pipefail
    17  IFS=$'\n\t'
    18  
    19  cd "$(dirname "$0")"
    20  
    21  if ((BASH_VERSINFO[0] < 4)); then
    22      echo "At least bash version 4 is required to run this script"
    23      exit 1
    24  fi
    25  
    26  # Change the following configurations to adapt the resulting ignitions files.
    27  declare -A CONFIGURATIONS=(
    28      ["crio_cgroupsv1"]="root cgroups-v1 criu-enabled"
    29      ["crio_cgroupsv1_eventedpleg"]="root cgroups-v1 eventedpleg"
    30      ["crio_cgroupsv1_hugepages"]="root cgroups-v1 hugepages"
    31      ["crio_cgroupsv2"]="root"
    32      ["crio_cgroupsv2_swap1g"]="root swap-1G"
    33      ["crio_cgroupsv2_imagefs"]="root imagefs"
    34      ["crio_cgroupsv2_splitfs"]="root splitfs"
    35      ["crio_cgroupsv2_hugepages"]="root hugepages"
    36      ["crio_cgroupsv2_userns"]="root userns"
    37  )
    38  
    39  CONTAINER_RUNTIME=$(which podman 2>/dev/null) ||
    40      CONTAINER_RUNTIME=$(which nerdctl 2>/dev/null) ||
    41      CONTAINER_RUNTIME=$(which docker 2>/dev/null)
    42  
    43  if [[ -z "$CONTAINER_RUNTIME" ]]; then
    44      echo "Neither podman, nerdctl nor docker found in \$PATH"
    45      exit 1
    46  fi
    47  
    48  YQ_IMAGE=mikefarah/yq:4
    49  BUTANE_IMAGE=quay.io/coreos/butane:release
    50  BASE_PATH=base
    51  
    52  # Pull the latest image version
    53  for IMAGE in $YQ_IMAGE $BUTANE_IMAGE; do
    54      $CONTAINER_RUNTIME pull "$IMAGE"
    55  done
    56  
    57  merge() {
    58      ARGS=()
    59      for ARG in "${@:2}"; do
    60          ARGS+=("$BASE_PATH/$ARG.yaml")
    61      done
    62  
    63      set -x
    64      # shellcheck disable=SC2016
    65      $CONTAINER_RUNTIME run --privileged -i --rm -v "$PWD":/w -w /w $YQ_IMAGE \
    66          ea '. as $item ireduce ({}; . *+ $item)' "${ARGS[@]}" >"$1.yaml"
    67      { set +x; } 2>/dev/null
    68  }
    69  
    70  for i in "${!CONFIGURATIONS[@]}"; do
    71      echo "Building ${i}"
    72  
    73      IFS=' ' read -r -a ARGS <<<"${CONFIGURATIONS[$i]}"
    74      merge "$i" "${ARGS[@]}"
    75  
    76      set -x
    77      $CONTAINER_RUNTIME run --privileged -i --rm -v "$PWD":/w -w /w $BUTANE_IMAGE \
    78          -ps -d $BASE_PATH <"$i.yaml" >../"$i.ign"
    79      { set +x; } 2>/dev/null
    80  done