def asg(clusterID): # TODO: get aws autoscaling groups and update their placement group """ aws autoscaling update-auto-scaling-group --auto-scaling-group-name nodes.m4.2xlarge.prom.7688c.k8s.local --placement-group perfd""" # cmd(f"aws autoscaling update-auto-scaling-group --auto-scaling-group-name {clusterID} --placementgroup perfd || true") out = cmd_out(f"aws autoscaling describe-auto-scaling-groups | jq ") for i in range(10): for asg in json.loads(out)["AutoScalingGroups"]: print(asg["AutoScalingGroupName"])
def get_cluster_info(): ci_raw = utils.cmd_out("source {}; kops get cluster --output yaml".format( _env_file)).decode("utf-8") ci = yaml.load(ci_raw) return { "name": ci["metadata"]["name"], "region": ci["spec"]["subnets"][0]["zone"], # TODO: support multiple zones }
def get_all_worker_ig_num(): docs = utils.cmd_out("source {}; kops get ig --output yaml".format( _env_file)).decode("utf-8") igs = dict() for doc in yaml.load_all(docs): assert doc["spec"]["maxSize"] == doc["spec"]["minSize"] name = doc["metadata"]["name"] if name.startswith("master") or name.endswith("prom"): continue num = doc["spec"]["maxSize"] igs[name] = num return igs
def get_ig_config_raw(ig_name: str): return utils.cmd_out( "source {}; kops get ig {} --name $NAME --output yaml".format( _env_file, ig_name)).decode("utf-8")
def get_ins_ready_num(ins_type: str): # TODO: more reliable counting ready nodes return utils.cmd_out( "source {}; kubectl get nodes -l \"kops.k8s.io/instancegroup={}\" ". format(_env_file, get_ig_name(ins_type))).decode("utf-8").count(" Ready")