Skip to content

Commit 571c992

Browse files
merqrilresende
andauthored
change V1Subject to RbacV1Subject in k8s.py (#1384)
Co-authored-by: Luciano Resende <[email protected]>
1 parent 1e6b2f3 commit 571c992

File tree

1 file changed

+24
-1
lines changed
  • enterprise_gateway/services/processproxies

1 file changed

+24
-1
lines changed

enterprise_gateway/services/processproxies/k8s.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import re
1111
from typing import Any
1212

13+
import kubernetes
1314
import urllib3
1415
from kubernetes import client, config
1516

@@ -33,6 +34,26 @@
3334
config.load_incluster_config()
3435

3536

37+
def get_subject_class():
38+
"""
39+
Returns the appropriate Subject class based on the kubernetes client version.
40+
41+
In kubernetes-client, V1Subject was renamed to RbacV1Subject.
42+
This function returns the appropriate class based on the installed version.
43+
"""
44+
# Check if V1Subject exists in the client
45+
if hasattr(client, 'V1Subject'):
46+
logging.debug(
47+
"Using client.V1Subject for Kubernetes client version: %s", kubernetes.__version__
48+
)
49+
return client.V1Subject
50+
# Fall back to RbacV1Subject for older versions
51+
logging.debug(
52+
"Using client.RbacV1Subject for Kubernetes client version: %s", kubernetes.__version__
53+
)
54+
return client.RbacV1Subject
55+
56+
3657
class KubernetesProcessProxy(ContainerProcessProxy):
3758
"""
3859
Kernel lifecycle management for Kubernetes kernels.
@@ -393,7 +414,9 @@ def _create_role_binding(self, namespace: str, service_account_name: str) -> Non
393414
binding_role_ref = client.V1RoleRef(
394415
api_group="", kind="ClusterRole", name=kernel_cluster_role
395416
)
396-
binding_subjects = client.V1Subject(
417+
# Use the appropriate Subject class based on kubernetes client version
418+
SubjectClass = get_subject_class()
419+
binding_subjects = SubjectClass(
397420
api_group="", kind="ServiceAccount", name=service_account_name, namespace=namespace
398421
)
399422

0 commit comments

Comments
 (0)