Merge pull request #32840 from Random-Liu/keep-os-distro-during-upgrade
Node Upgrade: Change the upgrade script to keep os distro during upgrade.
This commit is contained in:
		@@ -33,11 +33,12 @@ source "${KUBE_ROOT}/cluster/kube-util.sh"
 | 
				
			|||||||
function usage() {
 | 
					function usage() {
 | 
				
			||||||
  echo "!!! EXPERIMENTAL !!!"
 | 
					  echo "!!! EXPERIMENTAL !!!"
 | 
				
			||||||
  echo ""
 | 
					  echo ""
 | 
				
			||||||
  echo "${0} [-M|-N|-P] -l | <version number or publication>"
 | 
					  echo "${0} [-M|-N|-P] -l -o | <version number or publication>"
 | 
				
			||||||
  echo "  Upgrades master and nodes by default"
 | 
					  echo "  Upgrades master and nodes by default"
 | 
				
			||||||
  echo "  -M:  Upgrade master only"
 | 
					  echo "  -M:  Upgrade master only"
 | 
				
			||||||
  echo "  -N:  Upgrade nodes only"
 | 
					  echo "  -N:  Upgrade nodes only"
 | 
				
			||||||
  echo "  -P:  Node upgrade prerequisites only (create a new instance template)"
 | 
					  echo "  -P:  Node upgrade prerequisites only (create a new instance template)"
 | 
				
			||||||
 | 
					  echo "  -o:  Use os distro sepcified in KUBE_NODE_OS_DISTRIBUTION for new nodes"
 | 
				
			||||||
  echo "  -l:  Use local(dev) binaries"
 | 
					  echo "  -l:  Use local(dev) binaries"
 | 
				
			||||||
  echo ""
 | 
					  echo ""
 | 
				
			||||||
  echo '  Version number or publication is either a proper version number'
 | 
					  echo '  Version number or publication is either a proper version number'
 | 
				
			||||||
@@ -134,6 +135,20 @@ function get-node-env() {
 | 
				
			|||||||
      'http://metadata/computeMetadata/v1/instance/attributes/kube-env'" 2>/dev/null
 | 
					      'http://metadata/computeMetadata/v1/instance/attributes/kube-env'" 2>/dev/null
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Read os distro information from /os/release on node.
 | 
				
			||||||
 | 
					# $1: The name of node
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# Assumed vars:
 | 
				
			||||||
 | 
					#   PROJECT
 | 
				
			||||||
 | 
					#   ZONE
 | 
				
			||||||
 | 
					function get-node-os() {
 | 
				
			||||||
 | 
					  gcloud compute ssh "$1" \
 | 
				
			||||||
 | 
					    --project "${PROJECT}" \
 | 
				
			||||||
 | 
					    --zone "${ZONE}" \
 | 
				
			||||||
 | 
					    --command \
 | 
				
			||||||
 | 
					    "cat /etc/os-release | grep \"^ID=.*\" | cut -c 4-"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Assumed vars:
 | 
					# Assumed vars:
 | 
				
			||||||
#   KUBE_VERSION
 | 
					#   KUBE_VERSION
 | 
				
			||||||
#   NODE_SCOPES
 | 
					#   NODE_SCOPES
 | 
				
			||||||
@@ -199,6 +214,13 @@ function prepare-node-upgrade() {
 | 
				
			|||||||
  #                 compatible way?
 | 
					  #                 compatible way?
 | 
				
			||||||
  write-node-env
 | 
					  write-node-env
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if [[ "${env_os_distro}" == "false" ]]; then
 | 
				
			||||||
 | 
					    NODE_OS_DISTRIBUTION=$(get-node-os "${NODE_NAMES[0]}")
 | 
				
			||||||
 | 
					    source "${KUBE_ROOT}/cluster/gce/${NODE_OS_DISTRIBUTION}/node-helper.sh"
 | 
				
			||||||
 | 
					    # Reset the node image based on current os distro
 | 
				
			||||||
 | 
					    set-node-image
 | 
				
			||||||
 | 
					  fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  # TODO(zmerlynn): Get configure-vm script from ${version}. (Must plumb this
 | 
					  # TODO(zmerlynn): Get configure-vm script from ${version}. (Must plumb this
 | 
				
			||||||
  #                 through all create-node-instance-template implementations).
 | 
					  #                 through all create-node-instance-template implementations).
 | 
				
			||||||
  local template_name=$(get-template-name-from-version ${SANITIZED_VERSION})
 | 
					  local template_name=$(get-template-name-from-version ${SANITIZED_VERSION})
 | 
				
			||||||
@@ -271,6 +293,7 @@ master_upgrade=true
 | 
				
			|||||||
node_upgrade=true
 | 
					node_upgrade=true
 | 
				
			||||||
node_prereqs=false
 | 
					node_prereqs=false
 | 
				
			||||||
local_binaries=false
 | 
					local_binaries=false
 | 
				
			||||||
 | 
					env_os_distro=false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
while getopts ":MNPlh" opt; do
 | 
					while getopts ":MNPlh" opt; do
 | 
				
			||||||
  case ${opt} in
 | 
					  case ${opt} in
 | 
				
			||||||
@@ -286,6 +309,9 @@ while getopts ":MNPlh" opt; do
 | 
				
			|||||||
    l)
 | 
					    l)
 | 
				
			||||||
      local_binaries=true
 | 
					      local_binaries=true
 | 
				
			||||||
      ;;
 | 
					      ;;
 | 
				
			||||||
 | 
					    o)
 | 
				
			||||||
 | 
					      env_os_distro=true
 | 
				
			||||||
 | 
					      ;;
 | 
				
			||||||
    h)
 | 
					    h)
 | 
				
			||||||
      usage
 | 
					      usage
 | 
				
			||||||
      exit 0
 | 
					      exit 0
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -47,15 +47,21 @@ elif [[ "${MASTER_OS_DISTRIBUTION}" == "debian" ]]; then
 | 
				
			|||||||
  MASTER_IMAGE_PROJECT=${KUBE_GCE_MASTER_PROJECT:-google-containers}
 | 
					  MASTER_IMAGE_PROJECT=${KUBE_GCE_MASTER_PROJECT:-google-containers}
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if [[ "${NODE_OS_DISTRIBUTION}" == "gci" ]]; then
 | 
					# Sets node image based on the specified os distro. Currently this function only
 | 
				
			||||||
  # If the node image is not set, we use the latest GCI image.
 | 
					# supports gci and debian.
 | 
				
			||||||
  # Otherwise, we respect whatever is set by the user.
 | 
					function set-node-image() {
 | 
				
			||||||
  NODE_IMAGE=${KUBE_GCE_NODE_IMAGE:-${GCI_VERSION}}
 | 
					  if [[ "${NODE_OS_DISTRIBUTION}" == "gci" ]]; then
 | 
				
			||||||
  NODE_IMAGE_PROJECT=${KUBE_GCE_NODE_PROJECT:-google-containers}
 | 
					    # If the node image is not set, we use the latest GCI image.
 | 
				
			||||||
elif [[ "${NODE_OS_DISTRIBUTION}" == "debian" ]]; then
 | 
					    # Otherwise, we respect whatever is set by the user.
 | 
				
			||||||
  NODE_IMAGE=${KUBE_GCE_NODE_IMAGE:-${CVM_VERSION}}
 | 
					    NODE_IMAGE=${KUBE_GCE_NODE_IMAGE:-${GCI_VERSION}}
 | 
				
			||||||
  NODE_IMAGE_PROJECT=${KUBE_GCE_NODE_PROJECT:-google-containers}
 | 
					    NODE_IMAGE_PROJECT=${KUBE_GCE_NODE_PROJECT:-google-containers}
 | 
				
			||||||
fi
 | 
					  elif [[ "${NODE_OS_DISTRIBUTION}" == "debian" ]]; then
 | 
				
			||||||
 | 
					    NODE_IMAGE=${KUBE_GCE_NODE_IMAGE:-${CVM_VERSION}}
 | 
				
			||||||
 | 
					    NODE_IMAGE_PROJECT=${KUBE_GCE_NODE_PROJECT:-google-containers}
 | 
				
			||||||
 | 
					  fi
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					set-node-image
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Verfiy cluster autoscaler configuration.
 | 
					# Verfiy cluster autoscaler configuration.
 | 
				
			||||||
if [[ "${ENABLE_CLUSTER_AUTOSCALER}" == "true" ]]; then
 | 
					if [[ "${ENABLE_CLUSTER_AUTOSCALER}" == "true" ]]; then
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user