mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
staging/copy.sh: add safety check for k8s.io/apimachinery/ in GOPATH
This commit is contained in:
parent
dd9219f304
commit
0b07908358
@ -69,7 +69,7 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
cleanup() {
|
cleanup() {
|
||||||
rm -rf "${CLIENT_REPO_TEMP}"
|
rm -rf "${CLIENT_REPO_TEMP}"
|
||||||
}
|
}
|
||||||
|
|
||||||
trap cleanup EXIT SIGINT
|
trap cleanup EXIT SIGINT
|
||||||
@ -88,8 +88,8 @@ cd "${CLIENT_REPO}"
|
|||||||
# save copies code from client-go into the temp folder to make sure we don't lose it by accident
|
# save copies code from client-go into the temp folder to make sure we don't lose it by accident
|
||||||
# TODO this is temporary until everything in certain directories is authoritative
|
# TODO this is temporary until everything in certain directories is authoritative
|
||||||
function save() {
|
function save() {
|
||||||
mkdir -p "$(dirname "${CLIENT_REPO_TEMP}/$1")"
|
mkdir -p "$(dirname "${CLIENT_REPO_TEMP}/$1")"
|
||||||
cp -r "${CLIENT_REPO}/$1"* "${CLIENT_REPO_TEMP}/"
|
cp -r "${CLIENT_REPO}/$1"* "${CLIENT_REPO_TEMP}/"
|
||||||
}
|
}
|
||||||
|
|
||||||
# save everything for which the staging directory is the source of truth
|
# save everything for which the staging directory is the source of truth
|
||||||
@ -107,7 +107,7 @@ save "OWNERS"
|
|||||||
|
|
||||||
# mkcp copies file from the main repo to the client repo, it creates the directory if it doesn't exist in the client repo.
|
# mkcp copies file from the main repo to the client repo, it creates the directory if it doesn't exist in the client repo.
|
||||||
function mkcp() {
|
function mkcp() {
|
||||||
mkdir -p "${CLIENT_REPO_TEMP}/$2" && cp -r "${MAIN_REPO}/$1" "${CLIENT_REPO_TEMP}/$2"
|
mkdir -p "${CLIENT_REPO_TEMP}/$2" && cp -r "${MAIN_REPO}/$1" "${CLIENT_REPO_TEMP}/$2"
|
||||||
}
|
}
|
||||||
|
|
||||||
# assemble all the other parts of the staging directory
|
# assemble all the other parts of the staging directory
|
||||||
@ -120,6 +120,12 @@ find "${MAIN_REPO}/pkg/version" -maxdepth 1 -type f | xargs -I{} cp {} "${CLIENT
|
|||||||
mkcp "pkg/client/clientset_generated/${CLIENTSET}" "pkg/client/clientset_generated"
|
mkcp "pkg/client/clientset_generated/${CLIENTSET}" "pkg/client/clientset_generated"
|
||||||
mkcp "pkg/client/informers/informers_generated/externalversions" "pkg/client/informers/informers_generated"
|
mkcp "pkg/client/informers/informers_generated/externalversions" "pkg/client/informers/informers_generated"
|
||||||
|
|
||||||
|
# safety check that we don't have another apimachinery in the GOPATH
|
||||||
|
if go list -f '{{.Dir}}' k8s.io/apimachinery/pkg/runtime &>/dev/null; then
|
||||||
|
echo "ERROR: unexpected k8s.io/apimachinery in GOPATH '$GOPATH'" 1>&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
pushd "${CLIENT_REPO_TEMP}" > /dev/null
|
pushd "${CLIENT_REPO_TEMP}" > /dev/null
|
||||||
echo "generating vendor/"
|
echo "generating vendor/"
|
||||||
# client-go depends on some apimachinery packages. Adding staging/ to the GOPATH
|
# client-go depends on some apimachinery packages. Adding staging/ to the GOPATH
|
||||||
@ -143,9 +149,9 @@ go run "${KUBE_ROOT}/staging/godeps-json-updater.go" --godeps-file="${CLIENT_REP
|
|||||||
|
|
||||||
echo "rewriting imports"
|
echo "rewriting imports"
|
||||||
grep -Rl "\"${MAIN_REPO_FROM_SRC}" "${CLIENT_REPO_TEMP}" | \
|
grep -Rl "\"${MAIN_REPO_FROM_SRC}" "${CLIENT_REPO_TEMP}" | \
|
||||||
grep "\.go" | \
|
grep "\.go" | \
|
||||||
grep -v "vendor/" | \
|
grep -v "vendor/" | \
|
||||||
xargs ${SED} -i "s|\"${MAIN_REPO_FROM_SRC}|\"${CLIENT_REPO_FROM_SRC}|g"
|
xargs ${SED} -i "s|\"${MAIN_REPO_FROM_SRC}|\"${CLIENT_REPO_FROM_SRC}|g"
|
||||||
|
|
||||||
echo "rewrite proto names in proto.RegisterType"
|
echo "rewrite proto names in proto.RegisterType"
|
||||||
find "${CLIENT_REPO_TEMP}" -type f -name "generated.pb.go" -print0 | xargs -0 ${SED} -i "s/k8s\.io\.kubernetes/k8s.io.client-go/g"
|
find "${CLIENT_REPO_TEMP}" -type f -name "generated.pb.go" -print0 | xargs -0 ${SED} -i "s/k8s\.io\.kubernetes/k8s.io.client-go/g"
|
||||||
@ -160,37 +166,37 @@ find "${CLIENT_REPO_TEMP}" -type f -name "*.go" -print0 | xargs -0 ${SED} -i '/^
|
|||||||
echo "rearranging directory layout"
|
echo "rearranging directory layout"
|
||||||
# $1 and $2 are relative to ${CLIENT_REPO_TEMP}
|
# $1 and $2 are relative to ${CLIENT_REPO_TEMP}
|
||||||
function mvfolder {
|
function mvfolder {
|
||||||
local src=${1%/#/}
|
local src=${1%/#/}
|
||||||
local dst=${2%/#/}
|
local dst=${2%/#/}
|
||||||
mkdir -p "${CLIENT_REPO_TEMP}/${dst}"
|
mkdir -p "${CLIENT_REPO_TEMP}/${dst}"
|
||||||
# move
|
# move
|
||||||
mv "${CLIENT_REPO_TEMP}/${src}"/* "${CLIENT_REPO_TEMP}/${dst}"
|
mv "${CLIENT_REPO_TEMP}/${src}"/* "${CLIENT_REPO_TEMP}/${dst}"
|
||||||
# rewrite package
|
# rewrite package
|
||||||
local src_package="${src##*/}"
|
local src_package="${src##*/}"
|
||||||
local dst_package="${dst##*/}"
|
local dst_package="${dst##*/}"
|
||||||
find "${CLIENT_REPO_TEMP}/${dst}" -type f -name "*.go" -print0 | xargs -0 ${SED} -i "s,package ${src_package},package ${dst_package},g"
|
find "${CLIENT_REPO_TEMP}/${dst}" -type f -name "*.go" -print0 | xargs -0 ${SED} -i "s,package ${src_package},package ${dst_package},g"
|
||||||
|
|
||||||
{ grep -Rl "\"${CLIENT_REPO_FROM_SRC}/${src}" "${CLIENT_REPO_TEMP}" || true ; } | while read -r target ; do
|
{ grep -Rl "\"${CLIENT_REPO_FROM_SRC}/${src}" "${CLIENT_REPO_TEMP}" || true ; } | while read -r target ; do
|
||||||
# rewrite imports
|
# rewrite imports
|
||||||
# the first rule is to convert import lines like `restclient "k8s.io/client-go/pkg/client/restclient"`,
|
# the first rule is to convert import lines like `restclient "k8s.io/client-go/pkg/client/restclient"`,
|
||||||
# where a package alias is the same the package name.
|
# where a package alias is the same the package name.
|
||||||
${SED} -i "s,\<${src_package} \"${CLIENT_REPO_FROM_SRC}/${src},${dst_package} \"${CLIENT_REPO_FROM_SRC}/${dst},g" "${target}"
|
${SED} -i "s,\<${src_package} \"${CLIENT_REPO_FROM_SRC}/${src},${dst_package} \"${CLIENT_REPO_FROM_SRC}/${dst},g" "${target}"
|
||||||
${SED} -i "s,\"${CLIENT_REPO_FROM_SRC}/${src},\"${CLIENT_REPO_FROM_SRC}/${dst},g" "${target}"
|
${SED} -i "s,\"${CLIENT_REPO_FROM_SRC}/${src},\"${CLIENT_REPO_FROM_SRC}/${dst},g" "${target}"
|
||||||
# rewrite import invocation
|
# rewrite import invocation
|
||||||
if [ "${src_package}" != "${dst_package}" ]; then
|
if [ "${src_package}" != "${dst_package}" ]; then
|
||||||
${SED} -i "s,\<${src_package}\.\([a-zA-Z]\),${dst_package}\.\1,g" "${target}"
|
${SED} -i "s,\<${src_package}\.\([a-zA-Z]\),${dst_package}\.\1,g" "${target}"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
mvfolder "pkg/client/clientset_generated/${CLIENTSET}" kubernetes
|
mvfolder "pkg/client/clientset_generated/${CLIENTSET}" kubernetes
|
||||||
mvfolder "pkg/client/informers/informers_generated/externalversions" informers
|
mvfolder "pkg/client/informers/informers_generated/externalversions" informers
|
||||||
mvfolder "pkg/client/listers" listers
|
mvfolder "pkg/client/listers" listers
|
||||||
if [ "$(find "${CLIENT_REPO_TEMP}"/pkg/client -type f -name "*.go")" ]; then
|
if [ "$(find "${CLIENT_REPO_TEMP}"/pkg/client -type f -name "*.go")" ]; then
|
||||||
echo "${CLIENT_REPO_TEMP}/pkg/client is expected to be empty"
|
echo "${CLIENT_REPO_TEMP}/pkg/client is expected to be empty"
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
rm -r "${CLIENT_REPO_TEMP}"/pkg/client
|
rm -r "${CLIENT_REPO_TEMP}"/pkg/client
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "running gofmt"
|
echo "running gofmt"
|
||||||
@ -198,12 +204,12 @@ find "${CLIENT_REPO_TEMP}" -type f -name "*.go" -print0 | xargs -0 gofmt -w
|
|||||||
|
|
||||||
echo "remove black listed files"
|
echo "remove black listed files"
|
||||||
find "${CLIENT_REPO_TEMP}" -type f \( \
|
find "${CLIENT_REPO_TEMP}" -type f \( \
|
||||||
-name "*BUILD" -o \
|
-name "*BUILD" -o \
|
||||||
-name "*.json" -not -name "Godeps.json" -o \
|
-name "*.json" -not -name "Godeps.json" -o \
|
||||||
-name "*.yaml" -o \
|
-name "*.yaml" -o \
|
||||||
-name "*.yml" -o \
|
-name "*.yml" -o \
|
||||||
-name "*.sh" \
|
-name "*.sh" \
|
||||||
\) -delete
|
\) -delete
|
||||||
|
|
||||||
echo "remove cyclical godep"
|
echo "remove cyclical godep"
|
||||||
rm -rf "${CLIENT_REPO_TEMP}/_vendor/k8s.io/client-go"
|
rm -rf "${CLIENT_REPO_TEMP}/_vendor/k8s.io/client-go"
|
||||||
@ -232,8 +238,8 @@ fi
|
|||||||
# clean the ${CLIENT_REPO}
|
# clean the ${CLIENT_REPO}
|
||||||
echo "move to the client repo"
|
echo "move to the client repo"
|
||||||
if [ "${DRY_RUN}" = false ]; then
|
if [ "${DRY_RUN}" = false ]; then
|
||||||
ls "${CLIENT_REPO}" | { grep -v '_tmp' || true; } | xargs rm -rf
|
ls "${CLIENT_REPO}" | { grep -v '_tmp' || true; } | xargs rm -rf
|
||||||
mv "${CLIENT_REPO_TEMP}"/* "${CLIENT_REPO}"
|
mv "${CLIENT_REPO_TEMP}"/* "${CLIENT_REPO}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cleanup
|
cleanup
|
||||||
|
Loading…
Reference in New Issue
Block a user