-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Description Adds `set_service` instruction which can be used to override the service config of a service added earlier in the plan. This can be really useful for two cases: 1. A user wants to set a specific image (or other config) for a service in a package but the package author has not made the image configurable. This can be done by appending `set_service` to the plan. ex. ``` postgres = import_module("github.com/kurtosis-tech/postgres-package/main.star") def run(plan, args): postgres.run(plan) plan.set_service(name="postgres", config=ServiceConfig(image="postgres:bullseye")) ``` 2. A user wants to swap out the image (or other config) of a service running in an enclave. This can be done by appending `set_service` to the plan and enclave editing. ex. https://www.loom.com/share/f88d0f5555dd49b0aeabc55c5ed41d43 This instruction has some functionality missing such as overriding ports, env vars, and cmd/entrypoint as these require special handling of future references and handling consecutive set service instructions properly but functionality can be added iteratively in future PRs. ## Is this change user facing? YES ## References: #2057
- Loading branch information
Showing
14 changed files
with
841 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
.../startosis_engine/interpretation_time_value_store/interpretation_time_value_store_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package interpretation_time_value_store | ||
|
||
import ( | ||
"fmt" | ||
"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/database_accessors/enclave_db" | ||
"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/kurtosis_instruction/shared_helpers" | ||
"github.com/stretchr/testify/require" | ||
bolt "go.etcd.io/bbolt" | ||
"os" | ||
"testing" | ||
) | ||
|
||
const ( | ||
testServiceName = service.ServiceName("datastore-service") | ||
testContainerImageName = "datastore-image" | ||
enclaveDbFilePerm = 0666 | ||
) | ||
|
||
func TestGetServiceConfigReturnsError(t *testing.T) { | ||
enclaveDb := getEnclaveDBForTest(t) | ||
dummySerde := shared_helpers.NewDummyStarlarkValueSerDeForTest() | ||
itvs, err := CreateInterpretationTimeValueStore(enclaveDb, dummySerde) | ||
require.NoError(t, err) | ||
|
||
// no service config exists in store | ||
_, err = itvs.GetServiceConfig(testServiceName) | ||
require.Error(t, err) | ||
} | ||
|
||
func TestPutServiceConfig(t *testing.T) { | ||
enclaveDb := getEnclaveDBForTest(t) | ||
dummySerde := shared_helpers.NewDummyStarlarkValueSerDeForTest() | ||
itvs, err := CreateInterpretationTimeValueStore(enclaveDb, dummySerde) | ||
require.NoError(t, err) | ||
|
||
expectedServiceConfig, err := getTestServiceConfigForService(testServiceName, "latest") | ||
require.NoError(t, err) | ||
|
||
itvs.PutServiceConfig(testServiceName, expectedServiceConfig) | ||
|
||
actualServiceConfig, err := itvs.GetServiceConfig(testServiceName) | ||
require.NoError(t, err) | ||
require.Equal(t, expectedServiceConfig.GetContainerImageName(), actualServiceConfig.GetContainerImageName()) | ||
} | ||
|
||
func TestPutNewServiceConfig(t *testing.T) { | ||
enclaveDb := getEnclaveDBForTest(t) | ||
dummySerde := shared_helpers.NewDummyStarlarkValueSerDeForTest() | ||
itvs, err := CreateInterpretationTimeValueStore(enclaveDb, dummySerde) | ||
require.NoError(t, err) | ||
|
||
oldServiceConfig, err := getTestServiceConfigForService(testServiceName, "older") | ||
require.NoError(t, err) | ||
itvs.PutServiceConfig(testServiceName, oldServiceConfig) | ||
|
||
newerServiceConfig, err := getTestServiceConfigForService(testServiceName, "latest") | ||
require.NoError(t, err) | ||
itvs.SetServiceConfig(testServiceName, newerServiceConfig) | ||
|
||
actualNewerServiceConfig, err := itvs.GetNewServiceConfig(testServiceName) | ||
require.NoError(t, err) | ||
require.Equal(t, newerServiceConfig.GetContainerImageName(), actualNewerServiceConfig.GetContainerImageName()) | ||
} | ||
|
||
func getTestServiceConfigForService(name service.ServiceName, imageTag string) (*service.ServiceConfig, error) { | ||
return service.CreateServiceConfig( | ||
fmt.Sprintf("%v-%v:%v", name, testContainerImageName, imageTag), | ||
nil, | ||
nil, | ||
nil, | ||
nil, | ||
nil, | ||
[]string{}, | ||
[]string{}, | ||
map[string]string{}, | ||
nil, | ||
nil, | ||
0, | ||
0, | ||
"IP-ADDRESS", | ||
0, | ||
0, | ||
map[string]string{}, | ||
nil, | ||
nil, | ||
nil, | ||
image_download_mode.ImageDownloadMode_Always) | ||
} | ||
|
||
func getEnclaveDBForTest(t *testing.T) *enclave_db.EnclaveDB { | ||
file, err := os.CreateTemp("/tmp", "*.db") | ||
defer func() { | ||
err = os.Remove(file.Name()) | ||
require.NoError(t, err) | ||
}() | ||
|
||
require.NoError(t, err) | ||
db, err := bolt.Open(file.Name(), enclaveDbFilePerm, nil) | ||
require.NoError(t, err) | ||
enclaveDb := &enclave_db.EnclaveDB{ | ||
DB: db, | ||
} | ||
|
||
return enclaveDb | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.