From 98b2b4b138c8095003e05fca8ae4cd71421bf869 Mon Sep 17 00:00:00 2001 From: Tedi Mitiku Date: Wed, 29 Nov 2023 15:51:39 -0500 Subject: [PATCH] move where logs collector is created --- ...cker_kurtosis_backend_enclave_functions.go | 17 -------------- .../engine/enclave_manager/enclave_creator.go | 22 ++++++++++++++++++- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/docker_kurtosis_backend_enclave_functions.go b/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/docker_kurtosis_backend_enclave_functions.go index 54aabf1a93..e6fecd4d3b 100644 --- a/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/docker_kurtosis_backend_enclave_functions.go +++ b/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/docker_kurtosis_backend_enclave_functions.go @@ -23,9 +23,6 @@ const ( shouldFetchStoppedContainersWhenDumpingEnclave = true - defaultHttpLogsCollectorPortNum = uint16(9712) - defaultTcpLogsCollectorPortNum = uint16(9713) - serializedArgs = "SERIALIZED_ARGS" ) @@ -148,21 +145,7 @@ func (backend *DockerKurtosisBackend) CreateEnclave(ctx context.Context, enclave // TODO: return production mode for create enclave request as well newEnclave := enclave.NewEnclave(enclaveUuid, enclaveName, enclave.EnclaveStatus_Empty, &creationTime, false) - // TODO the logs collector has a random private ip address in the enclave network that must be tracked - if _, err := backend.CreateLogsCollectorForEnclave(ctx, enclaveUuid, defaultTcpLogsCollectorPortNum, defaultHttpLogsCollectorPortNum); err != nil { - return nil, stacktrace.Propagate(err, "An error occurred creating the logs collector with TCP port number '%v' and HTTP port number '%v'", defaultTcpLogsCollectorPortNum, defaultHttpLogsCollectorPortNum) - } - shouldDeleteLogsCollector := true - defer func() { - if shouldDeleteLogsCollector { - err = backend.DestroyLogsCollectorForEnclave(ctx, enclaveUuid) - if err != nil { - logrus.Errorf("Couldn't cleanup logs collector for enclave '%v' as the following error was thrown:\n%v", enclaveUuid, err) - } - } - }() - shouldDeleteLogsCollector = false shouldDeleteNetwork = false shouldDeleteVolume = false return newEnclave, nil diff --git a/engine/server/engine/enclave_manager/enclave_creator.go b/engine/server/engine/enclave_manager/enclave_creator.go index 41fad2c683..05ff2b1534 100644 --- a/engine/server/engine/enclave_manager/enclave_creator.go +++ b/engine/server/engine/enclave_manager/enclave_creator.go @@ -13,6 +13,11 @@ import ( "github.com/sirupsen/logrus" ) +const ( + defaultHttpLogsCollectorPortNum = uint16(9712) + defaultTcpLogsCollectorPortNum = uint16(9713) +) + type EnclaveCreator struct { kurtosisBackend backend_interface.KurtosisBackend apiContainerKurtosisBackendConfigSupplier api_container_launcher.KurtosisBackendConfigSupplier @@ -75,6 +80,20 @@ func (creator *EnclaveCreator) CreateEnclave( } }() + // TODO the logs collector has a random private ip address in the enclave network that must be tracked + if _, err := creator.kurtosisBackend.CreateLogsCollectorForEnclave(setupCtx, enclaveUuid, defaultTcpLogsCollectorPortNum, defaultHttpLogsCollectorPortNum); err != nil { + return nil, stacktrace.Propagate(err, "An error occurred creating the logs collector with TCP port number '%v' and HTTP port number '%v'", defaultTcpLogsCollectorPortNum, defaultHttpLogsCollectorPortNum) + } + shouldDeleteLogsCollector := true + defer func() { + if shouldDeleteLogsCollector { + err = creator.kurtosisBackend.DestroyLogsCollectorForEnclave(teardownCtx, enclaveUuid) + if err != nil { + logrus.Errorf("Couldn't cleanup logs collector for enclave '%v' as the following error was thrown:\n%v", enclaveUuid, err) + } + } + }() + apiContainer, err := creator.launchApiContainer(setupCtx, apiContainerImageVersionTag, apiContainerLogLevel, @@ -155,8 +174,9 @@ func (creator *EnclaveCreator) CreateEnclave( } // Everything started successfully, so the responsibility of deleting the enclave is now transferred to the caller - shouldDestroyEnclave = false shouldStopApiContainer = false + shouldDeleteLogsCollector = false + shouldDestroyEnclave = false return newEnclaveInfo, nil }