mirror of
				https://github.com/k3s-io/kubernetes.git
				synced 2025-10-31 13:50:01 +00:00 
			
		
		
		
	fix addon manager failing to elect leader on masters with _ in the hostname (issue #88214)
This commit is contained in:
		| @@ -210,13 +210,15 @@ function is_leader() { | |||||||
|   # Disabling because "${KUBECTL_OPTS}" needs to allow for expansion here |   # Disabling because "${KUBECTL_OPTS}" needs to allow for expansion here | ||||||
|   KUBE_CONTROLLER_MANAGER_LEADER=$(${KUBECTL} ${KUBECTL_OPTS} -n kube-system get ep kube-controller-manager \ |   KUBE_CONTROLLER_MANAGER_LEADER=$(${KUBECTL} ${KUBECTL_OPTS} -n kube-system get ep kube-controller-manager \ | ||||||
|     -o go-template=$'{{index .metadata.annotations "control-plane.alpha.kubernetes.io/leader"}}' \ |     -o go-template=$'{{index .metadata.annotations "control-plane.alpha.kubernetes.io/leader"}}' \ | ||||||
|     | sed 's/^.*"holderIdentity":"\([^"]*\)".*/\1/' | awk -F'_' '{print $1}') |     | sed 's/^.*"holderIdentity":"\([^"]*\)".*/\1/') | ||||||
|   # If there was any problem with getting the leader election results, var will |   # If there was any problem with getting the leader election results, var will | ||||||
|   # be empty. Since it's better to have multiple addon managers than no addon |   # be empty. Since it's better to have multiple addon managers than no addon | ||||||
|   # managers at all, we're going to assume that we're the leader in such case. |   # managers at all, we're going to assume that we're the leader in such case. | ||||||
|   log INFO "Leader is $KUBE_CONTROLLER_MANAGER_LEADER" |   log INFO "Leader is $KUBE_CONTROLLER_MANAGER_LEADER" | ||||||
|   [[ "$KUBE_CONTROLLER_MANAGER_LEADER" == "" || |   # KUBE_CONTROLLER_MANAGER_LEADER value is in the form "${HOSTNAME}_*" | ||||||
|      "$HOSTNAME" == "$KUBE_CONTROLLER_MANAGER_LEADER" ]] |   # Here we verify that the value is either empty or is in the expected form for the leader | ||||||
|  |   KUBE_CONTROLLER_MANAGER_LEADER="${KUBE_CONTROLLER_MANAGER_LEADER##${HOSTNAME}_*}" | ||||||
|  |   [[ "$KUBE_CONTROLLER_MANAGER_LEADER" == "" ]] | ||||||
| } | } | ||||||
|  |  | ||||||
| # The business logic for whether a given object should be created | # The business logic for whether a given object should be created | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user