Skip to content

Commit 0ee39e3

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 5399f6e commit 0ee39e3

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 coniguration option to control how Nuclio functions are invoked
11+
(<https://github.com/opencv/cvat/pull/6146>)
1112

1213
### Changed
1314
- TDB

cvat/apps/lambda_manager/views.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,21 @@ def get(self, func_id):
8686
return response
8787

8888
def invoke(self, func, payload):
89-
if os.getenv('KUBERNETES_SERVICE_HOST'):
90-
return self._http(method="post", url='/api/function_invocations',
89+
invoke_method = {
90+
'dashboard': self._invoke_via_dashboard,
91+
'direct': self._invoke_directly,
92+
}
93+
94+
return invoke_method[settings.NUCLIO['INVOKE_METHOD']](func, payload)
95+
96+
def _invoke_via_dashboard(self, func, payload):
97+
return self._http(method="post", url='/api/function_invocations',
9198
data=payload, headers={
9299
'x-nuclio-function-name': func.id,
93100
'x-nuclio-path': '/'
94101
})
95102

96-
# Note: call the function directly without the nuclio dashboard
103+
def _invoke_directly(self, func, payload):
97104
# host.docker.internal for Linux will work only with Docker 20.10+
98105
NUCLIO_TIMEOUT = settings.NUCLIO['DEFAULT_TIMEOUT']
99106
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)