|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Copyright 2024 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 -o errexit |
| 17 | +set -o nounset |
| 18 | +set -o pipefail |
| 19 | + |
| 20 | +DIR="$(dirname "${BASH_SOURCE[0]}")" |
| 21 | +ROOT_DIR="$(realpath "${DIR}/..")" |
| 22 | + |
| 23 | +function clone_or_checkout() { |
| 24 | + local repo=https://github.com/kubernetes/api |
| 25 | + local version=$1 |
| 26 | + local dest=$2 |
| 27 | + |
| 28 | + if [[ -d "${dest}" ]]; then |
| 29 | + echo "Checking out ${repo}#${version} to ${dest}" |
| 30 | + pushd "${dest}" |
| 31 | + git fetch origin |
| 32 | + git checkout "${version}" |
| 33 | + popd |
| 34 | + else |
| 35 | + echo "Cloning ${repo}#${version} to ${dest}" |
| 36 | + git clone --branch "${version}" --depth 1 "${repo}" "${dest}" |
| 37 | + fi |
| 38 | +} |
| 39 | + |
| 40 | +function find_package() { |
| 41 | + local dir=$1 |
| 42 | + find "${dir}" | grep register.go | sed "s#/register.go##g" | sed "s#${dir}/##g" || : |
| 43 | +} |
| 44 | + |
| 45 | +apiset=() |
| 46 | + |
| 47 | +function append_api() { |
| 48 | + local api=$1 |
| 49 | + if [[ ! " ${apiset[@]} " =~ " ${api} " ]]; then |
| 50 | + apiset+=("${api}") |
| 51 | + return 0 |
| 52 | + fi |
| 53 | + return 1 |
| 54 | +} |
| 55 | + |
| 56 | +function clone_api() { |
| 57 | + local release=$1 |
| 58 | + local skip=$2 |
| 59 | + version="release-1.${release}" |
| 60 | + version_dir="${ROOT_DIR}/_tmp/k8s-api/${version}" |
| 61 | + clone_or_checkout "${version}" "${version_dir}" |
| 62 | + for api in $(find_package "${version_dir}"); do |
| 63 | + if append_api "${api}" ; then |
| 64 | + if [[ "${release}" -eq "${skip}" ]]; then |
| 65 | + continue |
| 66 | + fi |
| 67 | + dir_api="${ROOT_DIR}/pkg/old/apis/${api}" |
| 68 | + echo "Copying ${version_dir}/${api}/*.go to ${dir_api}" |
| 69 | + mkdir -p "${dir_api}" |
| 70 | + cp "${version_dir}/${api}"/*.go "${dir_api}" |
| 71 | + echo "# k8s.io/api/${api} |
| 72 | +
|
| 73 | +Copying from release 1.${release} |
| 74 | +
|
| 75 | +Generated by ./hack/clone_old_apis.sh |
| 76 | +" > "${dir_api}/README.md" |
| 77 | + fi |
| 78 | + done |
| 79 | +} |
| 80 | + |
| 81 | +last_release=${1} |
| 82 | + |
| 83 | +for release in $(seq ${last_release} -1 9); do |
| 84 | + clone_api "${release}" "${last_release}" |
| 85 | +done |
0 commit comments