Reformatting code to make it simpler
This commit is contained in:
parent
22c80a1b4c
commit
99506725ab
2 changed files with 20 additions and 14 deletions
|
@ -9,7 +9,7 @@ Usage
|
||||||
::
|
::
|
||||||
|
|
||||||
$ get-k8s-resources -h
|
$ get-k8s-resources -h
|
||||||
usage: get-k8s-resources.py [-h] [-n NAMESPACE] [-c CONTEXT] -t
|
usage: get-k8s-resources [-h] [-n NAMESPACE] [-c CONTEXT] -t
|
||||||
{deployments,services,pods,ingresses}
|
{deployments,services,pods,ingresses}
|
||||||
|
|
||||||
Returns a json list of kubernetes deployments.
|
Returns a json list of kubernetes deployments.
|
||||||
|
|
|
@ -81,7 +81,7 @@ def print_list(k8s_object_list):
|
||||||
print(_k8s_object_list)
|
print(_k8s_object_list)
|
||||||
|
|
||||||
|
|
||||||
def get_client_extensions(api):
|
def get_extensions(api):
|
||||||
return client.ExtensionsV1beta1Api(api)
|
return client.ExtensionsV1beta1Api(api)
|
||||||
|
|
||||||
|
|
||||||
|
@ -100,10 +100,22 @@ def get_client(kubeconfig, context):
|
||||||
|
|
||||||
|
|
||||||
k8s_types = {
|
k8s_types = {
|
||||||
"deployments": get_deployments,
|
"deployments": {
|
||||||
"services": get_services,
|
"function": get_deployments,
|
||||||
"pods": get_pods,
|
"api": get_extensions
|
||||||
"ingresses": get_ingresses,
|
},
|
||||||
|
"services": {
|
||||||
|
"function": get_services,
|
||||||
|
"api": get_core_api_v1
|
||||||
|
},
|
||||||
|
"pods": {
|
||||||
|
"function": get_pods,
|
||||||
|
"api": get_core_api_v1
|
||||||
|
},
|
||||||
|
"ingresses": {
|
||||||
|
"function": get_ingresses,
|
||||||
|
"api": get_extensions
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -112,14 +124,8 @@ def main():
|
||||||
_client = get_client(parser.kubeconfig, parser.context)
|
_client = get_client(parser.kubeconfig, parser.context)
|
||||||
api = None
|
api = None
|
||||||
if parser.type in k8s_types.keys():
|
if parser.type in k8s_types.keys():
|
||||||
if parser.type in ["pods", "services"]:
|
api = k8s_types[parser.type]["api"](_client)
|
||||||
api = get_core_api_v1(_client)
|
k8s_types[parser.type]["function"](api, parser.namespace)
|
||||||
if parser.type in ["deployments", "ingresses"]:
|
|
||||||
api = get_client_extensions(_client)
|
|
||||||
k8s_types[parser.type](api, parser.namespace)
|
|
||||||
else:
|
|
||||||
print("No type provided, failing...")
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
def argumentparser():
|
def argumentparser():
|
||||||
|
|
Loading…
Reference in a new issue