Skip to content

Commit c8f0c12

Browse files
committed
Add scripts to synchronize schemes that have been removed
Signed-off-by: Shiming Zhang <[email protected]>
1 parent e0dda1c commit c8f0c12

File tree

5 files changed

+192
-0
lines changed

5 files changed

+192
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
auger
22
build
33
vendor
4+
_tmp
45

56
# IDEs
67
*.iml

Makefile

+8
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ pkg/scheme/scheme.go: ./hack/gen_scheme.sh go.mod
7373
-rm ./pkg/scheme/scheme.go
7474
./hack/gen_scheme.sh > ./pkg/scheme/scheme.go
7575

76+
pkg/old/scheme/scheme.go: ./hack/gen_old_scheme.sh pkg/old/apis
77+
-rm ./pkg/old/scheme/scheme.go
78+
./hack/gen_old_scheme.sh > ./pkg/old/scheme/scheme.go
79+
80+
pkg/old/apis: ./hack/clone_old_apis.sh go.mod
81+
-rm -rf ./pkg/old/apis/*
82+
./hack/clone_old_apis.sh $(shell cat go.mod | grep 'k8s.io/api v0.' | awk '{print $$2}' | awk -F. '{print $$2}')
83+
7684
.PHONY: generate
7785
generate: pkg/scheme/scheme.go
7886

cmd/init.go

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
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+
17+
package cmd
18+
19+
import (
20+
oldscheme "github.com/etcd-io/auger/pkg/old/scheme"
21+
"github.com/etcd-io/auger/pkg/scheme"
22+
)
23+
24+
func init() {
25+
oldscheme.AddToScheme(scheme.Scheme)
26+
}

hack/clone_old_apis.sh

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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+
REPO=https://github.com/kubernetes/api
23+
24+
function clone_or_checkout() {
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 ${REPO}/tree/${version}/${api}
74+
75+
Generated by ./hack/clone_old_apis.sh" > "${dir_api}/README.md"
76+
fi
77+
done
78+
}
79+
80+
last_release=${1}
81+
82+
for release in $(seq "${last_release}" -1 9); do
83+
clone_api "${release}" "${last_release}"
84+
done

hack/gen_old_scheme.sh

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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 find_package() {
24+
local dir=$1
25+
find "${dir}" | grep register.go | sed "s#/register.go##g" | sed "s#${dir}/##g" || :
26+
}
27+
28+
function gen() {
29+
cat <<EOF
30+
/*
31+
Copyright The Kubernetes Authors.
32+
33+
Licensed under the Apache License, Version 2.0 (the "License");
34+
you may not use this file except in compliance with the License.
35+
You may obtain a copy of the License at
36+
37+
http://www.apache.org/licenses/LICENSE-2.0
38+
39+
Unless required by applicable law or agreed to in writing, software
40+
distributed under the License is distributed on an "AS IS" BASIS,
41+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
42+
See the License for the specific language governing permissions and
43+
limitations under the License.
44+
*/
45+
46+
package scheme
47+
48+
// Don't edit this file directly. It is generated by gen_old_scheme.sh.
49+
import (
50+
EOF
51+
52+
for pkg in $(find_package "${ROOT_DIR}/pkg/old/apis"); do
53+
echo "${pkg}" | awk -F '/' '{print " "$1$2, "\"github.com/etcd-io/auger/pkg/old/apis/"$1"\/"$2"\""}'
54+
done
55+
56+
cat <<EOF
57+
"k8s.io/apimachinery/pkg/runtime"
58+
)
59+
60+
// AddToScheme adds all types of this clientset into the given scheme.
61+
func AddToScheme(scheme *runtime.Scheme) {
62+
EOF
63+
64+
for pkg in $(find_package "${ROOT_DIR}/pkg/old/apis"); do
65+
echo "${pkg}" | awk -F '/' '{print " _ = " $1$2"\.AddToScheme(scheme)"}'
66+
done
67+
68+
cat <<EOF
69+
}
70+
EOF
71+
}
72+
73+
gen

0 commit comments

Comments
 (0)