mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 15:25:57 +00:00
add coredns migration support to upgrade.sh
This commit is contained in:
parent
f2dd24820a
commit
e57b867957
@ -439,6 +439,85 @@ function do-node-upgrade() {
|
||||
echo "== Finished upgrading nodes to ${KUBE_VERSION}. ==" >&2
|
||||
}
|
||||
|
||||
|
||||
function update-coredns-config() {
|
||||
# Get the current CoreDNS version
|
||||
local -r coredns_addon_path="/etc/kubernetes/addons/0-dns/coredns"
|
||||
local -r tmpdir=/tmp
|
||||
local -r download_dir=$(mktemp --tmpdir=${tmpdir} -d coredns-migration.XXXXXXXXXX) || exit 1
|
||||
|
||||
# Get the new installed CoreDNS version
|
||||
echo "Waiting for CoreDNS to update"
|
||||
until [[ $(${KUBE_ROOT}/cluster/kubectl.sh -n kube-system get deployment coredns -o=jsonpath='{$.metadata.resourceVersion}') -ne ${COREDNS_DEPLOY_RESOURCE_VERSION} ]]; do
|
||||
sleep 1
|
||||
done
|
||||
echo "Fetching the latest installed CoreDNS version"
|
||||
NEW_COREDNS_VERSION=$(${KUBE_ROOT}/cluster/kubectl.sh -n kube-system get deployment coredns -o=jsonpath='{$.spec.template.spec.containers[:1].image}' | cut -d ":" -f 2)
|
||||
|
||||
case "$(uname -m)" in
|
||||
x86_64*)
|
||||
host_arch=amd64
|
||||
;;
|
||||
i?86_64*)
|
||||
host_arch=amd64
|
||||
;;
|
||||
amd64*)
|
||||
host_arch=amd64
|
||||
;;
|
||||
aarch64*)
|
||||
host_arch=arm64
|
||||
;;
|
||||
arm64*)
|
||||
host_arch=arm64
|
||||
;;
|
||||
arm*)
|
||||
host_arch=arm
|
||||
;;
|
||||
i?86*)
|
||||
host_arch=x86
|
||||
;;
|
||||
s390x*)
|
||||
host_arch=s390x
|
||||
;;
|
||||
ppc64le*)
|
||||
host_arch=ppc64le
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported host arch. Must be x86_64, 386, arm, arm64, s390x or ppc64le." >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
# Download the CoreDNS migration tool
|
||||
echo "== Downloading the CoreDNS migration tool =="
|
||||
wget -P ${download_dir} "https://github.com/coredns/corefile-migration/releases/download/v1.0.2/corefile-tool-${host_arch}" >/dev/null 2>&1
|
||||
chmod +x ${download_dir}/corefile-tool-${host_arch}
|
||||
|
||||
# Migrate the CoreDNS ConfigMap depending on whether it is being downgraded or upgraded.
|
||||
${KUBE_ROOT}/cluster/kubectl.sh -n kube-system get cm coredns -o jsonpath='{.data.Corefile}' > ${download_dir}/Corefile-old
|
||||
|
||||
if test "$(printf '%s\n' ${CURRENT_COREDNS_VERSION} ${NEW_COREDNS_VERSION} | sort -V | head -n 1)" != ${NEW_COREDNS_VERSION}; then
|
||||
echo "== Upgrading the CoreDNS ConfigMap =="
|
||||
./corefile-tool-${host_arch} migrate --from ${CURRENT_COREDNS_VERSION} --to ${NEW_COREDNS_VERSION} --corefile ${download_dir}/Corefile-old > ${download_dir}/Corefile
|
||||
${KUBE_ROOT}/cluster/kubectl.sh -n kube-system create configmap coredns --from-file ${download_dir}/Corefile -o yaml --dry-run | ${KUBE_ROOT}/cluster/kubectl.sh apply -f -
|
||||
else
|
||||
# In case of a downgrade, a custom CoreDNS Corefile will be overwritten by a default Corefile. In that case,
|
||||
# the user will need to manually modify the resulting (default) Corefile after the downgrade is complete.
|
||||
echo "== Applying the latest default CoreDNS configuration =="
|
||||
gcloud compute --project ${PROJECT} scp --zone ${ZONE} ${MASTER_NAME}:${coredns_addon_path}/coredns.yaml ${download_dir}/coredns-manifest.yaml > /dev/null
|
||||
${KUBE_ROOT}/cluster/kubectl.sh apply -f ${download_dir}/coredns-manifest.yaml
|
||||
fi
|
||||
|
||||
# clean up
|
||||
rm -rf ${download_dir}
|
||||
|
||||
echo "== The CoreDNS Config has been updated =="
|
||||
}
|
||||
|
||||
echo "Fetching the previously installed CoreDNS version"
|
||||
CURRENT_COREDNS_VERSION=$(${KUBE_ROOT}/cluster/kubectl.sh -n kube-system get deployment coredns -o=jsonpath='{$.spec.template.spec.containers[:1].image}' | cut -d ":" -f 2)
|
||||
COREDNS_DEPLOY_RESOURCE_VERSION=$(${KUBE_ROOT}/cluster/kubectl.sh -n kube-system get deployment coredns -o=jsonpath='{$.metadata.resourceVersion}')
|
||||
|
||||
master_upgrade=true
|
||||
node_upgrade=true
|
||||
node_prereqs=false
|
||||
@ -580,6 +659,10 @@ if [[ "${node_upgrade}" == "true" ]]; then
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ "${CLUSTER_DNS_CORE_DNS:-}" == "true" ]]; then
|
||||
update-coredns-config
|
||||
fi
|
||||
|
||||
echo "== Validating cluster post-upgrade =="
|
||||
"${KUBE_ROOT}/cluster/validate-cluster.sh"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user