From be02a7007d65ce1227bfc61dba59de33f79c295b Mon Sep 17 00:00:00 2001 From: Keming Date: Wed, 31 Aug 2022 16:14:23 +0800 Subject: [PATCH] fix(lang): expose host port (#832) * fix(lang): expose host port Signed-off-by: Keming * update doc Signed-off-by: Keming Signed-off-by: Keming --- envd/api/runtime/__init__.py | 4 ++-- pkg/lang/frontend/starlark/runtime/runtime.go | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/envd/api/runtime/__init__.py b/envd/api/runtime/__init__.py index 1b63078cd..c92bda272 100644 --- a/envd/api/runtime/__init__.py +++ b/envd/api/runtime/__init__.py @@ -48,8 +48,8 @@ def expose(envd_port: str, host_port: Optional[str], service: Optional[str]): Args: envd_port (str): port in `envd` container - host_port (Optional[str]): port in the host, if not provided, `envd` will - randomly choose a free port + host_port (Optional[str]): port in the host, if not provided or + `host_port=0`, `envd` will randomly choose a free port service (Optional[str]): service name """ diff --git a/pkg/lang/frontend/starlark/runtime/runtime.go b/pkg/lang/frontend/starlark/runtime/runtime.go index 199ada62d..6b5c0a1cd 100644 --- a/pkg/lang/frontend/starlark/runtime/runtime.go +++ b/pkg/lang/frontend/starlark/runtime/runtime.go @@ -95,7 +95,7 @@ func ruleFuncExpose(thread *starlark.Thread, _ *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) { var ( envdPort starlark.Int - hostPort = starlark.MakeInt(0) + hostPort = starlark.MakeInt(0) // 0 means envd can randomly choose a free port serviceName = starlark.String("") ) @@ -108,8 +108,8 @@ func ruleFuncExpose(thread *starlark.Thread, _ *starlark.Builtin, return nil, errors.New("envd_port must be a positive integer less than 65535") } hostPortInt, ok := hostPort.Int64() - if !ok || hostPortInt < 1 || hostPortInt > 65535 { - return nil, errors.New("envd_port must be a positive integer less than 65535") + if !ok || hostPortInt < 0 || hostPortInt > 65535 { + return nil, errors.New("host_port must be a positive integer less than 65535") } serviceNameStr := serviceName.GoString()