Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
  • Loading branch information
SpecLad committed May 14, 2023
commit 2012fd585b16906f9eef1934b27d5095ed9d4eef
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>)
Expand Down
13 changes: 10 additions & 3 deletions cvat/apps/lambda_manager/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,21 @@ def get(self, func_id):
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
Expand Down
6 changes: 5 additions & 1 deletion cvat/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,13 @@ class CVAT_QUEUES(Enum):
'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',
Expand Down