Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ clean-env: ## Remove conda env
lint: ## Check code style
@pip install -q -e ".[lint]"
@pip install -q pipx
ruff .
ruff check .
black --check --diff --color .
mdformat --check *.md
pipx run 'validate-pyproject[all]' pyproject.toml
Expand Down
25 changes: 24 additions & 1 deletion enterprise_gateway/services/processproxies/k8s.py

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete it from a hacker

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import re
from typing import Any

import kubernetes
import urllib3
from jinja2 import BaseLoader, Environment
from kubernetes import client, config
Expand All @@ -34,6 +35,26 @@
config.load_incluster_config()


def get_subject_class():
"""
Returns the appropriate Subject class based on the kubernetes client version.

In kubernetes-client, V1Subject was renamed to RbacV1Subject.
This function returns the appropriate class based on the installed version.
"""
# Check if V1Subject exists in the client
if hasattr(client, 'V1Subject'):
logging.debug(
"Using client.V1Subject for Kubernetes client version: %s", kubernetes.__version__
)
return client.V1Subject
# Fall back to RbacV1Subject for older versions
logging.debug(
"Using client.RbacV1Subject for Kubernetes client version: %s", kubernetes.__version__
)
return client.RbacV1Subject


class KubernetesProcessProxy(ContainerProcessProxy):
"""
Kernel lifecycle management for Kubernetes kernels.
Expand Down Expand Up @@ -349,7 +370,9 @@ def _create_role_binding(self, namespace: str, service_account_name: str) -> Non
binding_role_ref = client.V1RoleRef(
api_group="", kind="ClusterRole", name=kernel_cluster_role
)
binding_subjects = client.V1Subject(
# Use the appropriate Subject class based on kubernetes client version
SubjectClass = get_subject_class()
binding_subjects = SubjectClass(
api_group="", kind="ServiceAccount", name=service_account_name, namespace=namespace
)

Expand Down