-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dws2jgf: add script for generating rabbit map
Problem: as described in #193, JGF is too unwieldy to be stored in Ansible. On the other hand, Flux's ability to start up and run jobs cannot be dependent on the responsiveness of kubernetes, so generating JGF from kubernetes before starting Flux is not an option. A solution would be to store some static rabbit data in ansible, generated by reading from kubernetes. This data could be read in to generate JGF. Add a script that generates a JSON file describing which nodes map to which rabbits and what the capacity of each rabbit is.
- Loading branch information
1 parent
ffdf81c
commit 68a06db
Showing
2 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
dist_fluxcmd_SCRIPTS = \ | ||
flux-dws2jgf.py | ||
flux-dws2jgf.py \ | ||
flux-rabbitmapping.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import argparse | ||
import sys | ||
import json | ||
import subprocess | ||
|
||
import flux | ||
from flux.hostlist import Hostlist | ||
|
||
import kubernetes as k8s | ||
from kubernetes.client.rest import ApiException | ||
|
||
|
||
def get_storage(config_file): | ||
k8s_client = k8s.config.new_client_from_config(config_file=config_file) | ||
try: | ||
api_instance = k8s.client.CustomObjectsApi(k8s_client) | ||
except ApiException as rest_exception: | ||
if rest_exception.status == 403: | ||
raise Exception( | ||
"You must be logged in to the K8s or OpenShift cluster to continue" | ||
) | ||
raise | ||
|
||
group = "dataworkflowservices.github.io" | ||
version = "v1alpha2" | ||
plural = "storages" | ||
return api_instance.list_cluster_custom_object(group, version, plural) | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser( | ||
formatter_class=flux.util.help_formatter(), | ||
description=("Create a mapping between compute nodes and rabbit nodes"), | ||
) | ||
parser.add_argument( | ||
"--kubeconfig", | ||
"-k", | ||
default=None, | ||
metavar="FILE", | ||
help="Path to kubeconfig file to use", | ||
) | ||
parser.add_argument( | ||
"--indent", | ||
"-i", | ||
default=None, | ||
type=int, | ||
metavar="N", | ||
help="Number of spaces to indent output JSON document", | ||
) | ||
parser.add_argument( | ||
"--nosort", | ||
action="store_false", | ||
help="Do not sort keys in output JSON document", | ||
) | ||
args = parser.parse_args() | ||
rabbit_mapping = {"computes": {}, "rabbits": {}} | ||
for nnf in get_storage(args.kubeconfig)["items"]: | ||
hlist = Hostlist() | ||
nnf_name = nnf["metadata"]["name"] | ||
for compute in nnf["status"]["access"].get("computes", []): | ||
hlist.append(compute["name"]) | ||
rabbit_mapping["computes"][compute["name"]] = nnf_name | ||
rabbit_mapping["rabbits"][nnf_name] = {} | ||
rabbit_mapping["rabbits"][nnf_name]["hostlist"] = hlist.uniq().encode() | ||
rabbit_mapping["rabbits"][nnf_name]["capacity"] = nnf["status"]["capacity"] | ||
json.dump(rabbit_mapping, sys.stdout, indent=args.indent, sort_keys=args.nosort) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |