@@ -2,7 +2,6 @@ package enclave_manager
22
33import (
44 "context"
5- "fmt"
65 "github.com/kurtosis-tech/kurtosis/api/golang/engine/kurtosis_engine_rpc_api_bindings"
76 "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/docker_manager/types"
87 "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface"
@@ -24,11 +23,11 @@ const (
2423
2524 apiContainerListenGrpcProxyPortNumInsideNetwork = uint16 (7444 )
2625
27- enclavesCleaningPhaseTitle = "enclaves"
28-
2926 getRandomEnclaveIdRetries = uint16 (5 )
3027
3128 validNumberOfUuidMatches = 1
29+
30+ errorDelimiter = ", "
3231)
3332
3433// TODO Move this to the KurtosisBackend to calculate!!
@@ -288,54 +287,34 @@ func (manager *EnclaveManager) Clean(ctx context.Context, shouldCleanAll bool) (
288287 manager .mutex .Lock ()
289288 defer manager .mutex .Unlock ()
290289 // TODO: Refactor with kurtosis backend
291- resultSuccessfullyRemovedArtifactsIds := map [string ]map [ string ] bool {}
290+ resultSuccessfullyRemovedArtifactsIds := map [string ]bool {}
292291
293- // Map of cleaning_phase_title -> (successfully_destroyed_object_id, object_destruction_errors, clean_error)
294- cleaningPhaseFunctions := map [string ]func () ([]string , []error , error ){
295- enclavesCleaningPhaseTitle : func () ([]string , []error , error ) {
296- return manager .cleanEnclaves (ctx , shouldCleanAll )
297- },
292+ successfullyRemovedArtifactIds , removalErrors , err := manager .cleanEnclaves (ctx , shouldCleanAll )
293+ if err != nil {
294+ return nil , stacktrace .Propagate (err , "An error occurred while cleaning enclaves with shouldCleanAll set to '%v'" , shouldCleanAll )
298295 }
299296
300- phasesWithErrors := []string {}
301- for phaseTitle , cleaningFunc := range cleaningPhaseFunctions {
302- logrus .Infof ("Cleaning %v..." , phaseTitle )
303- successfullyRemovedArtifactIds , removalErrors , err := cleaningFunc ()
304- if err != nil {
305- logrus .Errorf ("Errors occurred cleaning %v:\n %v" , phaseTitle , err )
306- phasesWithErrors = append (phasesWithErrors , phaseTitle )
307- continue
308- }
309-
310- if len (successfullyRemovedArtifactIds ) > 0 {
311- artifactIDs := map [string ]bool {}
312- logrus .Infof ("Successfully removed the following %v:" , phaseTitle )
313- sort .Strings (successfullyRemovedArtifactIds )
314- for _ , successfulArtifactId := range successfullyRemovedArtifactIds {
315- artifactIDs [successfulArtifactId ] = true
316- fmt .Fprintln (logrus .StandardLogger ().Out , successfulArtifactId )
317- }
318- resultSuccessfullyRemovedArtifactsIds [phaseTitle ] = artifactIDs
319- }
320-
321- if len (removalErrors ) > 0 {
322- logrus .Errorf ("Errors occurred removing the following %v:" , phaseTitle )
323- for _ , err := range removalErrors {
324- fmt .Fprintln (logrus .StandardLogger ().Out , "" )
325- fmt .Fprintln (logrus .StandardLogger ().Out , err .Error ())
326- }
327- phasesWithErrors = append (phasesWithErrors , phaseTitle )
328- continue
297+ if len (removalErrors ) > 0 {
298+ logrus .Errorf ("Errors occurred removing the following enclaves" )
299+ var removalErrorStrings []string
300+ for _ , err = range removalErrors {
301+ logrus .Errorf ("Error '%v'" , err .Error ())
302+ removalErrorStrings = append (removalErrorStrings , err .Error ())
329303 }
330- logrus .Infof ("Successfully cleaned %v" , phaseTitle )
304+ joinedRemovalErrors := strings .Join (removalErrorStrings , errorDelimiter )
305+ return nil , stacktrace .NewError ("Following errors occurred while removing some enclaves '%v'" , joinedRemovalErrors )
331306 }
332307
333- if len (phasesWithErrors ) > 0 {
334- errorStr := "Errors occurred cleaning " + strings .Join (phasesWithErrors , ", " )
335- return nil , stacktrace .NewError (errorStr )
308+ if len (successfullyRemovedArtifactIds ) > 0 {
309+ logrus .Infof ("Successfully removed the enclaves" )
310+ sort .Strings (successfullyRemovedArtifactIds )
311+ for _ , successfulArtifactId := range successfullyRemovedArtifactIds {
312+ resultSuccessfullyRemovedArtifactsIds [successfulArtifactId ] = true
313+ logrus .Infof ("Enclave Uuid '%v'" , successfulArtifactId )
314+ }
336315 }
337316
338- return resultSuccessfullyRemovedArtifactsIds [ enclavesCleaningPhaseTitle ] , nil
317+ return resultSuccessfullyRemovedArtifactsIds , nil
339318}
340319
341320func (manager * EnclaveManager ) GetEnclaveUuidForEnclaveIdentifier (ctx context.Context , enclaveIdentifier string ) (enclave.EnclaveUUID , error ) {
0 commit comments