-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🐛 bootstrap: fix useExperimentalRetryJoin for kubernetes v1.31 #10983
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
#!/bin/bash | ||
# Copyright 2020 The Kubernetes Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# Log an error and exit. | ||
# Args: | ||
# $1 Message to log with the error | ||
# $2 The error code to return | ||
log::error_exit() { | ||
local message="${1}" | ||
local code="${2}" | ||
|
||
log::error "${message}" | ||
# {{ if .ControlPlane }} | ||
log::info "Removing member from cluster status" | ||
kubeadm reset -f update-cluster-status || true | ||
log::info "Removing etcd member" | ||
kubeadm reset -f remove-etcd-member || true | ||
# {{ end }} | ||
log::info "Resetting kubeadm" | ||
kubeadm reset -f || true | ||
log::error "cluster.x-k8s.io kubeadm bootstrap script $0 exiting with status ${code}" | ||
exit "${code}" | ||
} | ||
|
||
log::success_exit() { | ||
log::info "cluster.x-k8s.io kubeadm bootstrap script $0 finished" | ||
exit 0 | ||
} | ||
|
||
# Log an error but keep going. | ||
log::error() { | ||
local message="${1}" | ||
timestamp=$(date --iso-8601=seconds) | ||
echo "!!! [${timestamp}] ${1}" >&2 | ||
shift | ||
for message; do | ||
echo " ${message}" >&2 | ||
done | ||
} | ||
|
||
# Print a status line. Formatted to show up in a stream of output. | ||
log::info() { | ||
timestamp=$(date --iso-8601=seconds) | ||
echo "+++ [${timestamp}] ${1}" | ||
shift | ||
for message; do | ||
echo " ${message}" | ||
done | ||
} | ||
|
||
check_kubeadm_command() { | ||
local command="${1}" | ||
local code="${2}" | ||
case ${code} in | ||
"0") | ||
log::info "kubeadm reported successful execution for ${command}" | ||
;; | ||
"1") | ||
log::error "kubeadm reported failed action(s) for ${command}" | ||
;; | ||
"2") | ||
log::error "kubeadm reported preflight check error during ${command}" | ||
;; | ||
"3") | ||
log::error_exit "kubeadm reported validation error for ${command}" "${code}" | ||
;; | ||
*) | ||
log::error "kubeadm reported unknown error ${code} for ${command}" | ||
;; | ||
esac | ||
} | ||
|
||
function retry-command() { | ||
n=0 | ||
local kubeadm_return | ||
until [ $n -ge 5 ]; do | ||
log::info "running '$*'" | ||
# shellcheck disable=SC1083 | ||
"$@" --config=/run/kubeadm/kubeadm-join-config.yaml {{.KubeadmVerbosity}} | ||
kubeadm_return=$? | ||
check_kubeadm_command "'$*'" "${kubeadm_return}" | ||
if [ ${kubeadm_return} -eq 0 ]; then | ||
break | ||
fi | ||
# We allow preflight errors to pass | ||
if [ ${kubeadm_return} -eq 2 ]; then | ||
break | ||
fi | ||
n=$((n + 1)) | ||
sleep 15 | ||
done | ||
if [ ${kubeadm_return} -ne 0 ]; then | ||
log::error_exit "too many errors, exiting" "${kubeadm_return}" | ||
fi | ||
} | ||
|
||
# {{ if .ControlPlane }} | ||
function try-or-die-command() { | ||
local kubeadm_return | ||
log::info "running '$*'" | ||
# shellcheck disable=SC1083 | ||
"$@" --config=/run/kubeadm/kubeadm-join-config.yaml {{.KubeadmVerbosity}} | ||
kubeadm_return=$? | ||
check_kubeadm_command "'$*'" "${kubeadm_return}" | ||
if [ ${kubeadm_return} -ne 0 ]; then | ||
log::error_exit "fatal error, exiting" "${kubeadm_return}" | ||
fi | ||
} | ||
# {{ end }} | ||
|
||
retry-command kubeadm join phase preflight --ignore-preflight-errors=DirAvailable--etc-kubernetes-manifests | ||
# {{ if .ControlPlane }} | ||
retry-command kubeadm join phase control-plane-prepare download-certs | ||
retry-command kubeadm join phase control-plane-prepare certs | ||
retry-command kubeadm join phase control-plane-prepare kubeconfig | ||
retry-command kubeadm join phase control-plane-prepare control-plane | ||
# {{ end }} | ||
retry-command kubeadm join phase kubelet-start | ||
# {{ if .ControlPlane }} | ||
try-or-die-command kubeadm join phase control-plane-join etcd | ||
retry-command kubeadm join phase control-plane-join update-status | ||
retry-command kubeadm join phase control-plane-join mark-control-plane | ||
# {{ end }} | ||
|
||
log::success_exit |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#!/bin/bash | ||
# Copyright 2020 The Kubernetes Authors. | ||
# Copyright 2024 The Kubernetes Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
|
@@ -128,10 +128,8 @@ retry-command kubeadm join phase control-plane-prepare kubeconfig | |
retry-command kubeadm join phase control-plane-prepare control-plane | ||
# {{ end }} | ||
retry-command kubeadm join phase kubelet-start | ||
# {{ if .ControlPlane }} | ||
try-or-die-command kubeadm join phase control-plane-join etcd | ||
retry-command kubeadm join phase control-plane-join update-status | ||
retry-command kubeadm join phase control-plane-join mark-control-plane | ||
# {{ end }} | ||
|
||
# Run kubeadm join and skip all already executed phases. | ||
chrischdi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
try-or-die-command kubeadm join --skip-phases preflight,control-plane-prepare,kubelet-start | ||
Comment on lines
+131
to
+133
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have two options here: Current implementation Just run The alternative would be:
I think the advantages of the current implementation are better then doing the alternative here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think given all recent versions of kubeadm in support by CAPI have integrated retries. breaking down the join in phases and/or retrying any of them is pointless. so i'm +1 to make experimental-retry-join be just a regular single kubeadm cmd join too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. |
||
|
||
log::success_exit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2024
(because it's a new file, even if we are just copying code to it)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
github is misdisplaying it a bit. This is the old file, and just the same :-)
But thanks for the pointer, have to bump the year on the other file!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm, not sure how so.
seems like bootstrap/kubeadm/internal/cloudinit/kubeadm-bootstrap-script-pre-k8s-1-31.sh is a new file that has the old contents. it should be with the 2024 year. old file can have the new changes but be with the old year.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's basically a
git mv bootstrap/kubeadm/internal/cloudinit/kubeadm-bootstrap-script.sh bootstrap/kubeadm/internal/cloudinit/kubeadm-bootstrap-script-pre-k8s-1-31.sh
🤔There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, it ends up as a new file in the tree, so the correct action is to apply 2024.
i don't think the license police will mind, so up to you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a license police? :)