def join(connection, worker, skip_verify, disable_low_memory_guard): """ Join the node to a cluster CONNECTION: the cluster connection endpoint in format <master>:<port>/<token> """ connection_parts = connection.split("/") verify = not skip_verify if is_low_memory_guard_enabled() and disable_low_memory_guard: os.remove( os.path.expandvars("$SNAP_DATA/var/lock/low-memory-guard.lock")) if is_low_memory_guard_enabled() and not worker: print(""" This node does not have enough RAM to host the Kubernetes control plane services and join the database quorum. You may consider joining this node as a worker instead: microk8s join {connection} --worker If you would still like to join the cluster as a control plane node, use: microk8s join {connection} --disable-low-memory-guard """.format(connection=connection)) sys.exit(1) if is_node_running_dqlite(): join_dqlite(connection_parts, verify, worker) else: join_etcd(connection_parts, verify) sys.exit(0)
def reset(node, force): """ Remove a node from the cluster """ if is_node_running_dqlite(): remove_dqlite_node(node, force) else: remove_node(node) sys.exit(0)
def leave(): """ The node will depart from the cluster it is in. """ if is_node_running_dqlite(): if is_node_dqlite_worker(): reset_current_dqlite_worker_installation() else: reset_current_dqlite_installation() else: reset_current_etcd_installation() sys.exit(0)
def get_cluster_agent_endpoints(include_self=False): """ Get a list of all cluster agent endpoints and their callback token. :param include_self: If true, include the current node in the list. :return: [("node1:25000", "token1"), ("node2:25000", "token2"), ...] """ nodes = [] if is_node_running_dqlite(): hostname = socket.gethostname() token = get_callback_token() subprocess.check_call( [MICROK8S_STATUS, "--wait-ready", "--timeout=60"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, ) stdout = subprocess.check_output( [KUBECTL, "get", "node", "-o", "json"]) info = json.loads(stdout) for node_info in info["items"]: node_ip = get_internal_ip_from_get_node(node_info) if not include_self and is_same_server(hostname, node_ip): continue nodes.append(("{}:25000".format(node_ip), token.rstrip())) else: if include_self: token = get_callback_token() port = get_cluster_agent_port() nodes.append(("127.0.0.1:{}".format(port), token.rstrip())) try: with open(callback_tokens_file, "r+") as fin: for line in fin: node_ep, token = line.split() host = node_ep.split(":")[0] try: subprocess.check_call( [KUBECTL, "get", "node", host], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, ) nodes.append((node_ep, token.rstrip())) except subprocess.CalledProcessError: print("Node {} not present".format(host)) except OSError: pass return nodes
def print_pretty(token, check): default_ip, all_ips, port = get_network_info() print("From the node you wish to join to this cluster, run the following:") print(f"microk8s join {default_ip}:{port}/{token}/{check}\n") if is_node_running_dqlite(): print( "Use the '--worker' flag to join a node as a worker not running the control plane, eg:" ) print(f"microk8s join {default_ip}:{port}/{token}/{check} --worker\n") print( "If the node you are adding is not reachable through the default interface you can use one of the following:" ) for ip in all_ips: print(f"microk8s join {ip}:{port}/{token}/{check}")
"name": addon, state: "true" }], } do_configure_op(remote_op) def usage(): print("usage: dist_refresh_opt [OPERATION] [SERVICE] (ARGUMENT) (value)") print( "OPERATION is one of restart, update_argument, remove_argument, set_addon" ) if __name__ == "__main__": if is_node_running_dqlite() and not os.path.isfile(callback_token_file): # print("Single node cluster.") exit(0) if not is_node_running_dqlite() and not os.path.isfile( callback_tokens_file): print("No callback tokens file.") exit(1) try: opts, args = getopt.getopt(sys.argv[1:], "h", ["help"]) except getopt.GetoptError as err: # print help information and exit: print(err) # will print something like "option -a not recognized" usage() sys.exit(2)