Skip to content

Commit 2012fd5

Browse files
committed
Add an option to call Nuclio functions via the dashboard
Currently, this only happens when running in Kubernetes. This option lets CVAT use Nuclio that's deployed to Kubernetes without being deployed to Kubernetes itself, or just to use Nuclio that is deployed on another machine.
1 parent 2a41d59 commit 2012fd5

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## \[2.5.0] - Unreleased
99
### Added
10-
- TDB
10+
- A configuration option to control how Nuclio functions are invoked
11+
(<https://github.com/opencv/cvat/pull/6146>)
1112

1213
### Changed
1314
- Running SAM masks decoder on frontend (<https://github.com/opencv/cvat/pull/6019>)

cvat/apps/lambda_manager/views.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,21 @@ def get(self, func_id):
8989
return response
9090

9191
def invoke(self, func, payload):
92-
if os.getenv('KUBERNETES_SERVICE_HOST'):
93-
return self._http(method="post", url='/api/function_invocations',
92+
invoke_method = {
93+
'dashboard': self._invoke_via_dashboard,
94+
'direct': self._invoke_directly,
95+
}
96+
97+
return invoke_method[settings.NUCLIO['INVOKE_METHOD']](func, payload)
98+
99+
def _invoke_via_dashboard(self, func, payload):
100+
return self._http(method="post", url='/api/function_invocations',
94101
data=payload, headers={
95102
'x-nuclio-function-name': func.id,
96103
'x-nuclio-path': '/'
97104
})
98105

99-
# Note: call the function directly without the nuclio dashboard
106+
def _invoke_directly(self, func, payload):
100107
# host.docker.internal for Linux will work only with Docker 20.10+
101108
NUCLIO_TIMEOUT = settings.NUCLIO['DEFAULT_TIMEOUT']
102109
if os.path.exists('/.dockerenv'): # inside a docker container

cvat/settings/base.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,13 @@ class CVAT_QUEUES(Enum):
333333
'HOST': os.getenv('CVAT_NUCLIO_HOST', 'localhost'),
334334
'PORT': int(os.getenv('CVAT_NUCLIO_PORT', 8070)),
335335
'DEFAULT_TIMEOUT': int(os.getenv('CVAT_NUCLIO_DEFAULT_TIMEOUT', 120)),
336-
'FUNCTION_NAMESPACE': os.getenv('CVAT_NUCLIO_FUNCTION_NAMESPACE', 'nuclio')
336+
'FUNCTION_NAMESPACE': os.getenv('CVAT_NUCLIO_FUNCTION_NAMESPACE', 'nuclio'),
337+
'INVOKE_METHOD': os.getenv('CVAT_NUCLIO_INVOKE_METHOD',
338+
default='dashboard' if 'KUBERNETES_SERVICE_HOST' in os.environ else 'direct'),
337339
}
338340

341+
assert NUCLIO['INVOKE_METHOD'] in {'dashboard', 'direct'}
342+
339343
RQ_SHOW_ADMIN_LINK = True
340344
RQ_EXCEPTION_HANDLERS = [
341345
'cvat.apps.engine.views.rq_exception_handler',

0 commit comments

Comments
 (0)