Merge "Fix 50-remove-calico-ipip.py upgrade script"
This commit is contained in:
@@ -37,11 +37,10 @@ def main():
|
|||||||
'%(filename)s(%(lineno)s): %(levelname)s: %(message)s')
|
'%(filename)s(%(lineno)s): %(levelname)s: %(message)s')
|
||||||
LOG.basicConfig(filename="/var/log/software.log",
|
LOG.basicConfig(filename="/var/log/software.log",
|
||||||
format=log_format, level=LOG.INFO, datefmt="%FT%T")
|
format=log_format, level=LOG.INFO, datefmt="%FT%T")
|
||||||
|
|
||||||
LOG.info("%s invoked from_release = %s to_release = %s action = %s"
|
|
||||||
% (sys.argv[0], from_release, to_release, action))
|
|
||||||
res = 0
|
res = 0
|
||||||
if action == "activate" and from_release == '22.12':
|
if action == "activate" and from_release == '22.12':
|
||||||
|
LOG.info("%s invoked from_release = %s to_release = %s action = %s"
|
||||||
|
% (sys.argv[0], from_release, to_release, action))
|
||||||
try:
|
try:
|
||||||
res = do_update(from_release, to_release)
|
res = do_update(from_release, to_release)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -52,19 +51,33 @@ def main():
|
|||||||
|
|
||||||
|
|
||||||
def do_update(from_release, to_release):
|
def do_update(from_release, to_release):
|
||||||
|
# Check if IPv4 IPIP pool exists
|
||||||
|
cmd = (KUBE_CMD + "get ippools.crd.projectcalico.org" +
|
||||||
|
" --no-headers" +
|
||||||
|
" -o custom-columns=NAME:.metadata.name")
|
||||||
|
stdout, _ = run_cmd(cmd)
|
||||||
|
|
||||||
# Disable IPIP overlay by setting default IPv4 ippool's ipipMode to Never
|
# Disable IPIP overlay by setting default IPv4 ippool's ipipMode to Never
|
||||||
|
if stdout.rstrip('\n') == "default-ipv4-ippool":
|
||||||
LOG.info("Disabling Calico's IPIP tunnel")
|
LOG.info("Disabling Calico's IPIP tunnel")
|
||||||
cmd = (KUBE_CMD + "patch ippools.crd.projectcalico.org" +
|
cmd = (KUBE_CMD + "patch ippools.crd.projectcalico.org" +
|
||||||
" default-ipv4-ippool" +
|
" default-ipv4-ippool" +
|
||||||
" --type=merge -p '{\"spec\":{\"ipipMode\":\"Never\"}}'")
|
" --type=merge -p" +
|
||||||
|
" '{\"spec\":{\"ipipMode\":\"Never\"}}'")
|
||||||
|
run_cmd(cmd)
|
||||||
|
else:
|
||||||
|
LOG.info("Skipping, default-ipv4-ippool not found")
|
||||||
|
|
||||||
|
|
||||||
|
def run_cmd(cmd):
|
||||||
sub = subprocess.Popen(cmd, shell=True,
|
sub = subprocess.Popen(cmd, shell=True,
|
||||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
stdout, stderr = sub.communicate()
|
stdout, stderr = sub.communicate()
|
||||||
if sub.returncode != 0:
|
if sub.returncode != 0:
|
||||||
LOG.error('Command failed:\n %s\n. %s\n%s\n'
|
LOG.error('Command failed:\n %s\n. %s\n%s\n'
|
||||||
% (cmd, stdout.decode('utf-8'), stderr.decode('utf-8')))
|
% (cmd, stdout.decode('utf-8'), stderr.decode('utf-8')))
|
||||||
raise Exception('Cannot change default-ipv4-ippool')
|
raise Exception(f'Cannot run cmd: "{cmd}"')
|
||||||
|
return stdout.decode('utf-8'), stderr.decode('utf-8')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Reference in New Issue
Block a user