Skip to content

Commit 1a33433

Browse files
authored
Merge pull request kubernetes#88215 from kublr/fix/addon-manager
fix addon manager failing to elect leader on masters with _ in the hostname
2 parents 0fd4beb + a6739db commit 1a33433

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

cluster/addons/addon-manager/kube-addons.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,15 @@ function is_leader() {
210210
# Disabling because "${KUBECTL_OPTS}" needs to allow for expansion here
211211
KUBE_CONTROLLER_MANAGER_LEADER=$(${KUBECTL} ${KUBECTL_OPTS} -n kube-system get ep kube-controller-manager \
212212
-o go-template=$'{{index .metadata.annotations "control-plane.alpha.kubernetes.io/leader"}}' \
213-
| sed 's/^.*"holderIdentity":"\([^"]*\)".*/\1/' | awk -F'_' '{print $1}')
213+
| sed 's/^.*"holderIdentity":"\([^"]*\)".*/\1/')
214214
# If there was any problem with getting the leader election results, var will
215215
# be empty. Since it's better to have multiple addon managers than no addon
216216
# managers at all, we're going to assume that we're the leader in such case.
217217
log INFO "Leader is $KUBE_CONTROLLER_MANAGER_LEADER"
218-
[[ "$KUBE_CONTROLLER_MANAGER_LEADER" == "" ||
219-
"$HOSTNAME" == "$KUBE_CONTROLLER_MANAGER_LEADER" ]]
218+
# KUBE_CONTROLLER_MANAGER_LEADER value is in the form "${HOSTNAME}_*"
219+
# Here we verify that the value is either empty or is in the expected form for the leader
220+
KUBE_CONTROLLER_MANAGER_LEADER="${KUBE_CONTROLLER_MANAGER_LEADER##${HOSTNAME}_*}"
221+
[[ "$KUBE_CONTROLLER_MANAGER_LEADER" == "" ]]
220222
}
221223

222224
# The business logic for whether a given object should be created

0 commit comments

Comments
 (0)