Skip to content

Commit

Permalink
Fix passing ingres ports to gate
Browse files Browse the repository at this point in the history
  • Loading branch information
shapovalovts committed Dec 24, 2023
1 parent 21fdb14 commit 4a332be
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
25 changes: 15 additions & 10 deletions src/lib/wm_resource_utils.erl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-module(wm_resource_utils).

-export([get_ingres_ports_map/1, get_ingres_ports_str/1, get_port_tuples/1]).
-export([get_ingres_ports_map/2, get_ingres_ports_str/1, get_port_tuples/1]).

-include("wm_entity.hrl").
-include("wm_log.hrl").
Expand All @@ -15,35 +15,40 @@ get_ingres_port_with_proto(Port) ->
{error, not_found}
end.

-spec get_ingres_ports_map([#resource{}]) -> map().
get_ingres_ports_map([]) ->
-spec get_ingres_ports_map([#resource{}], atom()) -> map().
get_ingres_ports_map([], _) ->
#{};
get_ingres_ports_map([#resource{name = "ports", properties = Properties} | T]) ->
get_ingres_ports_map([#resource{name = "ports", properties = Properties} | T], KeyType) ->
case proplists:get_value(value, Properties) of
Value when is_list(Value) ->
Ports = string:split(Value, ",", all),
lists:foldl(fun(Port, Map) ->
case get_ingres_port_with_proto(Port) of
{ok, PortAndProto} ->
PortNumberStr = hd(string:split(PortAndProto, "/")),
maps:put(list_to_binary(PortNumberStr), #{}, Map);
case KeyType of
binaries ->
maps:put(list_to_binary(PortNumberStr), #{}, Map);
strings ->
maps:put(PortNumberStr, #{}, Map)
end;
{error, not_found} ->
Map
end
end,
#{},
Ports);
_ ->
get_ingres_ports_map(T)
get_ingres_ports_map(T, KeyType)
end;
get_ingres_ports_map([_ | T]) ->
get_ingres_ports_map(T).
get_ingres_ports_map([_ | T], KeyType) ->
get_ingres_ports_map(T, KeyType).


-spec get_ingres_ports_str([#resource{}]) -> [string()].
get_ingres_ports_str(Resources) ->
Ports = maps:keys(get_ingres_ports_map(Resources)),
string:join(Ports, ",").
Ports = maps:keys(get_ingres_ports_map(Resources, strings)),
lists:flatten(string:join(Ports, ",")).

-spec get_port_tuples([#resource{}]) -> {[{string(), integer(), integer()}], []}.
get_port_tuples([]) ->
Expand Down
2 changes: 1 addition & 1 deletion src/srv/cloud/wm_virtres_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ spawn_partition(Job, Remote) ->
JobIngresPorts = wm_resource_utils:get_ingres_ports_str(wm_entity:get(request, Job)),
ApiPort = integer_to_list(wm_entity:get(api_port, SelfNode)),
SshPort = wm_conf:g(ssh_daemon_listen_port, {?DEFAULT_SSH_DAEMON_PORT, integer}),
IngresPorts = JobIngresPorts ++ "," ++ ApiPort ++ "," ++ SshPort,
IngresPorts = JobIngresPorts ++ "," ++ ApiPort ++ "," ++ integer_to_list(SshPort),
Options =
#{name => PartName,
image_name => get_resource_value_property(image, "cloud-image", Job, Remote, fun get_default_image_name/1),
Expand Down
2 changes: 1 addition & 1 deletion src/srv/container/wm_docker.erl
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ generate_container_json(#job{request = Request}, Porter) ->
Term9 = jwalk:set({"HostConfig"}, Term8, get_host_config(Request)),
Term10 = jwalk:set({"StdinOnce"}, Term9, false),
Term11 = jwalk:set({"VolumesFrom"}, Term10, get_volumes_from()),
Term12 = jwalk:set({"ExposedPorts"}, Term11, wm_resource_utils:get_ingres_ports_map(Request)),
Term12 = jwalk:set({"ExposedPorts"}, Term11, wm_resource_utils:get_ingres_ports_map(Request, binaries)),
Term13 = jwalk:set({"WorkingDir"}, Term12, <<"/tmp">>),
Term14 = jwalk:set({"AutoRemove"}, Term13, true),
Term15 = jwalk:set({"User"}, Term14, <<"root">>),
Expand Down

0 comments on commit 4a332be

Please sign in to comment.