Skip to content

Commit

Permalink
move where logs collector is created
Browse files Browse the repository at this point in the history
  • Loading branch information
tedim52 committed Nov 29, 2023
1 parent c760e9c commit 98b2b4b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ const (

shouldFetchStoppedContainersWhenDumpingEnclave = true

defaultHttpLogsCollectorPortNum = uint16(9712)
defaultTcpLogsCollectorPortNum = uint16(9713)

serializedArgs = "SERIALIZED_ARGS"
)

Expand Down Expand Up @@ -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
Expand Down
22 changes: 21 additions & 1 deletion engine/server/engine/enclave_manager/enclave_creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 98b2b4b

Please sign in to comment.