Skip to content

Commit

Permalink
ensure that persitent keys are unique
Browse files Browse the repository at this point in the history
  • Loading branch information
h4ck3rk3y committed Jan 5, 2024
1 parent 36bdc5b commit e2784c4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,15 @@ func validateSingleService(validatorEnvironment *startosis_validator.ValidatorEn
return startosis_errors.NewValidationError(invalidServiceNameErrorText(serviceName))
}

// TODO perhaps add AddPersistentKey DoesPersistentKeyExist methods to the validator environment checks for it here
if persistentDirectories := serviceConfig.GetPersistentDirectories(); persistentDirectories != nil {
for _, directory := range persistentDirectories.ServiceDirpathToPersistentDirectory {
if !service_directory.IsPersistentKeyValid(directory.PersistentKey) {
return startosis_errors.NewValidationError(invalidPersistentKeyErrorText(directory.PersistentKey))
}
if validatorEnvironment.DoesPersistentKeyExist(directory.PersistentKey) == startosis_validator.ComponentCreatedOrUpdatedDuringPackageRun {
return startosis_errors.NewValidationError("There was an error validating '%s' as persistent key '%s' already exists inside the enclave")

Check failure on line 80 in core/server/api_container/server/startosis_engine/kurtosis_instruction/add_service/add_service_shared.go

View workflow job for this annotation

GitHub Actions / golang-lint

printf: github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/startosis_errors.NewValidationError format %s reads arg #1, but call has 0 args (govet)
}
validatorEnvironment.AddPersistentKey(directory.PersistentKey)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/image_build_spec"
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/image_download_mode"
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/service"
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/service_directory"
"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/startosis_errors"
"github.com/sirupsen/logrus"
)
Expand All @@ -15,6 +16,7 @@ type ValidatorEnvironment struct {
imagesToBuild map[string]*image_build_spec.ImageBuildSpec
serviceNames map[service.ServiceName]ComponentExistence
artifactNames map[string]ComponentExistence
persistentKeys map[service_directory.DirectoryPersistentKey]ComponentExistence
serviceNameToPrivatePortIDs map[service.ServiceName][]string
availableCpuInMilliCores compute_resources.CpuMilliCores
availableMemoryInMegaBytes compute_resources.MemoryInMegaBytes
Expand Down Expand Up @@ -160,3 +162,15 @@ func (environment *ValidatorEnvironment) HasEnoughMemory(memoryToConsume uint64,
}
return startosis_errors.NewValidationError("service '%v' requires '%v' megabytes of memory but based on our calculation we will only have '%v' megabytes available at the time we start the service", serviceNameForLogging, memoryToConsume, environment.availableMemoryInMegaBytes)
}

func (environment *ValidatorEnvironment) AddPersistentKey(persistentKey service_directory.DirectoryPersistentKey) {
environment.persistentKeys[persistentKey] = ComponentCreatedOrUpdatedDuringPackageRun
}

func (environment *ValidatorEnvironment) DoesPersistentKeyExist(persistentKey service_directory.DirectoryPersistentKey) ComponentExistence {
persistentKeyExistence, found := environment.persistentKeys[persistentKey]
if !found {
return ComponentNotFound
}
return persistentKeyExistence
}
2 changes: 1 addition & 1 deletion docs/docs/api-reference/starlark-reference/directory.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ the above example, `files_artifact_1` is a files artifact name. (see [upload_fil
on how to create file artifacts).

A persistent directory, as its name indicates, persists over service updates and restarts. It is uniquely identified
by its `persistent_key` and the service ID on which it is being used (a persistent directory cannot be shared across
by its `persistent_key` (a persistent directory cannot be shared across
multiple services). When it is first created, it will be empty. The service can write anything in it. When the service
gets updated, the data in it persists. It is particularly useful for a service's data directory, logs directory, etc.

Expand Down

0 comments on commit e2784c4

Please sign in to comment.