From cfa032db744ce415017ed35e2d3c237ef1917992 Mon Sep 17 00:00:00 2001 From: Shiming Zhang Date: Sat, 11 May 2024 14:41:57 +0800 Subject: [PATCH] Add scripts to synchronize schemes that have been removed Signed-off-by: Shiming Zhang --- .gitignore | 1 + Makefile | 8 ++++ cmd/init.go | 26 +++++++++++++ hack/clone_old_apis.sh | 85 ++++++++++++++++++++++++++++++++++++++++++ hack/gen_old_scheme.sh | 73 ++++++++++++++++++++++++++++++++++++ 5 files changed, 193 insertions(+) create mode 100644 cmd/init.go create mode 100755 hack/clone_old_apis.sh create mode 100755 hack/gen_old_scheme.sh diff --git a/.gitignore b/.gitignore index ef8d69a..8dd2d47 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ auger build vendor +_tmp # IDEs *.iml diff --git a/Makefile b/Makefile index 3150de8..ab2a693 100644 --- a/Makefile +++ b/Makefile @@ -73,6 +73,14 @@ pkg/scheme/scheme.go: ./hack/gen_scheme.sh go.mod -rm ./pkg/scheme/scheme.go ./hack/gen_scheme.sh > ./pkg/scheme/scheme.go +pkg/old/scheme/scheme.go: ./hack/gen_old_scheme.sh pkg/old/apis + -rm pkg/old/scheme/scheme.go + ./hack/gen_old_scheme.sh > ./pkg/old/scheme/scheme.go + +pkg/old/apis: ./hack/clone_old_apis.sh go.mod + -rm -rf pkg/old/apis/* + ./hack/clone_old_apis.sh $(shell cat go.mod | grep 'k8s.io/api v0.' | awk '{print $$2}' | awk -F. '{print $$2}') + .PHONY: generate generate: pkg/scheme/scheme.go diff --git a/cmd/init.go b/cmd/init.go new file mode 100644 index 0000000..7a8dc64 --- /dev/null +++ b/cmd/init.go @@ -0,0 +1,26 @@ +/* +Copyright 2024 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package cmd + +import ( + "github.com/etcd-io/auger/pkg/scheme" + oldscheme "github.com/etcd-io/auger/pkg/old/scheme" +) + +func init() { + oldscheme.AddToScheme(scheme.Scheme) +} diff --git a/hack/clone_old_apis.sh b/hack/clone_old_apis.sh new file mode 100755 index 0000000..51c644d --- /dev/null +++ b/hack/clone_old_apis.sh @@ -0,0 +1,85 @@ +#!/usr/bin/env bash +# Copyright 2024 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -o errexit +set -o nounset +set -o pipefail + +DIR="$(dirname "${BASH_SOURCE[0]}")" +ROOT_DIR="$(realpath "${DIR}/..")" + +function clone_or_checkout() { + local repo=https://github.com/kubernetes/api + local version=$1 + local dest=$2 + + if [[ -d "${dest}" ]]; then + echo "Checking out ${repo}#${version} to ${dest}" + pushd "${dest}" + git fetch origin + git checkout "${version}" + popd + else + echo "Cloning ${repo}#${version} to ${dest}" + git clone --branch "${version}" --depth 1 "${repo}" "${dest}" + fi +} + +function find_package() { + local dir=$1 + find "${dir}" | grep register.go | sed "s#/register.go##g" | sed "s#${dir}/##g" || : +} + +apiset=() + +function append_api() { + local api=$1 + if [[ ! " ${apiset[@]} " =~ " ${api} " ]]; then + apiset+=("${api}") + return 0 + fi + return 1 +} + +function clone_api() { + local release=$1 + local skip=$2 + version="release-1.${release}" + version_dir="${ROOT_DIR}/_tmp/k8s-api/${version}" + clone_or_checkout "${version}" "${version_dir}" + for api in $(find_package "${version_dir}"); do + if append_api "${api}" ; then + if [[ "${release}" -eq "${skip}" ]]; then + continue + fi + dir_api="${ROOT_DIR}/pkg/old/apis/${api}" + echo "Copying ${version_dir}/${api}/*.go to ${dir_api}" + mkdir -p "${dir_api}" + cp "${version_dir}/${api}"/*.go "${dir_api}" + echo "# k8s.io/api/${api} + +Copying from release 1.${release} + +Generated by ./hack/clone_old_apis.sh +" > "${dir_api}/README.md" + fi + done +} + +last_release=${1} + +for release in $(seq ${last_release} -1 9); do + clone_api "${release}" "${last_release}" +done diff --git a/hack/gen_old_scheme.sh b/hack/gen_old_scheme.sh new file mode 100755 index 0000000..00e4127 --- /dev/null +++ b/hack/gen_old_scheme.sh @@ -0,0 +1,73 @@ +#!/usr/bin/env bash +# Copyright 2024 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -o errexit +set -o nounset +set -o pipefail + +DIR="$(dirname "${BASH_SOURCE[0]}")" +ROOT_DIR="$(realpath "${DIR}/..")" + +function find_package() { + local dir=$1 + find "${dir}" | grep register.go | sed "s#/register.go##g" | sed "s#${dir}/##g" || : +} + +function gen() { + cat <