Skip to content

Commit

Permalink
Minor refactoring of K8S resource proxy factorying
Browse files Browse the repository at this point in the history
Signed-off-by: Bartosz Zurkowski <zurkowski.bartosz@gmail.com>
  • Loading branch information
bzurkowski committed Apr 9, 2020
1 parent 323a6c1 commit d6f8309
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 24 deletions.
18 changes: 12 additions & 6 deletions orca/common/clients/istio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,27 @@ def get(kind):
client = k8s.ClientFactory.get()
if kind == 'virtual_service':
return k8s.CustomResourceProxy(
'virtual_service', client.CustomObjectsApi().list_cluster_custom_object,
kind='virtual_service',
list_fn=client.CustomObjectsApi().list_cluster_custom_object,
group="networking.istio.io",
version="v1alpha3",
plural="virtualservices")
plural="virtualservices"
)
elif kind == 'destination_rule':
return k8s.CustomResourceProxy(
'destination_rule', client.CustomObjectsApi().list_cluster_custom_object,
kind='destination_rule',
list_fn=client.CustomObjectsApi().list_cluster_custom_object,
group="networking.istio.io",
version="v1alpha3",
plural="destinationrules")
plural="destinationrules"
)
elif kind == 'gateway':
return k8s.CustomResourceProxy(
'gateway', client.CustomObjectsApi().list_cluster_custom_object,
kind='gateway',
list_fn=client.CustomObjectsApi().list_cluster_custom_object,
group="networking.istio.io",
version="v1alpha3",
plural="gateways")
plural="gateways"
)
else:
raise Exception("Unknown kind %s" % kind)
63 changes: 45 additions & 18 deletions orca/common/clients/k8s/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,52 +36,79 @@ def get(kind):
client = ClientFactory.get()
if kind == 'pod':
return ResourceProxy(
'pod', client.CoreV1Api().list_pod_for_all_namespaces)
kind='pod',
list_fn=client.CoreV1Api().list_pod_for_all_namespaces
)
elif kind == 'service':
return ResourceProxy(
'service', client.CoreV1Api().list_service_for_all_namespaces)
kind='service',
list_fn=client.CoreV1Api().list_service_for_all_namespaces
)
elif kind == 'endpoints':
return ResourceProxy(
'endpoints', client.CoreV1Api().list_endpoints_for_all_namespaces)
kind='endpoints',
list_fn=client.CoreV1Api().list_endpoints_for_all_namespaces
)
elif kind == 'config_map':
return ResourceProxy(
'config_map', client.CoreV1Api().list_config_map_for_all_namespaces)
kind='config_map',
list_fn=client.CoreV1Api().list_config_map_for_all_namespaces
)
elif kind == 'secret':
return ResourceProxy(
'secret', client.CoreV1Api().list_secret_for_all_namespaces)
kind='secret',
list_fn=client.CoreV1Api().list_secret_for_all_namespaces
)
elif kind == 'node':
return ResourceProxy(
'node', client.CoreV1Api().list_node)
kind='node',
list_fn=client.CoreV1Api().list_node
)
elif kind == 'deployment':
return ResourceProxy(
'deployment', client.AppsV1Api().list_deployment_for_all_namespaces)
kind='deployment',
list_fn=client.AppsV1Api().list_deployment_for_all_namespaces
)
elif kind == 'stateful_set':
return ResourceProxy(
'stateful_set', client.AppsV1Api().list_stateful_set_for_all_namespaces)
kind='stateful_set',
list_fn=client.AppsV1Api().list_stateful_set_for_all_namespaces
)
elif kind == 'daemon_set':
return ResourceProxy(
'daemon_set', client.AppsV1Api().list_daemon_set_for_all_namespaces)
kind='daemon_set',
list_fn=client.AppsV1Api().list_daemon_set_for_all_namespaces
)
elif kind == 'replica_set':
return ResourceProxy(
'replica_set',
client.ExtensionsV1beta1Api().list_replica_set_for_all_namespaces)
kind='replica_set',
list_fn=client.ExtensionsV1beta1Api().list_replica_set_for_all_namespaces
)
elif kind == 'storage_class':
return ResourceProxy(
'storage_class', client.StorageV1Api().list_storage_class)
kind='storage_class',
list_fn=client.StorageV1Api().list_storage_class
)
elif kind == 'persistent_volume':
return ResourceProxy(
'persistent_volume', client.CoreV1Api().list_persistent_volume)
kind='persistent_volume',
list_fn=client.CoreV1Api().list_persistent_volume
)
elif kind == 'persistent_volume_claim':
return ResourceProxy(
'persistent_volume_claim',
client.CoreV1Api().list_persistent_volume_claim_for_all_namespaces)
kind='persistent_volume_claim',
list_fn=client.CoreV1Api().list_persistent_volume_claim_for_all_namespaces
)
elif kind == 'namespace':
return ResourceProxy(
'namespace', client.CoreV1Api().list_namespace)
kind='namespace',
list_fn=client.CoreV1Api().list_namespace
)
elif kind == 'horizontal_pod_autoscaler':
return ResourceProxy(
'horizontal_pod_autoscaler',
client.AutoscalingV1Api().list_horizontal_pod_autoscaler_for_all_namespaces)
kind='horizontal_pod_autoscaler',
list_fn=client.AutoscalingV1Api().list_horizontal_pod_autoscaler_for_all_namespaces
)
else:
raise Exception("Unknown kind %s" % kind)

Expand Down

0 comments on commit d6f8309

Please sign in to comment.