mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-07-17 20:00:07 +00:00
cleanup unused rsync utilities
This commit is contained in:
119
build/common.sh
119
build/common.sh
@@ -88,14 +88,6 @@ readonly REMOTE_OUTPUT_SUBPATH="${REMOTE_OUTPUT_ROOT}/dockerized"
|
||||
readonly REMOTE_OUTPUT_BINPATH="${REMOTE_OUTPUT_SUBPATH}/bin"
|
||||
readonly REMOTE_OUTPUT_GOPATH="${REMOTE_OUTPUT_SUBPATH}/go"
|
||||
|
||||
# This is the port on the workstation host to expose RSYNC on. Set this if you
|
||||
# are doing something fancy with ssh tunneling.
|
||||
readonly KUBE_RSYNC_PORT="${KUBE_RSYNC_PORT:-}"
|
||||
|
||||
# This is the port that rsync is running on *inside* the container. This may be
|
||||
# mapped to KUBE_RSYNC_PORT via docker networking.
|
||||
readonly KUBE_CONTAINER_RSYNC_PORT=8730
|
||||
|
||||
# These are the default versions (image tags) for their respective base images.
|
||||
readonly __default_distroless_iptables_version=v0.8.2
|
||||
readonly __default_go_runner_version=v2.4.0-go1.25.1-bookworm.0
|
||||
@@ -517,114 +509,3 @@ function kube::build::run_build_command_ex() {
|
||||
kube::build::destroy_container "${container_name}"
|
||||
fi
|
||||
}
|
||||
|
||||
function kube::build::rsync_probe {
|
||||
# Wait until rsync is up and running.
|
||||
local tries=20
|
||||
while (( tries > 0 )) ; do
|
||||
if rsync "rsync://k8s@${1}:${2}/" \
|
||||
--password-file="${LOCAL_OUTPUT_BUILD_CONTEXT}/rsyncd.password" \
|
||||
&> /dev/null ; then
|
||||
return 0
|
||||
fi
|
||||
tries=$(( tries - 1))
|
||||
sleep 0.1
|
||||
done
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
# Start up the rsync container in the background. This should be explicitly
|
||||
# stopped with kube::build::stop_rsyncd_container.
|
||||
#
|
||||
# This will set the global var KUBE_RSYNC_ADDR to the effective port that the
|
||||
# rsync daemon can be reached out.
|
||||
function kube::build::start_rsyncd_container() {
|
||||
IPTOOL=ifconfig
|
||||
if kube::build::has_ip ; then
|
||||
IPTOOL="ip address"
|
||||
fi
|
||||
kube::build::stop_rsyncd_container
|
||||
V=3 kube::log::status "Starting rsyncd container"
|
||||
kube::build::run_build_command_ex \
|
||||
"${KUBE_RSYNC_CONTAINER_NAME}" -p 127.0.0.1:"${KUBE_RSYNC_PORT}":"${KUBE_CONTAINER_RSYNC_PORT}" -d \
|
||||
-e ALLOW_HOST="$(${IPTOOL} | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1' | tr '\n' ' ')" \
|
||||
-- /rsyncd.sh >/dev/null
|
||||
|
||||
local mapped_port
|
||||
if ! mapped_port=$("${DOCKER[@]}" port "${KUBE_RSYNC_CONTAINER_NAME}" "${KUBE_CONTAINER_RSYNC_PORT}" 2> /dev/null | cut -d: -f 2) ; then
|
||||
kube::log::error "Could not get effective rsync port"
|
||||
return 1
|
||||
fi
|
||||
|
||||
local container_ip
|
||||
container_ip=$("${DOCKER[@]}" inspect --format '{{ .NetworkSettings.IPAddress }}' "${KUBE_RSYNC_CONTAINER_NAME}")
|
||||
|
||||
# Sometimes we can reach rsync through localhost and a NAT'd port. Other
|
||||
# times (when we are running in another docker container on the Jenkins
|
||||
# machines) we have to talk directly to the container IP. There is no one
|
||||
# strategy that works in all cases so we test to figure out which situation we
|
||||
# are in.
|
||||
if kube::build::rsync_probe 127.0.0.1 "${mapped_port}"; then
|
||||
KUBE_RSYNC_ADDR="127.0.0.1:${mapped_port}"
|
||||
return 0
|
||||
elif kube::build::rsync_probe "${container_ip}" "${KUBE_CONTAINER_RSYNC_PORT}"; then
|
||||
KUBE_RSYNC_ADDR="${container_ip}:${KUBE_CONTAINER_RSYNC_PORT}"
|
||||
return 0
|
||||
fi
|
||||
|
||||
kube::log::error "Could not connect to rsync container."
|
||||
return 1
|
||||
}
|
||||
|
||||
function kube::build::stop_rsyncd_container() {
|
||||
V=3 kube::log::status "Stopping any currently running rsyncd container"
|
||||
unset KUBE_RSYNC_ADDR
|
||||
kube::build::destroy_container "${KUBE_RSYNC_CONTAINER_NAME}"
|
||||
}
|
||||
|
||||
function kube::build::rsync {
|
||||
local -a rsync_opts=(
|
||||
--archive
|
||||
"--password-file=${LOCAL_OUTPUT_BUILD_CONTEXT}/rsyncd.password"
|
||||
)
|
||||
if (( KUBE_VERBOSE >= 6 )); then
|
||||
rsync_opts+=("-iv")
|
||||
fi
|
||||
if (( KUBE_RSYNC_COMPRESS > 0 )); then
|
||||
rsync_opts+=("--compress-level=${KUBE_RSYNC_COMPRESS}")
|
||||
fi
|
||||
V=3 kube::log::status "Running rsync"
|
||||
rsync "${rsync_opts[@]}" "$@"
|
||||
}
|
||||
|
||||
# This will launch rsyncd in a container and then sync the source tree to the
|
||||
# container over the local network.
|
||||
function kube::build::sync_to_container() {
|
||||
# TODO: eliminate calls to this
|
||||
# for now making sure it doesn't run, so we can just use the volume mount
|
||||
return
|
||||
kube::log::status "Syncing sources to container"
|
||||
|
||||
kube::build::start_rsyncd_container
|
||||
|
||||
# rsync filters are a bit confusing. Here we are syncing everything except
|
||||
# output only directories and things that are not necessary like the git
|
||||
# directory and generated files. The '- /' filter prevents rsync
|
||||
# from trying to set the uid/gid/perms on the root of the sync tree.
|
||||
# As an exception, we need to sync generated files in staging/, because
|
||||
# they will not be re-generated by 'make'. Note that the 'H' filtered files
|
||||
# are hidden from rsync so they will be deleted in the target container if
|
||||
# they exist. This will allow them to be re-created in the container if
|
||||
# necessary.
|
||||
# PLEASE DO NOT ADD TO THIS
|
||||
# https://github.com/kubernetes/kubernetes/issues/112862
|
||||
kube::build::rsync \
|
||||
--delete \
|
||||
--filter='- /_tmp/' \
|
||||
--filter='- /_output/' \
|
||||
--filter='- /' \
|
||||
"${KUBE_ROOT}/" "rsync://k8s@${KUBE_RSYNC_ADDR}/k8s/"
|
||||
|
||||
kube::build::stop_rsyncd_container
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user