Merge pull request #1873 from xyz2277/karmada-zyx-7

do proxy setting in China mainland when installing Karmada from source
This commit is contained in:
karmada-bot 2022-06-02 13:35:52 +08:00 committed by GitHub
commit a8fd1f4596
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 19 deletions

View File

@ -28,26 +28,8 @@ KIND_LOG_FILE=${KIND_LOG_FILE:-"/tmp/karmada"}
#step0: prepare
# proxy setting in China mainland
if [[ -n ${CHINA_MAINLAND:-} ]]; then
export GOPROXY=https://goproxy.cn,direct # set domestic go proxy
# set mirror registry of k8s.gcr.io
registry_files=( # Yaml files that contain image host 'k8s.gcr.io' need to be replaced
"artifacts/deploy/karmada-etcd.yaml"
"artifacts/deploy/karmada-apiserver.yaml"
"artifacts/deploy/kube-controller-manager.yaml"
)
for registry_file in "${registry_files[@]}"; do
sed -i'' -e "s#k8s.gcr.io#registry.aliyuncs.com/google_containers#g" ${REPO_ROOT}/${registry_file}
done
# set mirror registry in the dockerfile of components of karmada
dockerfile_list=( # Dockerfile files need to be replaced
"cluster/images/Dockerfile"
"cluster/images/buildx.Dockerfile"
)
for dockerfile in "${dockerfile_list[@]}"; do
grep 'mirrors.ustc.edu.cn' ${REPO_ROOT}/${dockerfile} > /dev/null || sed -i'' -e "s#FROM alpine:3.15.1#FROM alpine:3.15.1\nRUN echo -e http://mirrors.ustc.edu.cn/alpine/v3.15/main/ > /etc/apk/repositories#" ${REPO_ROOT}/${dockerfile}
done
util::set_mirror_registry_for_china_mainland ${REPO_ROOT}
fi
# Make sure go exists and the go version is a viable version.

View File

@ -46,6 +46,12 @@ fi
# deploy karmada control plane
SCRIPT_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
source "${SCRIPT_ROOT}"/hack/util.sh
# proxy setting in China mainland
if [[ -n ${CHINA_MAINLAND:-} ]]; then
util::set_mirror_registry_for_china_mainland ${SCRIPT_ROOT}
fi
"${SCRIPT_ROOT}"/hack/deploy-karmada.sh "${HOST_CLUSTER_KUBECONFIG}" "${HOST_CLUSTER_NAME}" "remote"
kubectl config use-context karmada-apiserver --kubeconfig="${HOST_CLUSTER_KUBECONFIG}"

View File

@ -626,3 +626,30 @@ function util:create_gopath_tree() {
function util:host_platform() {
echo "$(go env GOHOSTOS)/$(go env GOHOSTARCH)"
}
# util::set_mirror_registry_for_china_mainland will do proxy setting in China mainland
# Parameters:
# - $1: the root path of repo
function util::set_mirror_registry_for_china_mainland() {
local repo_root=${1}
export GOPROXY=https://goproxy.cn,direct # set domestic go proxy
# set mirror registry of k8s.gcr.io
registry_files=( # Yaml files that contain image host 'k8s.gcr.io' need to be replaced
"artifacts/deploy/karmada-etcd.yaml"
"artifacts/deploy/karmada-apiserver.yaml"
"artifacts/deploy/kube-controller-manager.yaml"
)
for registry_file in "${registry_files[@]}"; do
sed -i'' -e "s#k8s.gcr.io#registry.aliyuncs.com/google_containers#g" ${repo_root}/${registry_file}
done
# set mirror registry in the dockerfile of components of karmada
dockerfile_list=( # Dockerfile files need to be replaced
"cluster/images/Dockerfile"
"cluster/images/buildx.Dockerfile"
)
for dockerfile in "${dockerfile_list[@]}"; do
grep 'mirrors.ustc.edu.cn' ${repo_root}/${dockerfile} > /dev/null || sed -i'' -e "s#FROM alpine:3.15.1#FROM alpine:3.15.1\nRUN echo -e http://mirrors.ustc.edu.cn/alpine/v3.15/main/ > /etc/apk/repositories#" ${repo_root}/${dockerfile}
done
}