Skip to content

Commit

Permalink
feat: allow disabling tini (#2425)
Browse files Browse the repository at this point in the history
Closes #2405

---------

Co-authored-by: leoporoli <[email protected]>
  • Loading branch information
h4ck3rk3y and leoporoli authored May 7, 2024
1 parent 07d6ebf commit 7927da4
Show file tree
Hide file tree
Showing 21 changed files with 109 additions and 503 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,7 @@ func createStartServiceOperation(
privateIPAddrPlaceholder := serviceConfig.GetPrivateIPAddrPlaceholder()
user := serviceConfig.GetUser()
filesToBeMoved := serviceConfig.GetFilesToBeMoved()
tiniEnabled := serviceConfig.GetTiniEnabled()

// We replace the placeholder value with the actual private IP address
privateIPAddrStr := privateIpAddr.String()
Expand Down Expand Up @@ -699,14 +700,16 @@ func createStartServiceOperation(
).WithSkipAddingToBridgeNetworkIfStaticIpIsSet(
skipAddingUserServiceToBridgeNetwork,
).WithContainerInitEnabled(
true,
tiniEnabled,
).WithVolumeMounts(
volumeMounts,
).WithLoggingDriver(
fluentdLoggingDriverCnfg,
).WithRestartPolicy(
restartPolicy,
).WithUser(user)
).WithUser(
user,
)

if entrypointArgs != nil {
createAndStartArgsBuilder.WithEntrypointArgs(entrypointArgs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,31 +74,11 @@ type privateServiceConfig struct {
ImageDownloadMode image_download_mode.ImageDownloadMode

FilesToBeMoved map[string]string

TiniEnabled bool
}

func CreateServiceConfig(
containerImageName string,
imageBuildSpec *image_build_spec.ImageBuildSpec,
imageRegistrySpec *image_registry_spec.ImageRegistrySpec,
nixBuildSpec *nix_build_spec.NixBuildSpec,
privatePorts map[string]*port_spec.PortSpec,
publicPorts map[string]*port_spec.PortSpec,
entrypointArgs []string,
cmdArgs []string,
envVars map[string]string,
filesArtifactExpansion *service_directory.FilesArtifactsExpansion,
persistentDirectories *service_directory.PersistentDirectories,
cpuAllocationMillicpus uint64,
memoryAllocationMegabytes uint64,
privateIPAddrPlaceholder string,
minCpuMilliCpus uint64,
minMemoryMegaBytes uint64,
labels map[string]string,
user *service_user.ServiceUser,
tolerations []v1.Toleration,
nodeSelectors map[string]string,
imageDownloadMode image_download_mode.ImageDownloadMode,
) (*ServiceConfig, error) {
func CreateServiceConfig(containerImageName string, imageBuildSpec *image_build_spec.ImageBuildSpec, imageRegistrySpec *image_registry_spec.ImageRegistrySpec, nixBuildSpec *nix_build_spec.NixBuildSpec, privatePorts map[string]*port_spec.PortSpec, publicPorts map[string]*port_spec.PortSpec, entrypointArgs []string, cmdArgs []string, envVars map[string]string, filesArtifactExpansion *service_directory.FilesArtifactsExpansion, persistentDirectories *service_directory.PersistentDirectories, cpuAllocationMillicpus uint64, memoryAllocationMegabytes uint64, privateIPAddrPlaceholder string, minCpuMilliCpus uint64, minMemoryMegaBytes uint64, labels map[string]string, user *service_user.ServiceUser, tolerations []v1.Toleration, nodeSelectors map[string]string, imageDownloadMode image_download_mode.ImageDownloadMode, tiniEnabled bool) (*ServiceConfig, error) {

if err := ValidateServiceConfigLabels(labels); err != nil {
return nil, stacktrace.Propagate(err, "Invalid service config labels '%+v'", labels)
Expand Down Expand Up @@ -128,6 +108,7 @@ func CreateServiceConfig(
NodeSelectors: nodeSelectors,
ImageDownloadMode: imageDownloadMode,
FilesToBeMoved: map[string]string{},
TiniEnabled: tiniEnabled,
}
return &ServiceConfig{internalServiceConfig}, nil
}
Expand Down Expand Up @@ -278,6 +259,10 @@ func (serviceConfig *ServiceConfig) GetFilesToBeMoved() map[string]string {
return serviceConfig.privateServiceConfig.FilesToBeMoved
}

func (serviceConfig *ServiceConfig) GetTiniEnabled() bool {
return serviceConfig.privateServiceConfig.TiniEnabled
}

func (serviceConfig *ServiceConfig) UnmarshalJSON(data []byte) error {

// Suppressing exhaustruct requirement because we want an object with zero values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,32 +65,10 @@ func TestServiceConfigMarshallers(t *testing.T) {
}

func getServiceConfigForTest(t *testing.T, imageName string) *ServiceConfig {
serviceConfig, err := CreateServiceConfig(
imageName,
testImageBuildSpec(),
testImageRegistrySpec(),
testNixBuildSpec(),
testPrivatePorts(t),
testPublicPorts(t),
[]string{"bin", "bash", "ls"},
[]string{"-l", "-a"},
testEnvVars(),
testFilesArtifactExpansion(),
testPersistentDirectory(),
500,
1024,
"IP-ADDRESS",
100,
512,
map[string]string{
"test-label-key": "test-label-value",
"test-second-label-key": "test-second-label-value",
},
testServiceUser(),
testToleration(),
testNodeSelectors(),
testImageDownloadMode(),
)
serviceConfig, err := CreateServiceConfig(imageName, testImageBuildSpec(), testImageRegistrySpec(), testNixBuildSpec(), testPrivatePorts(t), testPublicPorts(t), []string{"bin", "bash", "ls"}, []string{"-l", "-a"}, testEnvVars(), testFilesArtifactExpansion(), testPersistentDirectory(), 500, 1024, "IP-ADDRESS", 100, 512, map[string]string{
"test-label-key": "test-label-value",
"test-second-label-key": "test-second-label-value",
}, testServiceUser(), testToleration(), testNodeSelectors(), testImageDownloadMode(), true)
require.NoError(t, err)
return serviceConfig
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,34 +304,12 @@ func getServiceRegistrationWithDataForTest(
}

func getServiceConfigForTest(t *testing.T, imageName string) *service.ServiceConfig {
serviceConfig, err := service.CreateServiceConfig(
imageName,
nil,
nil,
nil,
testPrivatePorts(t),
testPublicPorts(t),
[]string{"bin", "bash", "ls"},
[]string{"-l", "-a"},
testEnvVars(),
testFilesArtifactExpansion(),
testPersistentDirectory(),
500,
1024,
"IP-ADDRESS",
100,
512,
map[string]string{
"test-label-key": "test-label-value",
"test-second-label-key": "test-second-label-value",
},
nil,
nil,
map[string]string{
"disktype": "ssd",
},
image_download_mode.ImageDownloadMode_Missing,
)
serviceConfig, err := service.CreateServiceConfig(imageName, nil, nil, nil, testPrivatePorts(t), testPublicPorts(t), []string{"bin", "bash", "ls"}, []string{"-l", "-a"}, testEnvVars(), testFilesArtifactExpansion(), testPersistentDirectory(), 500, 1024, "IP-ADDRESS", 100, 512, map[string]string{
"test-label-key": "test-label-value",
"test-second-label-key": "test-second-label-value",
}, nil, nil, map[string]string{
"disktype": "ssd",
}, image_download_mode.ImageDownloadMode_Missing, true)
require.NoError(t, err)
return serviceConfig
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1205,29 +1205,7 @@ func openFreeTCPAndUDPLocalHostPortAddressesForTesting() (*netip.AddrPort, *neti
}

func testServiceConfig(t *testing.T, imageName string) *service.ServiceConfig {
serviceConfig, err := service.CreateServiceConfig(
imageName,
nil,
nil,
nil,
nil,
nil,
nil,
nil,
nil,
nil,
nil,
0,
0,
"",
0,
0,
map[string]string{},
nil,
nil,
map[string]string{},
image_download_mode.ImageDownloadMode_Missing,
)
serviceConfig, err := service.CreateServiceConfig(imageName, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 0, 0, "", 0, 0, map[string]string{}, nil, nil, map[string]string{}, image_download_mode.ImageDownloadMode_Missing, true)
require.NoError(t, err)
return serviceConfig
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,28 +65,7 @@ func TestPutNewServiceConfig(t *testing.T) {
}

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)
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, true)
}

func getEnclaveDBForTest(t *testing.T) *enclave_db.EnclaveDB {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,29 +196,7 @@ func replaceMagicStrings(
}
}

renderedServiceConfig, err := service.CreateServiceConfig(
serviceConfig.GetContainerImageName(),
serviceConfig.GetImageBuildSpec(),
serviceConfig.GetImageRegistrySpec(),
serviceConfig.GetNixBuildSpec(),
serviceConfig.GetPrivatePorts(),
serviceConfig.GetPublicPorts(),
entrypoints,
cmdArgs,
envVars,
serviceConfig.GetFilesArtifactsExpansion(),
serviceConfig.GetPersistentDirectories(),
serviceConfig.GetCPUAllocationMillicpus(),
serviceConfig.GetMemoryAllocationMegabytes(),
serviceConfig.GetPrivateIPAddrPlaceholder(),
serviceConfig.GetMinCPUAllocationMillicpus(),
serviceConfig.GetMinMemoryAllocationMegabytes(),
serviceConfig.GetLabels(),
serviceConfig.GetUser(),
serviceConfig.GetTolerations(),
serviceConfig.GetNodeSelectors(),
serviceConfig.GetImageDownloadMode(),
)
renderedServiceConfig, err := service.CreateServiceConfig(serviceConfig.GetContainerImageName(), serviceConfig.GetImageBuildSpec(), serviceConfig.GetImageRegistrySpec(), serviceConfig.GetNixBuildSpec(), serviceConfig.GetPrivatePorts(), serviceConfig.GetPublicPorts(), entrypoints, cmdArgs, envVars, serviceConfig.GetFilesArtifactsExpansion(), serviceConfig.GetPersistentDirectories(), serviceConfig.GetCPUAllocationMillicpus(), serviceConfig.GetMemoryAllocationMegabytes(), serviceConfig.GetPrivateIPAddrPlaceholder(), serviceConfig.GetMinCPUAllocationMillicpus(), serviceConfig.GetMinMemoryAllocationMegabytes(), serviceConfig.GetLabels(), serviceConfig.GetUser(), serviceConfig.GetTolerations(), serviceConfig.GetNodeSelectors(), serviceConfig.GetImageDownloadMode(), serviceConfig.GetTiniEnabled())

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 @@ -38,29 +38,7 @@ func TestAddServiceShared_EntryPointArgsRuntimeValueAreReplaced(t *testing.T) {
runtimeValue := fmt.Sprintf(magic_string_helper.RuntimeValueReplacementPlaceholderFormat, stringValueUuid, runtimeValueName)

serviceName := service.ServiceName("example-datastore-server-2")
serviceConfig, err := service.CreateServiceConfig(
testContainerImageName,
nil,
nil,
nil,
nil,
nil,
[]string{"-- " + runtimeValue},
nil,
nil,
nil,
nil,
0,
0,
"",
0,
0,
map[string]string{},
nil,
nil,
map[string]string{},
image_download_mode.ImageDownloadMode_Missing,
)
serviceConfig, err := service.CreateServiceConfig(testContainerImageName, nil, nil, nil, nil, nil, []string{"-- " + runtimeValue}, nil, nil, nil, nil, 0, 0, "", 0, 0, map[string]string{}, nil, nil, map[string]string{}, image_download_mode.ImageDownloadMode_Missing, true)
require.NoError(t, err)

replacedServiceName, replacedServiceConfig, err := replaceMagicStrings(runtimeValueStore, serviceName, serviceConfig)
Expand All @@ -86,29 +64,7 @@ func TestAddServiceShared_CmdArgsRuntimeValueAreReplaced(t *testing.T) {
runtimeValue := fmt.Sprintf(magic_string_helper.RuntimeValueReplacementPlaceholderFormat, stringValueUuid, runtimeValueName)

serviceName := service.ServiceName("example-datastore-server-2")
serviceConfig, err := service.CreateServiceConfig(
testContainerImageName,
nil,
nil,
nil,
nil,
nil,
nil,
[]string{"bash", "-c", "sleep " + runtimeValue},
nil,
nil,
nil,
0,
0,
"",
0,
0,
map[string]string{},
nil,
nil,
map[string]string{},
image_download_mode.ImageDownloadMode_Missing,
)
serviceConfig, err := service.CreateServiceConfig(testContainerImageName, nil, nil, nil, nil, nil, nil, []string{"bash", "-c", "sleep " + runtimeValue}, nil, nil, nil, 0, 0, "", 0, 0, map[string]string{}, nil, nil, map[string]string{}, image_download_mode.ImageDownloadMode_Missing, true)
require.NoError(t, err)

replacedServiceName, replacedServiceConfig, err := replaceMagicStrings(runtimeValueStore, serviceName, serviceConfig)
Expand All @@ -134,31 +90,9 @@ func TestAddServiceShared_EnvVarsWithRuntimeValueAreReplaced(t *testing.T) {
runtimeValue := fmt.Sprintf(magic_string_helper.RuntimeValueReplacementPlaceholderFormat, stringValueUuid, runtimeValueName)

serviceName := service.ServiceName("example-datastore-server-2")
serviceConfig, err := service.CreateServiceConfig(
testContainerImageName,
nil,
nil,
nil,
nil,
nil,
nil,
nil,
map[string]string{
"PORT": runtimeValue,
},
nil,
nil,
0,
0,
"",
0,
0,
map[string]string{},
nil,
nil,
map[string]string{},
image_download_mode.ImageDownloadMode_Missing,
)
serviceConfig, err := service.CreateServiceConfig(testContainerImageName, nil, nil, nil, nil, nil, nil, nil, map[string]string{
"PORT": runtimeValue,
}, nil, nil, 0, 0, "", 0, 0, map[string]string{}, nil, nil, map[string]string{}, image_download_mode.ImageDownloadMode_Missing, true)
require.NoError(t, err)

replacedServiceName, replacedServiceConfig, err := replaceMagicStrings(runtimeValueStore, serviceName, serviceConfig)
Expand Down Expand Up @@ -187,29 +121,7 @@ func TestAddServiceShared_ServiceNameWithRuntimeValuesAreReplaced(t *testing.T)
stringRuntimeValue := fmt.Sprintf(magic_string_helper.RuntimeValueReplacementPlaceholderFormat, stringValueUuid, valueName)

serviceName := service.ServiceName(stringRuntimeValue)
serviceConfig, err := service.CreateServiceConfig(
testContainerImageName,
nil,
nil,
nil,
nil,
nil,
nil,
nil,
nil,
nil,
nil,
0,
0,
"",
0,
0,
map[string]string{},
nil,
nil,
map[string]string{},
image_download_mode.ImageDownloadMode_Missing,
)
serviceConfig, err := service.CreateServiceConfig(testContainerImageName, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 0, 0, "", 0, 0, map[string]string{}, nil, nil, map[string]string{}, image_download_mode.ImageDownloadMode_Missing, true)
require.NoError(t, err)

replacedServiceName, _, err := replaceMagicStrings(runtimeValueStore, serviceName, serviceConfig)
Expand Down
Loading

0 comments on commit 7927da4

Please sign in to comment.