未验证 提交 7d21a73a 编写于 作者: R Roman Donchenko 提交者: GitHub

Add an option to call Nuclio functions via the dashboard (#6146)

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.
上级 c005d6c0
......@@ -7,7 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## \[2.5.0] - Unreleased
### Added
- TDB
- A configuration option to control how Nuclio functions are invoked
(<https://github.com/opencv/cvat/pull/6146>)
### Changed
- Running SAM masks decoder on frontend (<https://github.com/opencv/cvat/pull/6019>)
......
......@@ -89,14 +89,21 @@ class LambdaGateway:
return response
def invoke(self, func, payload):
if os.getenv('KUBERNETES_SERVICE_HOST'):
return self._http(method="post", url='/api/function_invocations',
invoke_method = {
'dashboard': self._invoke_via_dashboard,
'direct': self._invoke_directly,
}
return invoke_method[settings.NUCLIO['INVOKE_METHOD']](func, payload)
def _invoke_via_dashboard(self, func, payload):
return self._http(method="post", url='/api/function_invocations',
data=payload, headers={
'x-nuclio-function-name': func.id,
'x-nuclio-path': '/'
})
# Note: call the function directly without the nuclio dashboard
def _invoke_directly(self, func, payload):
# host.docker.internal for Linux will work only with Docker 20.10+
NUCLIO_TIMEOUT = settings.NUCLIO['DEFAULT_TIMEOUT']
if os.path.exists('/.dockerenv'): # inside a docker container
......
......@@ -333,9 +333,13 @@ NUCLIO = {
'HOST': os.getenv('CVAT_NUCLIO_HOST', 'localhost'),
'PORT': int(os.getenv('CVAT_NUCLIO_PORT', 8070)),
'DEFAULT_TIMEOUT': int(os.getenv('CVAT_NUCLIO_DEFAULT_TIMEOUT', 120)),
'FUNCTION_NAMESPACE': os.getenv('CVAT_NUCLIO_FUNCTION_NAMESPACE', 'nuclio')
'FUNCTION_NAMESPACE': os.getenv('CVAT_NUCLIO_FUNCTION_NAMESPACE', 'nuclio'),
'INVOKE_METHOD': os.getenv('CVAT_NUCLIO_INVOKE_METHOD',
default='dashboard' if 'KUBERNETES_SERVICE_HOST' in os.environ else 'direct'),
}
assert NUCLIO['INVOKE_METHOD'] in {'dashboard', 'direct'}
RQ_SHOW_ADMIN_LINK = True
RQ_EXCEPTION_HANDLERS = [
'cvat.apps.engine.views.rq_exception_handler',
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册