|
10 | 10 | import re
|
11 | 11 | from typing import Any
|
12 | 12 |
|
| 13 | +import kubernetes |
13 | 14 | import urllib3
|
14 | 15 | from jinja2 import BaseLoader, Environment
|
15 | 16 | from kubernetes import client, config
|
|
34 | 35 | config.load_incluster_config()
|
35 | 36 |
|
36 | 37 |
|
| 38 | +def get_subject_class(): |
| 39 | + """ |
| 40 | + Returns the appropriate Subject class based on the kubernetes client version. |
| 41 | +
|
| 42 | + In kubernetes-client, V1Subject was renamed to RbacV1Subject. |
| 43 | + This function returns the appropriate class based on the installed version. |
| 44 | + """ |
| 45 | + # Check if V1Subject exists in the client |
| 46 | + if hasattr(client, 'V1Subject'): |
| 47 | + logging.debug( |
| 48 | + "Using client.V1Subject for Kubernetes client version: %s", kubernetes.__version__ |
| 49 | + ) |
| 50 | + return client.V1Subject |
| 51 | + # Fall back to RbacV1Subject for older versions |
| 52 | + logging.debug( |
| 53 | + "Using client.RbacV1Subject for Kubernetes client version: %s", kubernetes.__version__ |
| 54 | + ) |
| 55 | + return client.RbacV1Subject |
| 56 | + |
| 57 | + |
37 | 58 | class KubernetesProcessProxy(ContainerProcessProxy):
|
38 | 59 | """
|
39 | 60 | Kernel lifecycle management for Kubernetes kernels.
|
@@ -349,7 +370,9 @@ def _create_role_binding(self, namespace: str, service_account_name: str) -> Non
|
349 | 370 | binding_role_ref = client.V1RoleRef(
|
350 | 371 | api_group="", kind="ClusterRole", name=kernel_cluster_role
|
351 | 372 | )
|
352 |
| - binding_subjects = client.RbacV1Subject( |
| 373 | + # Use the appropriate Subject class based on kubernetes client version |
| 374 | + SubjectClass = get_subject_class() |
| 375 | + binding_subjects = SubjectClass( |
353 | 376 | api_group="", kind="ServiceAccount", name=service_account_name, namespace=namespace
|
354 | 377 | )
|
355 | 378 |
|
|
0 commit comments