Fix data-migration failure when upgrading N+1 node
When upgrading to N+1 node, cluster IP address from admin.conf needs to be replaced with the floating management IP address. This is to prevent failure in data migration when kubernetes api accesses dc-adminep-root-ca-certificate. The update of cluster IP address is temporary and done on a copy of the original /etc/kubernetes/admin.conf. This commit applies changes from the N side. Closes-Bug: 1883763 Change-Id: Ibc2dbbab5016d9c58248ebb5b0fb52299e99705c Signed-off-by: Carmen Rata <carmen.rata@windriver.com>
This commit is contained in:
parent
82f0efcc95
commit
002a818b19
|
@ -12,6 +12,7 @@ import glob
|
|||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import yaml
|
||||
|
||||
import tsconfig.tsconfig as tsc
|
||||
|
||||
|
@ -91,7 +92,7 @@ def export_vim(dest_dir):
|
|||
raise
|
||||
|
||||
|
||||
def prepare_upgrade(from_load, to_load, i_system):
|
||||
def prepare_upgrade(from_load, to_load, i_system, mgmt_address):
|
||||
""" Executed on the release N side to prepare for an upgrade. """
|
||||
devnull = open(os.devnull, 'w')
|
||||
|
||||
|
@ -162,6 +163,27 @@ def prepare_upgrade(from_load, to_load, i_system):
|
|||
utils.KUBERNETES_ADMIN_CONF_FILE))
|
||||
raise
|
||||
|
||||
# Update admin.conf file to replace the cluster address with
|
||||
# the floating management address
|
||||
# This is a temporary change used in upgrade of N+1 node
|
||||
admin_conf = os.path.join(tsc.PLATFORM_PATH, "config", to_load,
|
||||
"kubernetes", utils.KUBERNETES_ADMIN_CONF_FILE)
|
||||
with open(admin_conf, 'r') as yaml_file:
|
||||
config = yaml.load(yaml_file)
|
||||
|
||||
for item, values in config.items():
|
||||
# update server address in cluster
|
||||
if item == 'clusters':
|
||||
if 'cluster' in values[0] and 'server' in values[0]['cluster']:
|
||||
formatted_address = utils.format_url_address(mgmt_address)
|
||||
# TODO use urlparse() to get url components and update
|
||||
values[0]['cluster']['server'] = \
|
||||
"https://" + formatted_address + ":6443"
|
||||
break # no need to iterate further
|
||||
|
||||
with open(admin_conf, 'w') as yaml_file:
|
||||
yaml.dump(config, yaml_file, default_flow_style=False)
|
||||
|
||||
# Remove branding tar files from the release N+1 directory as branding
|
||||
# files are not compatible between releases.
|
||||
branding_files = os.path.join(
|
||||
|
|
|
@ -14,6 +14,7 @@ import os
|
|||
import subprocess
|
||||
import tempfile
|
||||
import yaml
|
||||
import netaddr
|
||||
|
||||
# WARNING: The controller-1 upgrade is done before any puppet manifests
|
||||
# have been applied, so only the static entries from tsconfig can be used.
|
||||
|
@ -254,3 +255,15 @@ def apply_upgrade_manifest(controller_address):
|
|||
msg = "Failed to execute upgrade manifest"
|
||||
print(msg)
|
||||
raise Exception(msg)
|
||||
|
||||
|
||||
def format_url_address(address):
|
||||
"""Format the URL address according to RFC 2732"""
|
||||
try:
|
||||
addr = netaddr.IPAddress(address)
|
||||
if addr.version == sysinv_constants.IPV6_FAMILY:
|
||||
return "[%s]" % address
|
||||
else:
|
||||
return str(address)
|
||||
except netaddr.AddrFormatError:
|
||||
return address
|
||||
|
|
|
@ -9277,9 +9277,14 @@ class ConductorManager(service.PeriodicService):
|
|||
rpcapi.create_simplex_backup(context, software_upgrade)
|
||||
return
|
||||
else:
|
||||
# get the floating management IP
|
||||
mgmt_address = self.dbapi.address_get_by_name(
|
||||
cutils.format_address_name(constants.CONTROLLER_HOSTNAME,
|
||||
constants.NETWORK_TYPE_MGMT)
|
||||
)
|
||||
i_system = self.dbapi.isystem_get_one()
|
||||
upgrades_management.prepare_upgrade(
|
||||
from_version, to_version, i_system)
|
||||
from_version, to_version, i_system, mgmt_address.address)
|
||||
|
||||
LOG.info("Finished upgrade preparation")
|
||||
except Exception:
|
||||
|
|
Loading…
Reference in New Issue