Skip to content

Commit

Permalink
Apply image download mode via validator
Browse files Browse the repository at this point in the history
  • Loading branch information
lostbean committed Oct 7, 2023
1 parent 4ae76ff commit 4f483d2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 (
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -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,
Expand Down

0 comments on commit 4f483d2

Please sign in to comment.