Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(app): use group in dynamic k8s client #151

Merged
merged 4 commits into from
Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions controller/server_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def cull_idle_jupyter_servers(body, name, namespace, logger, **kwargs):
except KeyError:
return
cpu_usage = get_cpu_usage_for_culling(pod=pod_name, namespace=namespace)
custom_resource_api = get_api(config.api_version, config.custom_resource_name)
custom_resource_api = get_api(config.api_version, config.custom_resource_name, config.api_group)
idle_seconds = int(body["status"].get("idleSeconds", 0))
now = pytz.UTC.localize(datetime.utcnow())
last_activity = js_server_status.get("last_activity", now)
Expand Down Expand Up @@ -279,7 +279,7 @@ def update_status(body, event, labels, logger, meta, name, namespace, uid, **_):

# We use the dynamic client for patching since we need
# content_type="application/json-patch+json"
custom_resource_api = get_api(config.api_version, config.custom_resource_name)
custom_resource_api = get_api(config.api_version, config.custom_resource_name, config.api_group)
try:
custom_resource_api.patch(
namespace=namespace,
Expand Down Expand Up @@ -334,7 +334,7 @@ def update_resource_usage(body, name, namespace, **kwargs):
}
}
}
custom_resource_api = get_api(config.api_version, config.custom_resource_name)
custom_resource_api = get_api(config.api_version, config.custom_resource_name, config.api_group)
try:
custom_resource_api.patch(
namespace=namespace,
Expand Down
8 changes: 4 additions & 4 deletions controller/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,20 +189,20 @@ def parse_du_command(capacity, bytes_multiplier=1024):
return None


def get_api(api_version, kind):
def get_api(api_version, kind, group=None):
"""
Get the proper API for a certain resource. We cache the resources
availabe in the cluster for 60 seconds in order to reduce the amount
of unnecessary requests in busy clusters.
"""
try:
return api_cache[(api_version, kind)]
return api_cache[(api_version, kind, group)]
except KeyError:
client = dynamic.DynamicClient(api_client.ApiClient())
api_cache[(api_version, kind)] = client.resources.get(
olevski marked this conversation as resolved.
Show resolved Hide resolved
api_version=api_version, kind=kind
api_version=api_version, kind=kind, group=group,
olevski marked this conversation as resolved.
Show resolved Hide resolved
)
return api_cache[(api_version, kind)]
return api_cache[(api_version, kind, group)]


def convert_to_bytes(value):
Expand Down