From d7335cc7b94f29b4999111e897ed18cdd77ecd8d Mon Sep 17 00:00:00 2001 From: Gyanendra Mishra Date: Wed, 1 May 2024 13:21:22 +0100 Subject: [PATCH 1/3] disable 1-1 mathcing --- .../user_services_functions/start_user_services.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/user_services_functions/start_user_services.go b/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/user_services_functions/start_user_services.go index d229461293..1fdebf0d5f 100644 --- a/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/user_services_functions/start_user_services.go +++ b/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/user_services_functions/start_user_services.go @@ -179,7 +179,7 @@ func StartRegisteredUserServices( publicPorts := serviceConfig.GetPublicPorts() if len(publicPorts) > 0 { privatePorts := serviceConfig.GetPrivatePorts() - err := checkPrivateAndPublicPortsAreOneToOne(privatePorts, publicPorts) + err := checkPrivateAndPublicPortIdsMatch(privatePorts, publicPorts) if err != nil { failedServicesPool[serviceUuid] = stacktrace.Propagate(err, "Private and public ports for service with UUID '%v' are not one to one.", serviceUuid) delete(serviceConfigsToStart, serviceUuid) @@ -815,11 +815,7 @@ func getUpdatedEntrypointAndCmdFromFilesToBeMoved(ctx context.Context, dockerMan // - There is a matching publicPort for every portID in privatePorts // - There are the same amount of private and public ports // If error is nil, the public and private ports are one to one. -func checkPrivateAndPublicPortsAreOneToOne(privatePorts map[string]*port_spec.PortSpec, publicPorts map[string]*port_spec.PortSpec) error { - if len(privatePorts) != len(publicPorts) { - return stacktrace.NewError("The received private ports length and the public ports length are not equal. Received '%v' private ports and '%v' public ports", len(privatePorts), len(publicPorts)) - } - +func checkPrivateAndPublicPortIdsMatch(privatePorts map[string]*port_spec.PortSpec, publicPorts map[string]*port_spec.PortSpec) error { for portID, privatePortSpec := range privatePorts { if _, found := publicPorts[portID]; !found { return stacktrace.NewError("Expected to receive public port with ID '%v' bound to private port number '%v', but it was not found", portID, privatePortSpec.GetNumber()) From ae8679437232553f9d150bfc1738dbfed55a2f2c Mon Sep 17 00:00:00 2001 From: Gyanendra Mishra Date: Wed, 1 May 2024 13:30:05 +0100 Subject: [PATCH 2/3] allow for private prots not being same size as public --- .../user_services_functions/start_user_services.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/user_services_functions/start_user_services.go b/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/user_services_functions/start_user_services.go index 1fdebf0d5f..2b6a77dc2a 100644 --- a/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/user_services_functions/start_user_services.go +++ b/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/user_services_functions/start_user_services.go @@ -657,7 +657,7 @@ func createStartServiceOperation( return nil, stacktrace.Propagate(err, "An error occurred converting private port spec '%v' to a Docker port", portId) } //TODO this is a huge hack to temporarily enable static ports for NEAR until we have a more productized solution - if len(publicPorts) > 0 { + if portShouldBeManuallyPublished(portId, publicPorts) { publicPortSpec, found := publicPorts[portId] if !found { return nil, stacktrace.NewError("Expected to receive public port with ID '%v' bound to private port number '%v', but it was not found", portId, privatePortSpec.GetNumber()) @@ -907,3 +907,11 @@ func quoteAndJoinArgs(args []string) string { } return strings.Join(quotedArgs, " ") } + +func portShouldBeManuallyPublished(key string, publicPorts map[string]*port_spec.PortSpec) bool { + if len(publicPorts) == 0 { + return false + } + _, found := publicPorts[key] + return found +} From 608f3d509c8bdae0c5bb5d86afd000b24e5afb2e Mon Sep 17 00:00:00 2001 From: Gyanendra Mishra Date: Wed, 1 May 2024 13:44:25 +0100 Subject: [PATCH 3/3] this builds --- .../user_services_functions/start_user_services.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/user_services_functions/start_user_services.go b/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/user_services_functions/start_user_services.go index 2b6a77dc2a..23c3f86a8f 100644 --- a/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/user_services_functions/start_user_services.go +++ b/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/user_services_functions/start_user_services.go @@ -811,14 +811,11 @@ func getUpdatedEntrypointAndCmdFromFilesToBeMoved(ctx context.Context, dockerMan return cmdArgs, entrypointArgs, nil } -// Ensure that provided [privatePorts] and [publicPorts] are one to one by checking: -// - There is a matching publicPort for every portID in privatePorts -// - There are the same amount of private and public ports -// If error is nil, the public and private ports are one to one. +// Ensure that every public port has a matching private port id func checkPrivateAndPublicPortIdsMatch(privatePorts map[string]*port_spec.PortSpec, publicPorts map[string]*port_spec.PortSpec) error { - for portID, privatePortSpec := range privatePorts { - if _, found := publicPorts[portID]; !found { - return stacktrace.NewError("Expected to receive public port with ID '%v' bound to private port number '%v', but it was not found", portID, privatePortSpec.GetNumber()) + for portID, publicPortSpec := range publicPorts { + if _, found := privatePorts[portID]; !found { + return stacktrace.NewError("Expected to receive private port with ID '%v' bound for public port number '%v', but it was not found", portID, publicPortSpec.GetNumber()) } } return nil