Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: image download mode always applies to k8s as well #2271

Merged
merged 10 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package user_services_functions
import (
"context"
"fmt"
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/image_download_mode"
h4ck3rk3y marked this conversation as resolved.
Show resolved Hide resolved
"strings"

"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/service_user"
Expand Down Expand Up @@ -311,6 +312,7 @@ func createStartServiceOperation(
user := serviceConfig.GetUser()
tolerations := serviceConfig.GetTolerations()
nodeSelectors := serviceConfig.GetNodeSelectors()
imageDownloadMode := serviceConfig.GetImageDownloadMode()

matchingObjectAndResources, found := servicesObjectsAndResources[serviceUuid]
if !found {
Expand Down Expand Up @@ -401,6 +403,7 @@ func createStartServiceOperation(
minCpuAllocationMilliCpus,
minMemoryAllocationMegabytes,
user,
imageDownloadMode,
)
if err != nil {
return nil, stacktrace.Propagate(err, "An error occurred creating the container specs for the user service pod with image '%v'", containerImageName)
Expand Down Expand Up @@ -640,6 +643,7 @@ func getUserServicePodContainerSpecs(
minCpuAllocationMilliCpus uint64,
minMemoryAllocationMegabytes uint64,
user *service_user.ServiceUser,
imageDownloadMode image_download_mode.ImageDownloadMode,
) ([]apiv1.Container, error) {

var containerEnvVars []apiv1.EnvVar
Expand Down Expand Up @@ -682,18 +686,25 @@ func getUserServicePodContainerSpecs(
Limits: resourceLimitsList,
Requests: resourceRequestsList,
}

imagePullPolicy := apiv1.PullIfNotPresent
if imageDownloadMode == image_download_mode.ImageDownloadMode_Always {
imagePullPolicy = apiv1.PullAlways
}

// nolint: exhaustruct
containers := []apiv1.Container{
{
Name: userServiceContainerName,
Image: image,
// Yes, even though this is called "command" it actually corresponds to the Docker ENTRYPOINT
Command: entrypointArgs,
Args: cmdArgs,
Ports: kubernetesContainerPorts,
Env: containerEnvVars,
VolumeMounts: containerMounts,
Resources: resourceRequirements,
Command: entrypointArgs,
Args: cmdArgs,
Ports: kubernetesContainerPorts,
Env: containerEnvVars,
VolumeMounts: containerMounts,
Resources: resourceRequirements,
ImagePullPolicy: imagePullPolicy,

// NOTE: There are a bunch of other interesting Container options that we omitted for now but might
// want to specify in the future
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package service

import (
"encoding/json"
"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/image_build_spec"
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/image_registry_spec"
Expand Down Expand Up @@ -67,6 +68,8 @@ type privateServiceConfig struct {
Tolerations []v1.Toleration

NodeSelectors map[string]string

ImageDownloadMode image_download_mode.ImageDownloadMode
}

func CreateServiceConfig(
Expand All @@ -90,6 +93,7 @@ func CreateServiceConfig(
user *service_user.ServiceUser,
tolerations []v1.Toleration,
nodeSelectors map[string]string,
imageDownloadMode image_download_mode.ImageDownloadMode,
) (*ServiceConfig, error) {

if err := ValidateServiceConfigLabels(labels); err != nil {
Expand Down Expand Up @@ -118,6 +122,7 @@ func CreateServiceConfig(
User: user,
Tolerations: tolerations,
NodeSelectors: nodeSelectors,
ImageDownloadMode: imageDownloadMode,
}
return &ServiceConfig{internalServiceConfig}, nil
}
Expand Down Expand Up @@ -200,6 +205,10 @@ func (serviceConfig *ServiceConfig) GetTolerations() []v1.Toleration {
return serviceConfig.privateServiceConfig.Tolerations
}

func (serviceConfig *ServiceConfig) GetImageDownloadMode() image_download_mode.ImageDownloadMode {
return serviceConfig.privateServiceConfig.ImageDownloadMode
}

func (serviceConfig *ServiceConfig) MarshalJSON() ([]byte, error) {
return json.Marshal(serviceConfig.privateServiceConfig)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package service

import (
"encoding/json"
"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/image_registry_spec"
"testing"
"time"
Expand Down Expand Up @@ -88,6 +89,7 @@ func getServiceConfigForTest(t *testing.T, imageName string) *ServiceConfig {
testServiceUser(),
testToleration(),
testNodeSelectors(),
testImageDownloadMode(),
)
require.NoError(t, err)
return serviceConfig
Expand Down Expand Up @@ -216,3 +218,7 @@ func testNodeSelectors() map[string]string {
"disktype": "ssd",
}
}

func testImageDownloadMode() image_download_mode.ImageDownloadMode {
return image_download_mode.ImageDownloadMode_Missing
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package service_registration

import (
"fmt"
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/image_download_mode"
"math/rand"
"net"
"os"
Expand Down Expand Up @@ -329,6 +330,7 @@ func getServiceConfigForTest(t *testing.T, imageName string) *service.ServiceCon
map[string]string{
"disktype": "ssd",
},
image_download_mode.ImageDownloadMode_Missing,
)
require.NoError(t, err)
return serviceConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package service_network
import (
"context"
"fmt"
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/image_download_mode"
"net"
"net/netip"
"os"
Expand Down Expand Up @@ -1225,6 +1226,7 @@ func testServiceConfig(t *testing.T, imageName string) *service.ServiceConfig {
nil,
nil,
map[string]string{},
image_download_mode.ImageDownloadMode_Missing,
)
require.NoError(t, err)
return serviceConfig
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package startosis_engine

import (
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/image_download_mode"
"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/service_network"
"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/builtins"
"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/builtins/import_module"
Expand Down Expand Up @@ -63,10 +64,11 @@ func KurtosisPlanInstructions(
packageReplaceOptions map[string]string,
nonBlockingMode bool,
interpretationTimeValueStore *interpretation_time_value_store.InterpretationTimeValueStore,
imageDownloadMode image_download_mode.ImageDownloadMode,
) []*kurtosis_plan_instruction.KurtosisPlanInstruction {
return []*kurtosis_plan_instruction.KurtosisPlanInstruction{
add_service.NewAddService(serviceNetwork, runtimeValueStore, packageId, packageContentProvider, packageReplaceOptions, interpretationTimeValueStore),
add_service.NewAddServices(serviceNetwork, runtimeValueStore, packageId, packageContentProvider, packageReplaceOptions, interpretationTimeValueStore),
add_service.NewAddService(serviceNetwork, runtimeValueStore, packageId, packageContentProvider, packageReplaceOptions, interpretationTimeValueStore, imageDownloadMode),
add_service.NewAddServices(serviceNetwork, runtimeValueStore, packageId, packageContentProvider, packageReplaceOptions, interpretationTimeValueStore, imageDownloadMode),
get_service.NewGetService(interpretationTimeValueStore),
verify.NewVerify(runtimeValueStore),
exec.NewExec(serviceNetwork, runtimeValueStore),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package add_service
import (
"context"
"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/core/server/api_container/server/service_network"
"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/enclave_plan_persistence"
Expand Down Expand Up @@ -36,7 +37,8 @@ func NewAddService(
packageId string,
packageContentProvider startosis_packages.PackageContentProvider,
packageReplaceOptions map[string]string,
interpretationTimeValueStore *interpretation_time_value_store.InterpretationTimeValueStore) *kurtosis_plan_instruction.KurtosisPlanInstruction {
interpretationTimeValueStore *interpretation_time_value_store.InterpretationTimeValueStore,
imageDownloadMode image_download_mode.ImageDownloadMode) *kurtosis_plan_instruction.KurtosisPlanInstruction {
return &kurtosis_plan_instruction.KurtosisPlanInstruction{
KurtosisBaseBuiltin: &kurtosis_starlark_framework.KurtosisBaseBuiltin{
Name: AddServiceBuiltinName,
Expand Down Expand Up @@ -81,6 +83,8 @@ func NewAddService(

interpretationTimeValueStore: interpretationTimeValueStore,
description: "", // populated at interpretation time

imageDownloadMode: imageDownloadMode,
}
},

Expand Down Expand Up @@ -108,6 +112,8 @@ type AddServiceCapabilities struct {

resultUuid string
description string

imageDownloadMode image_download_mode.ImageDownloadMode
}

func (builtin *AddServiceCapabilities) Interpret(locatorOfModuleInWhichThisBuiltInIsBeingCalled string, arguments *builtin_argument.ArgumentValuesSet) (starlark.Value, *startosis_errors.InterpretationError) {
Expand All @@ -127,6 +133,7 @@ func (builtin *AddServiceCapabilities) Interpret(locatorOfModuleInWhichThisBuilt
builtin.packageId,
builtin.packageContentProvider,
builtin.packageReplaceOptions,
builtin.imageDownloadMode,
)
if interpretationErr != nil {
return nil, interpretationErr
Expand Down Expand Up @@ -259,6 +266,7 @@ func validateAndConvertConfigAndReadyCondition(
packageId string,
packageContentProvider startosis_packages.PackageContentProvider,
packageReplaceOptions map[string]string,
imageDownloadMode image_download_mode.ImageDownloadMode,
) (*service.ServiceConfig, *service_config.ReadyCondition, *startosis_errors.InterpretationError) {
config, ok := rawConfig.(*service_config.ServiceConfig)
if !ok {
Expand All @@ -269,7 +277,7 @@ func validateAndConvertConfigAndReadyCondition(
locatorOfModuleInWhichThisBuiltInIsBeingCalled,
packageId,
packageContentProvider,
packageReplaceOptions)
packageReplaceOptions, imageDownloadMode)
if interpretationErr != nil {
return nil, nil, interpretationErr
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ func replaceMagicStrings(
serviceConfig.GetUser(),
serviceConfig.GetTolerations(),
serviceConfig.GetNodeSelectors(),
serviceConfig.GetImageDownloadMode(),
)
if err != nil {
return "", nil, stacktrace.Propagate(err, "An error occurred creating a service config")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package add_service

import (
"fmt"
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/image_download_mode"
"os"
"testing"

Expand Down Expand Up @@ -58,6 +59,7 @@ func TestAddServiceShared_EntryPointArgsRuntimeValueAreReplaced(t *testing.T) {
nil,
nil,
map[string]string{},
image_download_mode.ImageDownloadMode_Missing,
)
require.NoError(t, err)

Expand Down Expand Up @@ -105,6 +107,7 @@ func TestAddServiceShared_CmdArgsRuntimeValueAreReplaced(t *testing.T) {
nil,
nil,
map[string]string{},
image_download_mode.ImageDownloadMode_Missing,
)
require.NoError(t, err)

Expand Down Expand Up @@ -154,6 +157,7 @@ func TestAddServiceShared_EnvVarsWithRuntimeValueAreReplaced(t *testing.T) {
nil,
nil,
map[string]string{},
image_download_mode.ImageDownloadMode_Missing,
)
require.NoError(t, err)

Expand Down Expand Up @@ -204,6 +208,7 @@ func TestAddServiceShared_ServiceNameWithRuntimeValuesAreReplaced(t *testing.T)
nil,
nil,
map[string]string{},
image_download_mode.ImageDownloadMode_Missing,
)
require.NoError(t, err)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package add_service
import (
"context"
"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/core/server/api_container/server/service_network"
"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/enclave_plan_persistence"
Expand Down Expand Up @@ -39,7 +40,8 @@ func NewAddServices(
packageId string,
packageContentProvider startosis_packages.PackageContentProvider,
packageReplaceOptions map[string]string,
interpretationTimeValueStore *interpretation_time_value_store.InterpretationTimeValueStore) *kurtosis_plan_instruction.KurtosisPlanInstruction {
interpretationTimeValueStore *interpretation_time_value_store.InterpretationTimeValueStore,
imageDownloadMode image_download_mode.ImageDownloadMode) *kurtosis_plan_instruction.KurtosisPlanInstruction {
return &kurtosis_plan_instruction.KurtosisPlanInstruction{
KurtosisBaseBuiltin: &kurtosis_starlark_framework.KurtosisBaseBuiltin{
Name: AddServicesBuiltinName,
Expand Down Expand Up @@ -71,9 +73,10 @@ func NewAddServices(
serviceConfigs: nil, // populated at interpretation time
interpretationTimeValueStore: interpretationTimeValueStore,

resultUuids: map[service.ServiceName]string{}, // populated at interpretation time
readyConditions: nil, // populated at interpretation time
description: "", // populated at interpretation time
resultUuids: map[service.ServiceName]string{}, // populated at interpretation time
readyConditions: nil, // populated at interpretation time
description: "", // populated at interpretation time
imageDownloadMode: imageDownloadMode,
}
},

Expand All @@ -99,6 +102,8 @@ type AddServicesCapabilities struct {

resultUuids map[service.ServiceName]string
description string

imageDownloadMode image_download_mode.ImageDownloadMode
}

func (builtin *AddServicesCapabilities) Interpret(locatorOfModuleInWhichThisBuiltInIsBeingCalled string, arguments *builtin_argument.ArgumentValuesSet) (starlark.Value, *startosis_errors.InterpretationError) {
Expand All @@ -113,6 +118,7 @@ func (builtin *AddServicesCapabilities) Interpret(locatorOfModuleInWhichThisBuil
builtin.packageId,
builtin.packageContentProvider,
builtin.packageReplaceOptions,
builtin.imageDownloadMode,
)
if interpretationErr != nil {
return nil, interpretationErr
Expand Down Expand Up @@ -416,6 +422,7 @@ func validateAndConvertConfigsAndReadyConditions(
packageId string,
packageContentProvider startosis_packages.PackageContentProvider,
packageReplaceOptions map[string]string,
imageDownloadMode image_download_mode.ImageDownloadMode,
) (
map[service.ServiceName]*service.ServiceConfig,
map[service.ServiceName]*service_config.ReadyCondition,
Expand Down Expand Up @@ -444,7 +451,7 @@ func validateAndConvertConfigsAndReadyConditions(
if !isDictValueAServiceConfig {
return nil, nil, startosis_errors.NewInterpretationError("One value of the '%s' dictionary is not a ServiceConfig (was '%s'). Values of this argument should correspond to the config of the service to be added", ConfigsArgName, reflect.TypeOf(dictValue))
}
apiServiceConfig, interpretationErr := serviceConfig.ToKurtosisType(serviceNetwork, locatorOfModuleInWhichThisBuiltInIsBeingCalled, packageId, packageContentProvider, packageReplaceOptions)
apiServiceConfig, interpretationErr := serviceConfig.ToKurtosisType(serviceNetwork, locatorOfModuleInWhichThisBuiltInIsBeingCalled, packageId, packageContentProvider, packageReplaceOptions, imageDownloadMode)
if interpretationErr != nil {
return nil, nil, interpretationErr
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ func repacaeMagicStringsInEnvVars(runtimeValueStore *runtime_value_store.Runtime
serviceConfig.GetUser(),
serviceConfig.GetTolerations(),
serviceConfig.GetNodeSelectors(),
serviceConfig.GetImageDownloadMode(),
)
if err != nil {
return nil, stacktrace.Propagate(err, "An error occurred creating a service config with env var magric strings replaced.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tasks
import (
"context"
"fmt"
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/image_download_mode"
"reflect"
"strings"
"time"
Expand Down Expand Up @@ -281,6 +282,7 @@ func getServiceConfig(
nil,
nil,
map[string]string{},
image_download_mode.ImageDownloadMode_Missing,
)
if err != nil {
return nil, stacktrace.Propagate(err, "An error occurred creating service config")
Expand Down
Loading
Loading