Skip to content

Commit a378a08

Browse files
[k8s] Fix recursive decoration of kubernetes API methods (#3786)
* decorate only when necessary * lint * change to _sky_decorator_types * lint
1 parent 93b319e commit a378a08

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

sky/adaptors/kubernetes.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import logging
66
import os
7+
from typing import Any, Callable, Set
78

89
from sky.adaptors import common
910
from sky.sky_logging import set_logging_level
@@ -30,11 +31,19 @@
3031
API_TIMEOUT = 5
3132

3233

33-
def _decorate_methods(obj, decorator):
34+
def _decorate_methods(obj: Any, decorator: Callable, decoration_type: str):
3435
for attr_name in dir(obj):
3536
attr = getattr(obj, attr_name)
37+
# Skip methods starting with '__' since they are invoked through one
38+
# of the main methods, which are already decorated.
3639
if callable(attr) and not attr_name.startswith('__'):
37-
setattr(obj, attr_name, decorator(attr))
40+
decorated_types: Set[str] = getattr(attr, '_sky_decorator_types',
41+
set())
42+
if decoration_type not in decorated_types:
43+
decorated_attr = decorator(attr)
44+
decorated_attr._sky_decorator_types = ( # pylint: disable=protected-access
45+
decorated_types | {decoration_type})
46+
setattr(obj, attr_name, decorated_attr)
3847
return obj
3948

4049

@@ -49,7 +58,7 @@ def decorated_api(api):
4958

5059
def wrapped(*args, **kwargs):
5160
obj = api(*args, **kwargs)
52-
_decorate_methods(obj, set_logging_level(logger, level))
61+
_decorate_methods(obj, set_logging_level(logger, level), 'api_log')
5362
return obj
5463

5564
return wrapped

0 commit comments

Comments
 (0)