Skip to content

Commit c52a2da

Browse files
YinYangOfDaoAnbang-Hu
authored andcommitted
fix py2to3 breaks in az_tools and deploy, before prepare_vm phase in old deployment (#792)
1 parent 0c1820b commit c52a2da

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

src/ClusterBootstrap/az_tools.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -803,8 +803,10 @@ def gen_cluster_config(output_file_name, output_file=True, no_az=False):
803803
vm_list = get_vm_list_by_enum()
804804

805805
vm_ip_names = get_vm_private_ip()
806+
# 2 to 3
807+
vm_list = [{k.decode():v.decode() for k,v in itm.items()} for itm in vm_list]
808+
vm_ip_names = [{k.decode():[vi.decode() for vi in v] if isinstance(v, list) else v.decode() for k,v in itm.items()} for itm in vm_ip_names]
806809
vm_ip_names = sorted(vm_ip_names, key = lambda x:x['name'])
807-
808810
sku_mapping = config["sku_mapping"]
809811

810812
worker_machines = []
@@ -945,6 +947,8 @@ def get_vm_list_by_grp():
945947
if verbose:
946948
print(cmd)
947949
output = utils.exec_cmd_local(cmd)
950+
print("raw")
951+
print(output)
948952

949953
return utils.json_loads_byteified(output)
950954

@@ -970,7 +974,7 @@ def get_vm_list_by_enum():
970974
return vm_list
971975

972976
def random_str(length):
973-
return ''.join(random.choice(string.lowercase) for x in range(length))
977+
return ''.join(random.choice(string.ascii_lowercase) for x in range(length))
974978

975979

976980
def delete_cluster():
@@ -982,13 +986,13 @@ def delete_cluster():
982986

983987
def check_subscription():
984988
chkcmd ="az account list | grep -A5 -B5 '\"isDefault\": true'"
985-
output = utils.exec_cmd_local(chkcmd)
989+
output = utils.exec_cmd_local(chkcmd).decode()
986990
if not config["azure_cluster"]["subscription"] in output:
987991
setcmd = "az account set --subscription \"{}\"".format(config["azure_cluster"]["subscription"])
988992
setout = utils.exec_cmd_local(setcmd)
989993
print "Set your subscription to {}, please login.\nIf you want to specify another subscription, please configure azure_cluster.subscription".format(config["azure_cluster"]["subscription"])
990994
utils.exec_cmd_local("az login")
991-
assert config["azure_cluster"]["subscription"] in utils.exec_cmd_local(chkcmd)
995+
assert config["azure_cluster"]["subscription"] in utils.exec_cmd_local(chkcmd).decode()
992996

993997
def run_command(args, command, nargs, parser):
994998
if command == "genconfig":

src/ClusterBootstrap/deploy.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,9 @@ def add_kubelet_config():
372372
for file in kubemaster_cfg_files:
373373
with open(os.path.join("./deploy/kubelet", file), 'r') as f:
374374
content = f.read()
375-
config[file] = base64.b64encode(content)
375+
# encode to base64 and decode when used. this is to make STRUCTURED content more robust.
376+
# refer to {{cnf["ca.pem"]}} in template/cloud-config/cloud-config-worker.yml
377+
config[file] = base64.b64encode(content.encode('utf-8')).decode('utf-8')
376378

377379
def add_dns_entries():
378380
addCoreOSNetwork = ""
@@ -483,17 +485,17 @@ def init_deployment():
483485

484486
with open("./deploy/ssl/ca/ca.pem", 'r') as f:
485487
content = f.read()
486-
config["ca.pem"] = base64.b64encode(content)
488+
config["ca.pem"] = base64.b64encode(content.encode('utf-8')).decode('utf-8')
487489

488490
with open("./deploy/ssl/kubelet/apiserver.pem", 'r') as f:
489491
content = f.read()
490-
config["apiserver.pem"] = base64.b64encode(content)
491-
config["worker.pem"] = base64.b64encode(content)
492+
config["apiserver.pem"] = base64.b64encode(content.encode('utf-8')).decode('utf-8')
493+
config["worker.pem"] = base64.b64encode(content.encode('utf-8')).decode('utf-8')
492494

493495
with open("./deploy/ssl/kubelet/apiserver-key.pem", 'r') as f:
494496
content = f.read()
495-
config["apiserver-key.pem"] = base64.b64encode(content)
496-
config["worker-key.pem"] = base64.b64encode(content)
497+
config["apiserver-key.pem"] = base64.b64encode(content.encode('utf-8')).decode('utf-8')
498+
config["worker-key.pem"] = base64.b64encode(content.encode('utf-8')).decode('utf-8')
497499

498500
add_additional_cloud_config()
499501
add_kubelet_config()

0 commit comments

Comments
 (0)