From 4f483d2ce297d0d680740858b3d45e5520618215 Mon Sep 17 00:00:00 2001 From: lostbean Date: Fri, 6 Oct 2023 23:11:09 -0300 Subject: [PATCH] Apply image download mode via validator --- .../server/startosis_engine/startosis_runner.go | 2 +- .../server/startosis_engine/startosis_validator.go | 8 +++++--- .../startosis_validator/validator_environment.go | 4 +++- .../startosis_validator/validator_environment_test.go | 5 +++-- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/core/server/api_container/server/startosis_engine/startosis_runner.go b/core/server/api_container/server/startosis_engine/startosis_runner.go index 62dd7e5017..66889f2e6b 100644 --- a/core/server/api_container/server/startosis_engine/startosis_runner.go +++ b/core/server/api_container/server/startosis_engine/startosis_runner.go @@ -142,7 +142,7 @@ func (runner *StartosisRunner) Run( startingValidationMsg, defaultCurrentStepNumber, totalNumberOfInstructions) starlarkRunResponseLines <- progressInfo - validationErrorsChan := runner.startosisValidator.Validate(ctx, instructionsSequence) + validationErrorsChan := runner.startosisValidator.Validate(ctx, instructionsSequence, imageDownloadMode) if isRunFinished, isRunSuccessful := forwardKurtosisResponseLineChannelUntilSourceIsClosed(validationErrorsChan, starlarkRunResponseLines); isRunFinished { if !isRunSuccessful { logrus.Warnf("An error occurred validating the sequence of Kurtosis instructions. See logs above for more details") diff --git a/core/server/api_container/server/startosis_engine/startosis_validator.go b/core/server/api_container/server/startosis_engine/startosis_validator.go index 9fffdf7eac..d1a83caefc 100644 --- a/core/server/api_container/server/startosis_engine/startosis_validator.go +++ b/core/server/api_container/server/startosis_engine/startosis_validator.go @@ -3,6 +3,8 @@ package startosis_engine import ( "context" "fmt" + "strings" + "github.com/kurtosis-tech/kurtosis/api/golang/core/kurtosis_core_rpc_api_bindings" "github.com/kurtosis-tech/kurtosis/api/golang/core/lib/binding_constructors" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface" @@ -14,7 +16,6 @@ import ( "github.com/kurtosis-tech/kurtosis/core/server/commons/enclave_data_directory" "github.com/kurtosis-tech/stacktrace" "github.com/sirupsen/logrus" - "strings" ) const ( @@ -46,7 +47,7 @@ func NewStartosisValidator(kurtosisBackend *backend_interface.KurtosisBackend, s } } -func (validator *StartosisValidator) Validate(ctx context.Context, instructionsSequence []*instructions_plan.ScheduledInstruction) <-chan *kurtosis_core_rpc_api_bindings.StarlarkRunResponseLine { +func (validator *StartosisValidator) Validate(ctx context.Context, instructionsSequence []*instructions_plan.ScheduledInstruction, image_download_mode string) <-chan *kurtosis_core_rpc_api_bindings.StarlarkRunResponseLine { starlarkRunResponseLineStream := make(chan *kurtosis_core_rpc_api_bindings.StarlarkRunResponseLine) go func() { defer close(starlarkRunResponseLineStream) @@ -85,7 +86,8 @@ func (validator *StartosisValidator) Validate(ctx context.Context, instructionsS serviceNamePortIdMapping, availableCpuInMilliCores, availableMemoryInMegaBytes, - isResourceInformationComplete) + isResourceInformationComplete, + image_download_mode) isValidationFailure = isValidationFailure || validator.validateAndUpdateEnvironment(instructionsSequence, environment, starlarkRunResponseLineStream) diff --git a/core/server/api_container/server/startosis_engine/startosis_validator/validator_environment.go b/core/server/api_container/server/startosis_engine/startosis_validator/validator_environment.go index e9f3d8d12a..b7c1a3aa70 100644 --- a/core/server/api_container/server/startosis_engine/startosis_validator/validator_environment.go +++ b/core/server/api_container/server/startosis_engine/startosis_validator/validator_environment.go @@ -18,9 +18,10 @@ type ValidatorEnvironment struct { isResourceInformationComplete bool minCPUByServiceName map[service.ServiceName]compute_resources.CpuMilliCores minMemoryByServiceName map[service.ServiceName]compute_resources.MemoryInMegaBytes + imageDownloadMode string } -func NewValidatorEnvironment(serviceNames map[service.ServiceName]bool, artifactNames map[string]bool, serviceNameToPrivatePortIds map[service.ServiceName][]string, availableCpuInMilliCores compute_resources.CpuMilliCores, availableMemoryInMegaBytes compute_resources.MemoryInMegaBytes, isResourceInformationComplete bool) *ValidatorEnvironment { +func NewValidatorEnvironment(serviceNames map[service.ServiceName]bool, artifactNames map[string]bool, serviceNameToPrivatePortIds map[service.ServiceName][]string, availableCpuInMilliCores compute_resources.CpuMilliCores, availableMemoryInMegaBytes compute_resources.MemoryInMegaBytes, isResourceInformationComplete bool, image_download_mode string) *ValidatorEnvironment { serviceNamesWithComponentExistence := map[service.ServiceName]ComponentExistence{} for serviceName := range serviceNames { serviceNamesWithComponentExistence[serviceName] = ComponentExistedBeforePackageRun @@ -39,6 +40,7 @@ func NewValidatorEnvironment(serviceNames map[service.ServiceName]bool, artifact isResourceInformationComplete: isResourceInformationComplete, minMemoryByServiceName: map[service.ServiceName]compute_resources.MemoryInMegaBytes{}, minCPUByServiceName: map[service.ServiceName]compute_resources.CpuMilliCores{}, + imageDownloadMode: image_download_mode, } } diff --git a/core/server/api_container/server/startosis_engine/startosis_validator/validator_environment_test.go b/core/server/api_container/server/startosis_engine/startosis_validator/validator_environment_test.go index 6827e1a7a8..3056aa089f 100644 --- a/core/server/api_container/server/startosis_engine/startosis_validator/validator_environment_test.go +++ b/core/server/api_container/server/startosis_engine/startosis_validator/validator_environment_test.go @@ -1,9 +1,10 @@ package startosis_validator import ( + "testing" + "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/service" "github.com/stretchr/testify/require" - "testing" ) const ( @@ -20,7 +21,7 @@ const ( func TestMultiplePortIdsForValidation(t *testing.T) { emptyInitialMapping := map[service.ServiceName][]string{} - validatorEnvironment := NewValidatorEnvironment(nil, nil, emptyInitialMapping, availableCpuInMilliCores, availableMemoryInBytes, isResourceInformationComplete) + validatorEnvironment := NewValidatorEnvironment(nil, nil, emptyInitialMapping, availableCpuInMilliCores, availableMemoryInBytes, isResourceInformationComplete, "missing") portIds := []string{ fooPortId, fizzPortId,