diff --git a/cli/cli/kurtosis_gateway/connection/provider.go b/cli/cli/kurtosis_gateway/connection/provider.go index a0f323cfba..fbe5bf4e23 100644 --- a/cli/cli/kurtosis_gateway/connection/provider.go +++ b/cli/cli/kurtosis_gateway/connection/provider.go @@ -2,12 +2,12 @@ package connection import ( "context" + "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_label_key" "net/url" "github.com/kurtosis-tech/kurtosis/api/golang/engine/kurtosis_engine_rpc_api_bindings" "github.com/kurtosis-tech/kurtosis/api/golang/engine/lib/kurtosis_context" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_manager" - "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/label_key_consts" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/label_value_consts" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/engine" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/port_spec" @@ -111,9 +111,9 @@ func (provider *GatewayConnectionProvider) ForUserServiceIfRunning(enclaveId str func (provider *GatewayConnectionProvider) getEnginePodPortforwardEndpoint(engineGuid engine.EngineGUID) (*url.URL, error) { engineLabels := map[string]string{ - label_key_consts.IDKubernetesLabelKey.GetString(): string(engineGuid), - label_key_consts.KurtosisResourceTypeKubernetesLabelKey.GetString(): label_value_consts.EngineKurtosisResourceTypeKubernetesLabelValue.GetString(), - label_key_consts.AppIDKubernetesLabelKey.GetString(): label_value_consts.AppIDKubernetesLabelValue.GetString(), + kubernetes_label_key.IDKubernetesLabelKey.GetString(): string(engineGuid), + kubernetes_label_key.KurtosisResourceTypeKubernetesLabelKey.GetString(): label_value_consts.EngineKurtosisResourceTypeKubernetesLabelValue.GetString(), + kubernetes_label_key.AppIDKubernetesLabelKey.GetString(): label_value_consts.AppIDKubernetesLabelValue.GetString(), } // Call k8s to find our engine namespace engineNamespaceList, err := provider.kubernetesManager.GetNamespacesByLabels(provider.providerContext, engineLabels) @@ -146,8 +146,8 @@ func (provider *GatewayConnectionProvider) getApiContainerPodPortforwardEndpoint // Get running API Container pods from Kubernetes apiContainerPodLabels := map[string]string{ - label_key_consts.KurtosisResourceTypeKubernetesLabelKey.GetString(): label_value_consts.APIContainerKurtosisResourceTypeKubernetesLabelValue.GetString(), - label_key_consts.AppIDKubernetesLabelKey.GetString(): label_value_consts.AppIDKubernetesLabelValue.GetString(), + kubernetes_label_key.KurtosisResourceTypeKubernetesLabelKey.GetString(): label_value_consts.APIContainerKurtosisResourceTypeKubernetesLabelValue.GetString(), + kubernetes_label_key.AppIDKubernetesLabelKey.GetString(): label_value_consts.AppIDKubernetesLabelValue.GetString(), } runningApiContainerPodNames, err := provider.getRunningPodNamesByLabels(enclaveNamespaceName, apiContainerPodLabels) if err != nil { @@ -191,9 +191,9 @@ func (provider *GatewayConnectionProvider) getEnclaveNamespaceNameForEnclaveId(e } enclaveLabels := map[string]string{ - label_key_consts.EnclaveUUIDKubernetesLabelKey.GetString(): enclaveId, - label_key_consts.KurtosisResourceTypeKubernetesLabelKey.GetString(): label_value_consts.EnclaveKurtosisResourceTypeKubernetesLabelValue.GetString(), - label_key_consts.AppIDKubernetesLabelKey.GetString(): label_value_consts.AppIDKubernetesLabelValue.GetString(), + kubernetes_label_key.EnclaveUUIDKubernetesLabelKey.GetString(): enclaveId, + kubernetes_label_key.KurtosisResourceTypeKubernetesLabelKey.GetString(): label_value_consts.EnclaveKurtosisResourceTypeKubernetesLabelValue.GetString(), + kubernetes_label_key.AppIDKubernetesLabelKey.GetString(): label_value_consts.AppIDKubernetesLabelValue.GetString(), } enclaveNamespaceList, err := provider.kubernetesManager.GetNamespacesByLabels(provider.providerContext, enclaveLabels) if err != nil { diff --git a/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/backend_creator/backend_creator.go b/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/backend_creator/backend_creator.go index 5fd7fc18cb..7695f72548 100644 --- a/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/backend_creator/backend_creator.go +++ b/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/backend_creator/backend_creator.go @@ -7,7 +7,7 @@ import ( "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/logs_collector_functions" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/docker_manager" - "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/label_key_consts" + "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_label_key" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/label_value_consts" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/metrics_reporting" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface" @@ -211,8 +211,8 @@ func getDockerKurtosisBackend( enclaveUuid := optionalApiContainerModeArgs.EnclaveID enclaveNetworkSearchLabels := map[string]string{ - label_key_consts.AppIDDockerLabelKey.GetString(): label_value_consts.AppIDDockerLabelValue.GetString(), - label_key_consts.IDDockerLabelKey.GetString(): string(enclaveUuid), + docker_label_key.AppIDDockerLabelKey.GetString(): label_value_consts.AppIDDockerLabelValue.GetString(), + docker_label_key.IDDockerLabelKey.GetString(): string(enclaveUuid), } matchingNetworks, err := dockerManager.GetNetworksByLabels(ctx, enclaveNetworkSearchLabels) if err != nil { diff --git a/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/docker_kurtosis_backend.go b/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/docker_kurtosis_backend.go index d1948e7d5e..628d785f07 100644 --- a/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/docker_kurtosis_backend.go +++ b/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/docker_kurtosis_backend.go @@ -2,6 +2,7 @@ package docker_kurtosis_backend import ( "context" + "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_label_key" "github.com/sirupsen/logrus" "io" "sync" @@ -16,7 +17,6 @@ import ( "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/docker_manager/types" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/docker_network_allocator" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider" - "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/label_key_consts" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/label_value_consts" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/compute_resources" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/container" @@ -488,8 +488,8 @@ func (backend *DockerKurtosisBackend) GetAvailableCPUAndMemory(ctx context.Conte // ==================================================================================================== func (backend *DockerKurtosisBackend) getEnclaveNetworkByEnclaveUuid(ctx context.Context, enclaveUuid enclave.EnclaveUUID) (*types.Network, error) { networkSearchLabels := map[string]string{ - label_key_consts.AppIDDockerLabelKey.GetString(): label_value_consts.AppIDDockerLabelValue.GetString(), - label_key_consts.EnclaveUUIDDockerLabelKey.GetString(): string(enclaveUuid), + docker_label_key.AppIDDockerLabelKey.GetString(): label_value_consts.AppIDDockerLabelValue.GetString(), + docker_label_key.EnclaveUUIDDockerLabelKey.GetString(): string(enclaveUuid), } enclaveNetworksFound, err := backend.dockerManager.GetNetworksByLabels(ctx, networkSearchLabels) @@ -513,9 +513,9 @@ func (backend *DockerKurtosisBackend) getEnclaveNetworkByEnclaveUuid(ctx context // Guaranteed to either return an enclave data volume name or throw an error func (backend *DockerKurtosisBackend) getEnclaveDataVolumeByEnclaveUuid(ctx context.Context, enclaveUuid enclave.EnclaveUUID) (string, error) { volumeSearchLabels := map[string]string{ - label_key_consts.AppIDDockerLabelKey.GetString(): label_value_consts.AppIDDockerLabelValue.GetString(), - label_key_consts.EnclaveUUIDDockerLabelKey.GetString(): string(enclaveUuid), - label_key_consts.VolumeTypeDockerLabelKey.GetString(): label_value_consts.EnclaveDataVolumeTypeDockerLabelValue.GetString(), + docker_label_key.AppIDDockerLabelKey.GetString(): label_value_consts.AppIDDockerLabelValue.GetString(), + docker_label_key.EnclaveUUIDDockerLabelKey.GetString(): string(enclaveUuid), + docker_label_key.VolumeTypeDockerLabelKey.GetString(): label_value_consts.EnclaveDataVolumeTypeDockerLabelValue.GetString(), } foundVolumes, err := backend.dockerManager.GetVolumesByLabels(ctx, volumeSearchLabels) if err != nil { diff --git a/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/docker_kurtosis_backend_api_container_functions.go b/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/docker_kurtosis_backend_api_container_functions.go index 19e91facbe..7d8483881e 100644 --- a/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/docker_kurtosis_backend_api_container_functions.go +++ b/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/docker_kurtosis_backend_api_container_functions.go @@ -2,6 +2,7 @@ package docker_kurtosis_backend import ( "context" + "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_label_key" "net" "time" @@ -12,7 +13,6 @@ import ( "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/docker_manager/types" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/docker_operation_parallelizer" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_port_spec_serializer" - "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/label_key_consts" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/label_value_consts" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/api_container" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/container" @@ -337,8 +337,8 @@ func (backend *DockerKurtosisBackend) DestroyAPIContainers(ctx context.Context, func (backend *DockerKurtosisBackend) getMatchingApiContainers(ctx context.Context, filters *api_container.APIContainerFilters) (map[string]*api_container.APIContainer, error) { apiContainerSearchLabels := map[string]string{ - label_key_consts.AppIDDockerLabelKey.GetString(): label_value_consts.AppIDDockerLabelValue.GetString(), - label_key_consts.ContainerTypeDockerLabelKey.GetString(): label_value_consts.APIContainerContainerTypeDockerLabelValue.GetString(), + docker_label_key.AppIDDockerLabelKey.GetString(): label_value_consts.AppIDDockerLabelValue.GetString(), + docker_label_key.ContainerTypeDockerLabelKey.GetString(): label_value_consts.APIContainerContainerTypeDockerLabelValue.GetString(), // NOTE: we do NOT use the enclave UUID label here, and instead do postfiltering, because Docker has no way to do disjunctive search! } allApiContainers, err := backend.dockerManager.GetContainersByLabels(ctx, apiContainerSearchLabels, consts.ShouldFetchAllContainersWhenRetrievingContainers) @@ -392,16 +392,16 @@ func getApiContainerObjectFromContainerInfo( allHostMachinePortBindings map[nat.Port]*nat.PortBinding, bridgeNetworkIpAddress string, ) (*api_container.APIContainer, error) { - enclaveId, found := labels[label_key_consts.EnclaveUUIDDockerLabelKey.GetString()] + enclaveId, found := labels[docker_label_key.EnclaveUUIDDockerLabelKey.GetString()] if !found { - return nil, stacktrace.NewError("Expected the API container's enclave UUID to be found under label '%v' but the label wasn't present", label_key_consts.EnclaveUUIDDockerLabelKey.GetString()) + return nil, stacktrace.NewError("Expected the API container's enclave UUID to be found under label '%v' but the label wasn't present", docker_label_key.EnclaveUUIDDockerLabelKey.GetString()) } - privateIpAddrStr, found := labels[label_key_consts.PrivateIPDockerLabelKey.GetString()] + privateIpAddrStr, found := labels[docker_label_key.PrivateIPDockerLabelKey.GetString()] if !found { return nil, stacktrace.NewError( "Couldn't find the API container's private IP using label '%v'", - label_key_consts.PrivateIPDockerLabelKey.GetString(), + docker_label_key.PrivateIPDockerLabelKey.GetString(), ) } privateIpAddr := net.ParseIP(privateIpAddrStr) @@ -459,9 +459,9 @@ func getPrivateApiContainerPorts(containerLabels map[string]string) ( resultGrpcPortSpec *port_spec.PortSpec, resultErr error, ) { - serializedPortSpecs, found := containerLabels[label_key_consts.PortSpecsDockerLabelKey.GetString()] + serializedPortSpecs, found := containerLabels[docker_label_key.PortSpecsDockerLabelKey.GetString()] if !found { - return nil, stacktrace.NewError("Expected to find port specs label '%v' but none was found", label_key_consts.PortSpecsDockerLabelKey.GetString()) + return nil, stacktrace.NewError("Expected to find port specs label '%v' but none was found", docker_label_key.PortSpecsDockerLabelKey.GetString()) } portSpecs, err := docker_port_spec_serializer.DeserializePortSpecs(serializedPortSpecs) diff --git a/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/docker_kurtosis_backend_enclave_functions.go b/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/docker_kurtosis_backend_enclave_functions.go index d5526f95a1..54aabf1a93 100644 --- a/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/docker_kurtosis_backend_enclave_functions.go +++ b/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/docker_kurtosis_backend_enclave_functions.go @@ -9,7 +9,7 @@ import ( "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/docker_manager" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/docker_manager/types" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/docker_operation_parallelizer" - "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/label_key_consts" + "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_label_key" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/label_value_consts" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/enclave" "github.com/kurtosis-tech/stacktrace" @@ -42,8 +42,8 @@ func (backend *DockerKurtosisBackend) CreateEnclave(ctx context.Context, enclave teardownCtx := context.Background() // Separate context for tearing stuff down in case the input context is cancelled searchNetworkLabels := map[string]string{ - label_key_consts.AppIDDockerLabelKey.GetString(): label_value_consts.AppIDDockerLabelValue.GetString(), - label_key_consts.EnclaveUUIDDockerLabelKey.GetString(): string(enclaveUuid), + docker_label_key.AppIDDockerLabelKey.GetString(): label_value_consts.AppIDDockerLabelValue.GetString(), + docker_label_key.EnclaveUUIDDockerLabelKey.GetString(): string(enclaveUuid), } networks, err := backend.dockerManager.GetNetworksByLabels(ctx, searchNetworkLabels) @@ -55,9 +55,9 @@ func (backend *DockerKurtosisBackend) CreateEnclave(ctx context.Context, enclave } volumeSearchLabels := map[string]string{ - label_key_consts.AppIDDockerLabelKey.GetString(): label_value_consts.AppIDDockerLabelValue.GetString(), - label_key_consts.EnclaveUUIDDockerLabelKey.GetString(): string(enclaveUuid), - label_key_consts.VolumeTypeDockerLabelKey.GetString(): label_value_consts.EnclaveDataVolumeTypeDockerLabelValue.GetString(), + docker_label_key.AppIDDockerLabelKey.GetString(): label_value_consts.AppIDDockerLabelValue.GetString(), + docker_label_key.EnclaveUUIDDockerLabelKey.GetString(): string(enclaveUuid), + docker_label_key.VolumeTypeDockerLabelKey.GetString(): label_value_consts.EnclaveDataVolumeTypeDockerLabelValue.GetString(), } foundVolumes, err := backend.dockerManager.GetVolumesByLabels(ctx, volumeSearchLabels) if err != nil { @@ -196,7 +196,7 @@ func (backend *DockerKurtosisBackend) GetEnclaves( // and extracts out whether enclave is running on production mode for _, container := range matchingNetworkInfo.containers { labels := container.GetLabels() - containerType, ok := labels[label_key_consts.ContainerTypeDockerLabelKey.GetString()] + containerType, ok := labels[docker_label_key.ContainerTypeDockerLabelKey.GetString()] if !ok { continue } @@ -308,8 +308,8 @@ func (backend *DockerKurtosisBackend) DumpEnclave( outputDirpath string, ) error { enclaveContainerSearchLabels := map[string]string{ - label_key_consts.AppIDDockerLabelKey.GetString(): label_value_consts.AppIDDockerLabelValue.GetString(), - label_key_consts.EnclaveUUIDDockerLabelKey.GetString(): string(enclaveUuid), + docker_label_key.AppIDDockerLabelKey.GetString(): label_value_consts.AppIDDockerLabelValue.GetString(), + docker_label_key.EnclaveUUIDDockerLabelKey.GetString(): string(enclaveUuid), } enclaveContainers, err := backend.dockerManager.GetContainersByLabels(ctx, enclaveContainerSearchLabels, shouldFetchStoppedContainersWhenDumpingEnclave) @@ -417,7 +417,7 @@ func (backend *DockerKurtosisBackend) getMatchingEnclaveNetworkInfo( error, ) { kurtosisNetworkLabels := map[string]string{ - label_key_consts.AppIDDockerLabelKey.GetString(): label_value_consts.AppIDDockerLabelValue.GetString(), + docker_label_key.AppIDDockerLabelKey.GetString(): label_value_consts.AppIDDockerLabelValue.GetString(), // NOTE: we don't search by enclave ID here because Docker has no way to do disjunctive search } @@ -511,8 +511,8 @@ func (backend *DockerKurtosisBackend) getAllEnclaveContainers( var containers []*types.Container searchLabels := map[string]string{ - label_key_consts.AppIDDockerLabelKey.GetString(): label_value_consts.AppIDDockerLabelValue.GetString(), - label_key_consts.EnclaveUUIDDockerLabelKey.GetString(): string(enclaveUuid), + docker_label_key.AppIDDockerLabelKey.GetString(): label_value_consts.AppIDDockerLabelValue.GetString(), + docker_label_key.EnclaveUUIDDockerLabelKey.GetString(): string(enclaveUuid), } containers, err := backend.dockerManager.GetContainersByLabels(ctx, searchLabels, shouldFetchStoppedContainersWhenGettingEnclaveStatus) if err != nil { @@ -530,8 +530,8 @@ func getAllEnclaveVolumes( var volumes []*volume.Volume searchLabels := map[string]string{ - label_key_consts.AppIDDockerLabelKey.GetString(): label_value_consts.AppIDDockerLabelValue.GetString(), - label_key_consts.EnclaveUUIDDockerLabelKey.GetString(): string(enclaveUuid), + docker_label_key.AppIDDockerLabelKey.GetString(): label_value_consts.AppIDDockerLabelValue.GetString(), + docker_label_key.EnclaveUUIDDockerLabelKey.GetString(): string(enclaveUuid), } volumes, err := dockerManager.GetVolumesByLabels(ctx, searchLabels) @@ -736,9 +736,9 @@ func destroyEnclaveNetworks( func getEnclaveUuidFromNetwork(network *types.Network) (enclave.EnclaveUUID, error) { labels := network.GetLabels() - enclaveUuidLabelValue, found := labels[label_key_consts.EnclaveUUIDDockerLabelKey.GetString()] + enclaveUuidLabelValue, found := labels[docker_label_key.EnclaveUUIDDockerLabelKey.GetString()] if !found { - return "", stacktrace.NewError("Expected to find network's label with key '%v' but none was found", label_key_consts.EnclaveUUIDDockerLabelKey.GetString()) + return "", stacktrace.NewError("Expected to find network's label with key '%v' but none was found", docker_label_key.EnclaveUUIDDockerLabelKey.GetString()) } enclaveUuid := enclave.EnclaveUUID(enclaveUuidLabelValue) return enclaveUuid, nil @@ -747,7 +747,7 @@ func getEnclaveUuidFromNetwork(network *types.Network) (enclave.EnclaveUUID, err func getEnclaveCreationTimeFromNetwork(network *types.Network) (*time.Time, error) { labels := network.GetLabels() - enclaveCreationTimeStr, found := labels[label_key_consts.EnclaveCreationTimeLabelKey.GetString()] + enclaveCreationTimeStr, found := labels[docker_label_key.EnclaveCreationTimeLabelKey.GetString()] if !found { //Handling retro-compatibility, enclaves that did not track enclave's creation time return nil, nil //TODO remove this return after 2023-01-01 @@ -766,7 +766,7 @@ func getEnclaveCreationTimeFromNetwork(network *types.Network) (*time.Time, erro func getEnclaveNameFromNetwork(network *types.Network) string { labels := network.GetLabels() - enclaveNameStr, found := labels[label_key_consts.EnclaveNameDockerLabelKey.GetString()] + enclaveNameStr, found := labels[docker_label_key.EnclaveNameDockerLabelKey.GetString()] if !found { //Handling retro-compatibility, enclaves that did not track enclave's name return "" diff --git a/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/engine_functions/engine_logs.go b/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/engine_functions/engine_logs.go index 8ecb2b8fb4..a2ad618902 100644 --- a/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/engine_functions/engine_logs.go +++ b/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/engine_functions/engine_logs.go @@ -5,15 +5,15 @@ import ( "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/consts" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/shared_helpers" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/docker_manager" - "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/label_key_consts" + "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_label_key" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/label_value_consts" "github.com/kurtosis-tech/stacktrace" ) func GetEngineLogs(ctx context.Context, outputDirpath string, dockerManager *docker_manager.DockerManager) error { engineContainerSearchLabels := map[string]string{ - label_key_consts.AppIDDockerLabelKey.GetString(): label_value_consts.AppIDDockerLabelValue.GetString(), - label_key_consts.ContainerTypeDockerLabelKey.GetString(): label_value_consts.EngineContainerTypeDockerLabelValue.GetString(), + docker_label_key.AppIDDockerLabelKey.GetString(): label_value_consts.AppIDDockerLabelValue.GetString(), + docker_label_key.ContainerTypeDockerLabelKey.GetString(): label_value_consts.EngineContainerTypeDockerLabelValue.GetString(), // NOTE: we do NOT use the engine GUID label here, and instead do postfiltering, because Docker has no way to do disjunctive search! } allEngineContainers, err := dockerManager.GetContainersByLabels(ctx, engineContainerSearchLabels, consts.ShouldFetchAllContainersWhenRetrievingContainers) diff --git a/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/engine_functions/shared_helpers.go b/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/engine_functions/shared_helpers.go index 3e5b11e698..5b70c9fea8 100644 --- a/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/engine_functions/shared_helpers.go +++ b/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/engine_functions/shared_helpers.go @@ -2,6 +2,7 @@ package engine_functions import ( "context" + "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_label_key" "net" "strconv" "strings" @@ -12,7 +13,6 @@ import ( "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/docker_manager" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/docker_manager/types" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_port_spec_serializer" - "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/label_key_consts" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/label_value_consts" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/container" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/engine" @@ -25,8 +25,8 @@ const emptyApplicationProtocol = "" // Gets engines matching the search filters, indexed by their container ID func getMatchingEngines(ctx context.Context, filters *engine.EngineFilters, dockerManager *docker_manager.DockerManager) (map[string]*engine.Engine, error) { engineContainerSearchLabels := map[string]string{ - label_key_consts.AppIDDockerLabelKey.GetString(): label_value_consts.AppIDDockerLabelValue.GetString(), - label_key_consts.ContainerTypeDockerLabelKey.GetString(): label_value_consts.EngineContainerTypeDockerLabelValue.GetString(), + docker_label_key.AppIDDockerLabelKey.GetString(): label_value_consts.AppIDDockerLabelValue.GetString(), + docker_label_key.ContainerTypeDockerLabelKey.GetString(): label_value_consts.EngineContainerTypeDockerLabelValue.GetString(), // NOTE: we do NOT use the engine GUID label here, and instead do postfiltering, because Docker has no way to do disjunctive search! } allEngineContainers, err := dockerManager.GetContainersByLabels(ctx, engineContainerSearchLabels, consts.ShouldFetchAllContainersWhenRetrievingContainers) @@ -73,11 +73,11 @@ func getEngineObjectFromContainerInfo( containerStatus types.ContainerStatus, allHostMachinePortBindings map[nat.Port]*nat.PortBinding, ) (*engine.Engine, error) { - engineGuidStr, found := labels[label_key_consts.GUIDDockerLabelKey.GetString()] + engineGuidStr, found := labels[docker_label_key.GUIDDockerLabelKey.GetString()] if !found { return nil, stacktrace.NewError( "Expected a '%v' label on engine container with GUID '%v', but none was found", - label_key_consts.GUIDDockerLabelKey.GetString(), + docker_label_key.GUIDDockerLabelKey.GetString(), containerId, ) } @@ -126,9 +126,9 @@ func getEnginePrivatePorts(containerLabels map[string]string) ( resultErr error, ) { - serializedPortSpecs, found := containerLabels[label_key_consts.PortSpecsDockerLabelKey.GetString()] + serializedPortSpecs, found := containerLabels[docker_label_key.PortSpecsDockerLabelKey.GetString()] if !found { - return nil, stacktrace.NewError("Expected to find port specs label '%v' but none was found", label_key_consts.PortSpecsDockerLabelKey.GetString()) + return nil, stacktrace.NewError("Expected to find port specs label '%v' but none was found", docker_label_key.PortSpecsDockerLabelKey.GetString()) } portSpecs, err := docker_port_spec_serializer.DeserializePortSpecs(serializedPortSpecs) diff --git a/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/logs_aggregator_functions/shared_helpers.go b/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/logs_aggregator_functions/shared_helpers.go index 7aac614e2d..b47b19ad6f 100644 --- a/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/logs_aggregator_functions/shared_helpers.go +++ b/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/logs_aggregator_functions/shared_helpers.go @@ -2,12 +2,12 @@ package logs_aggregator_functions import ( "context" + "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_label_key" "net" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/consts" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/docker_manager" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/docker_manager/types" - "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/label_key_consts" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/label_value_consts" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/container" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/logs_aggregator" @@ -49,8 +49,8 @@ func getLogsAggregatorObjectAndContainerId( // Returns nil [Container] object and false if no logs aggregator container is found func getLogsAggregatorContainer(ctx context.Context, dockerManager *docker_manager.DockerManager) (*types.Container, bool, error) { logsAggregatorContainerSearchLabels := map[string]string{ - label_key_consts.AppIDDockerLabelKey.GetString(): label_value_consts.AppIDDockerLabelValue.GetString(), - label_key_consts.ContainerTypeDockerLabelKey.GetString(): label_value_consts.LogsAggregatorTypeDockerLabelValue.GetString(), + docker_label_key.AppIDDockerLabelKey.GetString(): label_value_consts.AppIDDockerLabelValue.GetString(), + docker_label_key.ContainerTypeDockerLabelKey.GetString(): label_value_consts.LogsAggregatorTypeDockerLabelValue.GetString(), } matchingLogsAggregatorContainers, err := dockerManager.GetContainersByLabels(ctx, logsAggregatorContainerSearchLabels, shouldShowStoppedLogsAggregatorContainers) diff --git a/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/logs_collector_functions/shared_helpers.go b/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/logs_collector_functions/shared_helpers.go index bf5cf4855d..1416a6fa13 100644 --- a/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/logs_collector_functions/shared_helpers.go +++ b/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/logs_collector_functions/shared_helpers.go @@ -2,6 +2,7 @@ package logs_collector_functions import ( "context" + "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_label_key" "net" "github.com/docker/docker/api/types/volume" @@ -9,7 +10,6 @@ import ( "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/docker_manager" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/docker_manager/types" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_port_spec_serializer" - "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/label_key_consts" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/label_value_consts" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/container" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/enclave" @@ -24,9 +24,9 @@ const ( func getLogsCollectorPrivatePorts(containerLabels map[string]string) (*port_spec.PortSpec, *port_spec.PortSpec, error) { - serializedPortSpecs, found := containerLabels[label_key_consts.PortSpecsDockerLabelKey.GetString()] + serializedPortSpecs, found := containerLabels[docker_label_key.PortSpecsDockerLabelKey.GetString()] if !found { - return nil, nil, stacktrace.NewError("Expected to find port specs label '%v' but none was found", label_key_consts.PortSpecsDockerLabelKey.GetString()) + return nil, nil, stacktrace.NewError("Expected to find port specs label '%v' but none was found", docker_label_key.PortSpecsDockerLabelKey.GetString()) } portSpecs, err := docker_port_spec_serializer.DeserializePortSpecs(serializedPortSpecs) @@ -113,9 +113,9 @@ func getLogsCollectorObjectFromContainerInfo( func getLogsCollectorForTheGivenEnclave(ctx context.Context, enclaveUuid enclave.EnclaveUUID, dockerManager *docker_manager.DockerManager) ([]*types.Container, error) { logsCollectorContainerSearchLabels := map[string]string{ - label_key_consts.AppIDDockerLabelKey.GetString(): label_value_consts.AppIDDockerLabelValue.GetString(), - label_key_consts.ContainerTypeDockerLabelKey.GetString(): label_value_consts.LogsCollectorTypeDockerLabelValue.GetString(), - label_key_consts.EnclaveUUIDDockerLabelKey.GetString(): string(enclaveUuid), + docker_label_key.AppIDDockerLabelKey.GetString(): label_value_consts.AppIDDockerLabelValue.GetString(), + docker_label_key.ContainerTypeDockerLabelKey.GetString(): label_value_consts.LogsCollectorTypeDockerLabelValue.GetString(), + docker_label_key.EnclaveUUIDDockerLabelKey.GetString(): string(enclaveUuid), } matchingLogsCollectorContainers, err := dockerManager.GetContainersByLabels(ctx, logsCollectorContainerSearchLabels, shouldShowStoppedLogsCollectorContainers) @@ -173,9 +173,9 @@ func getEnclaveLogsCollectorVolumeName( var volumes []*volume.Volume searchLabels := map[string]string{ - label_key_consts.AppIDDockerLabelKey.GetString(): label_value_consts.AppIDDockerLabelValue.GetString(), - label_key_consts.VolumeTypeDockerLabelKey.GetString(): label_value_consts.LogsCollectorVolumeTypeDockerLabelValue.GetString(), - label_key_consts.EnclaveUUIDDockerLabelKey.GetString(): string(enclaveUuid), + docker_label_key.AppIDDockerLabelKey.GetString(): label_value_consts.AppIDDockerLabelValue.GetString(), + docker_label_key.VolumeTypeDockerLabelKey.GetString(): label_value_consts.LogsCollectorVolumeTypeDockerLabelValue.GetString(), + docker_label_key.EnclaveUUIDDockerLabelKey.GetString(): string(enclaveUuid), } volumes, err := dockerManager.GetVolumesByLabels(ctx, searchLabels) diff --git a/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/shared_helpers/shared_helpers.go b/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/shared_helpers/shared_helpers.go index 3d2a59827e..56afcfe0e6 100644 --- a/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/shared_helpers/shared_helpers.go +++ b/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/shared_helpers/shared_helpers.go @@ -5,6 +5,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_label_key" "io" "net" "os" @@ -20,7 +21,6 @@ import ( "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/docker_manager" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/docker_manager/types" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_port_spec_serializer" - "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/label_key_consts" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/label_value_consts" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/container" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/enclave" @@ -77,8 +77,8 @@ type UserServiceDockerResources struct { func GetEnclaveNetworkByEnclaveUuid(ctx context.Context, enclaveUuid enclave.EnclaveUUID, dockerManager *docker_manager.DockerManager) (*types.Network, error) { networkSearchLabels := map[string]string{ - label_key_consts.AppIDDockerLabelKey.GetString(): label_value_consts.AppIDDockerLabelValue.GetString(), - label_key_consts.EnclaveUUIDDockerLabelKey.GetString(): string(enclaveUuid), + docker_label_key.AppIDDockerLabelKey.GetString(): label_value_consts.AppIDDockerLabelValue.GetString(), + docker_label_key.EnclaveUUIDDockerLabelKey.GetString(): string(enclaveUuid), } enclaveNetworksFound, err := dockerManager.GetNetworksByLabels(ctx, networkSearchLabels) @@ -230,21 +230,21 @@ func GetIpAndPortInfoFromContainer( resultPublicPortSpecs map[string]*port_spec.PortSpec, resultErr error, ) { - privateIpAddrStr, found := labels[label_key_consts.PrivateIPDockerLabelKey.GetString()] + privateIpAddrStr, found := labels[docker_label_key.PrivateIPDockerLabelKey.GetString()] if !found { - return nil, nil, nil, nil, stacktrace.NewError("Expected to find label '%v' on container '%v' but label was missing", label_key_consts.PrivateIPDockerLabelKey.GetString(), containerName) + return nil, nil, nil, nil, stacktrace.NewError("Expected to find label '%v' on container '%v' but label was missing", docker_label_key.PrivateIPDockerLabelKey.GetString(), containerName) } privateIp := net.ParseIP(privateIpAddrStr) if privateIp == nil { return nil, nil, nil, nil, stacktrace.NewError("Couldn't parse private IP string '%v' on container '%v' to an IP address", privateIpAddrStr, containerName) } - serializedPortSpecs, found := labels[label_key_consts.PortSpecsDockerLabelKey.GetString()] + serializedPortSpecs, found := labels[docker_label_key.PortSpecsDockerLabelKey.GetString()] if !found { return nil, nil, nil, nil, stacktrace.NewError( "Expected to find port specs label '%v' on container '%v' but none was found", containerName, - label_key_consts.PortSpecsDockerLabelKey.GetString(), + docker_label_key.PortSpecsDockerLabelKey.GetString(), ) } @@ -513,9 +513,9 @@ func getMatchingUserServiceDockerResources( // Grab services, INDEPENDENT OF volumes userServiceContainerSearchLabels := map[string]string{ - label_key_consts.AppIDDockerLabelKey.GetString(): label_value_consts.AppIDDockerLabelValue.GetString(), - label_key_consts.EnclaveUUIDDockerLabelKey.GetString(): string(enclaveId), - label_key_consts.ContainerTypeDockerLabelKey.GetString(): label_value_consts.UserServiceContainerTypeDockerLabelValue.GetString(), + docker_label_key.AppIDDockerLabelKey.GetString(): label_value_consts.AppIDDockerLabelValue.GetString(), + docker_label_key.EnclaveUUIDDockerLabelKey.GetString(): string(enclaveId), + docker_label_key.ContainerTypeDockerLabelKey.GetString(): label_value_consts.UserServiceContainerTypeDockerLabelValue.GetString(), } userServiceContainers, err := dockerManager.GetContainersByLabels(ctx, userServiceContainerSearchLabels, shouldGetStoppedContainersWhenGettingServiceInfo) if err != nil { @@ -523,9 +523,9 @@ func getMatchingUserServiceDockerResources( } for _, container := range userServiceContainers { - serviceUuidStr, found := container.GetLabels()[label_key_consts.GUIDDockerLabelKey.GetString()] + serviceUuidStr, found := container.GetLabels()[docker_label_key.GUIDDockerLabelKey.GetString()] if !found { - return nil, stacktrace.NewError("Found user service container '%v' that didn't have expected GUID label '%v'", container.GetId(), label_key_consts.GUIDDockerLabelKey.GetString()) + return nil, stacktrace.NewError("Found user service container '%v' that didn't have expected GUID label '%v'", container.GetId(), docker_label_key.GUIDDockerLabelKey.GetString()) } serviceUuid := service.ServiceUUID(serviceUuidStr) @@ -548,9 +548,9 @@ func getMatchingUserServiceDockerResources( // Grab volumes, INDEPENDENT OF whether there are any containers filesArtifactExpansionVolumeSearchLabels := map[string]string{ - label_key_consts.AppIDDockerLabelKey.GetString(): label_value_consts.AppIDDockerLabelValue.GetString(), - label_key_consts.EnclaveUUIDDockerLabelKey.GetString(): string(enclaveId), - label_key_consts.VolumeTypeDockerLabelKey.GetString(): label_value_consts.FilesArtifactExpansionVolumeTypeDockerLabelValue.GetString(), + docker_label_key.AppIDDockerLabelKey.GetString(): label_value_consts.AppIDDockerLabelValue.GetString(), + docker_label_key.EnclaveUUIDDockerLabelKey.GetString(): string(enclaveId), + docker_label_key.VolumeTypeDockerLabelKey.GetString(): label_value_consts.FilesArtifactExpansionVolumeTypeDockerLabelValue.GetString(), } matchingFilesArtifactExpansionVolumes, err := dockerManager.GetVolumesByLabels(ctx, filesArtifactExpansionVolumeSearchLabels) if err != nil { @@ -558,9 +558,9 @@ func getMatchingUserServiceDockerResources( } for _, volume := range matchingFilesArtifactExpansionVolumes { - serviceUuidStr, found := volume.Labels[label_key_consts.UserServiceGUIDDockerLabelKey.GetString()] + serviceUuidStr, found := volume.Labels[docker_label_key.UserServiceGUIDDockerLabelKey.GetString()] if !found { - return nil, stacktrace.NewError("Found files artifact expansion volume '%v' that didn't have expected service GUID label '%v'", volume.Name, label_key_consts.UserServiceGUIDDockerLabelKey.GetString()) + return nil, stacktrace.NewError("Found files artifact expansion volume '%v' that didn't have expected service GUID label '%v'", volume.Name, docker_label_key.UserServiceGUIDDockerLabelKey.GetString()) } serviceUuid := service.ServiceUUID(serviceUuidStr) @@ -606,9 +606,9 @@ func getUserServiceObjsFromDockerResources( containerName := serviceContainer.GetName() containerLabels := serviceContainer.GetLabels() - serviceIdStr, found := containerLabels[label_key_consts.IDDockerLabelKey.GetString()] + serviceIdStr, found := containerLabels[docker_label_key.IDDockerLabelKey.GetString()] if !found { - return nil, stacktrace.NewError("Expected to find label '%v' on container '%v' but label was missing", label_key_consts.IDDockerLabelKey.GetString(), containerName) + return nil, stacktrace.NewError("Expected to find label '%v' on container '%v' but label was missing", docker_label_key.IDDockerLabelKey.GetString(), containerName) } serviceName := service.ServiceName(serviceIdStr) diff --git a/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/user_services_functions/start_user_services.go b/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/user_services_functions/start_user_services.go index 84afb614ee..b8f542e466 100644 --- a/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/user_services_functions/start_user_services.go +++ b/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/user_services_functions/start_user_services.go @@ -623,6 +623,7 @@ func createStartServiceOperation( serviceUUID, privateIpAddr, privatePorts, + serviceConfig.GetLabels(), ) if err != nil { return nil, stacktrace.Propagate(err, "An error occurred while trying to get the user service container attributes for user service with UUID '%v'", serviceUUID) @@ -688,7 +689,9 @@ func createStartServiceOperation( volumeMounts, ).WithLoggingDriver( fluentdLoggingDriverCnfg, - ).WithRestartPolicy(restartPolicy) + ).WithRestartPolicy( + restartPolicy, + ) if entrypointArgs != nil { createAndStartArgsBuilder.WithEntrypointArgs(entrypointArgs) diff --git a/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_label_key/docker_label_key.go b/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_label_key/docker_label_key.go index b07435fa16..06ae7d1572 100644 --- a/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_label_key/docker_label_key.go +++ b/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_label_key/docker_label_key.go @@ -3,6 +3,7 @@ package docker_label_key import ( "github.com/kurtosis-tech/stacktrace" "regexp" + "strings" ) const ( @@ -20,21 +21,38 @@ type DockerLabelKey struct { } // NOTE: This is ONLY for areas where the label is declared statically!! Any sort of dynamic/runtime label creation -// should use CreateNewDockerLabelKey +// should use createNewDockerLabelKey func MustCreateNewDockerLabelKey(str string) *DockerLabelKey { - key, err := CreateNewDockerLabelKey(str) + key, err := createNewDockerLabelKey(str) if err != nil { panic(err) } return key } -func CreateNewDockerLabelKey(str string) (*DockerLabelKey, error) { - if !dockerLabelKeyRegex.MatchString(str) { - return nil, stacktrace.NewError("Label key string '%v' doesn't match Docker label key regex '%v'", str, dockerLabelKeyRegexStr) +// CreateNewDockerUserCustomLabelKey creates a custom user Docker label with the Kurtosis custom user prefix +func CreateNewDockerUserCustomLabelKey(str string) (*DockerLabelKey, error) { + if err := validateNotEmptyUserCustomLabelKey(str); err != nil { + return nil, stacktrace.NewError("Received an empty user custom label key") } - if len(str) > maxLabelLength { - return nil, stacktrace.NewError("Label key string '%v' is longer than max label key length '%v'", str, maxLabelLength) + labelKeyStr := customUserLabelsKeyPrefixStr + str + return createNewDockerLabelKey(labelKeyStr) +} + +func ValidateUserCustomLabelKey(str string) error { + if err := validateNotEmptyUserCustomLabelKey(str); err != nil { + return stacktrace.Propagate(err, "Received an empty user custom label key") + } + labelKeyStr := customUserLabelsKeyPrefixStr + str + if err := validate(labelKeyStr); err != nil { + return stacktrace.Propagate(err, "User custom label key '%s' is not valid", str) + } + return nil +} + +func createNewDockerLabelKey(str string) (*DockerLabelKey, error) { + if err := validate(str); err != nil { + return nil, stacktrace.NewError("Label key string '%v' is not valid", str) } return &DockerLabelKey{value: str}, nil } @@ -42,3 +60,21 @@ func CreateNewDockerLabelKey(str string) (*DockerLabelKey, error) { func (key *DockerLabelKey) GetString() string { return key.value } + +func validateNotEmptyUserCustomLabelKey(str string) error { + str = strings.TrimSpace(str) + if str == "" { + return stacktrace.NewError("User custom label key can't be an empty string") + } + return nil +} + +func validate(str string) error { + if !dockerLabelKeyRegex.MatchString(str) { + return stacktrace.NewError("Label key string '%v' doesn't match Docker label key regex '%v'", str, dockerLabelKeyRegexStr) + } + if len(str) > maxLabelLength { + return stacktrace.NewError("Label key string '%v' is longer than max label key length '%v'", str, maxLabelLength) + } + return nil +} diff --git a/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_label_key/docker_label_key_test.go b/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_label_key/docker_label_key_test.go index a1342ed576..ecb18397c0 100644 --- a/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_label_key/docker_label_key_test.go +++ b/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_label_key/docker_label_key_test.go @@ -6,6 +6,10 @@ import ( "testing" ) +const ( + oneRandomChar = "a" +) + var testLabelsWithValidity = map[string]bool{ "": false, " ": false, // whitespace not allowed @@ -15,18 +19,43 @@ var testLabelsWithValidity = map[string]bool{ "a99a9": true, "a.7.3.5": true, "com.kurtosistech.app-id": true, + "com.kurtosistech.app_id": true, + "kurtosistech.com/app-id": false, // Kubernetes labels standard not allowed } func TestEdgeCaseLabels(t *testing.T) { for label, shouldPass := range testLabelsWithValidity { - _, err := CreateNewDockerLabelKey(label) + _, err := createNewDockerLabelKey(label) didPass := err == nil - require.Equal(t, shouldPass, didPass, "Expected label key string '%v' validity to be '%v' but was '%v'", shouldPass, didPass) + require.Equal(t, shouldPass, didPass, "Expected label key string '%v' validity to be '%v' but was '%v'", label, shouldPass, didPass) + _, err = CreateNewDockerUserCustomLabelKey(label) + didPass = err == nil + require.Equal(t, shouldPass, didPass, "Expected user custom label key string '%v' validity to be '%v' but was '%v'", label, shouldPass, didPass) } } func TestTooLongLabel(t *testing.T) { invalidLabel := strings.Repeat("a", 9999) - _, err := CreateNewDockerLabelKey(invalidLabel) + _, err := createNewDockerLabelKey(invalidLabel) + require.Error(t, err) + _, err = CreateNewDockerUserCustomLabelKey(invalidLabel) + require.Error(t, err) +} + +func TestMaxAllowedLabel(t *testing.T) { + validMaxLabel := strings.Repeat(oneRandomChar, maxLabelLength) + _, err := createNewDockerLabelKey(validMaxLabel) + require.NoError(t, err) + + overValidMaxLabel := validMaxLabel + oneRandomChar + _, err = createNewDockerLabelKey(overValidMaxLabel) + require.Error(t, err) + + userCustomValidMaxLabel := strings.Repeat(oneRandomChar, maxLabelLength-len(customUserLabelsKeyPrefixStr)) + _, err = CreateNewDockerUserCustomLabelKey(userCustomValidMaxLabel) + require.NoError(t, err) + + overUserCustomValidMaxLabel := userCustomValidMaxLabel + oneRandomChar + _, err = CreateNewDockerUserCustomLabelKey(overUserCustomValidMaxLabel) require.Error(t, err) } diff --git a/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/label_key_consts/label_key_consts.go b/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_label_key/label_key_consts.go similarity index 56% rename from container-engine-lib/lib/backend_impls/docker/object_attributes_provider/label_key_consts/label_key_consts.go rename to container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_label_key/label_key_consts.go index c5a6cf4a5d..9fc758f8b3 100644 --- a/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/label_key_consts/label_key_consts.go +++ b/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_label_key/label_key_consts.go @@ -1,8 +1,4 @@ -package label_key_consts - -import ( - "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_label_key" -) +package docker_label_key const ( // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! DO NOT CHANGE THESE VALUES !!!!!!!!!!!!!!!!!!!!!!!!!!!!! @@ -11,8 +7,9 @@ const ( // // If you add new immutable values to this section, MAKE SURE TO UPDATE THE UNIT TEST! // These immutable values track resources between Kurtosis versions. - labelNamespaceStr = "com.kurtosistech." - appIdLabelKeyStr = labelNamespaceStr + "app-id" + labelNamespaceStr = "com.kurtosistech." + appIdLabelKeyStr = labelNamespaceStr + "app-id" + customUserLabelsKeyPrefixStr = labelNamespaceStr + "custom." // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! DO NOT CHANGE THESE VALUES !!!!!!!!!!!!!!!!!!!!!!!!!!!!! containerTypeLabelKeyStr = labelNamespaceStr + "container-type" @@ -53,21 +50,21 @@ const ( // which will cause a resource leak on the user's system! // // If you add new immutable values to this section, MAKE SURE TO UPDATE THE UNIT TEST! -var AppIDDockerLabelKey = docker_label_key.MustCreateNewDockerLabelKey(appIdLabelKeyStr) +var AppIDDockerLabelKey = MustCreateNewDockerLabelKey(appIdLabelKeyStr) // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! DO NOT CHANGE THESE VALUES !!!!!!!!!!!!!!!!!!!!!!!!!!!!! -var ContainerTypeDockerLabelKey = docker_label_key.MustCreateNewDockerLabelKey(containerTypeLabelKeyStr) -var VolumeTypeDockerLabelKey = docker_label_key.MustCreateNewDockerLabelKey(volumeTypeLabelKeyStr) -var IDDockerLabelKey = docker_label_key.MustCreateNewDockerLabelKey(idLabelKeyStr) -var GUIDDockerLabelKey = docker_label_key.MustCreateNewDockerLabelKey(guidLabelKeyStr) -var PortSpecsDockerLabelKey = docker_label_key.MustCreateNewDockerLabelKey(portSpecsLabelKeyStr) -var EnclaveUUIDDockerLabelKey = docker_label_key.MustCreateNewDockerLabelKey(enclaveIdLabelKeyStr) -var EnclaveNameDockerLabelKey = docker_label_key.MustCreateNewDockerLabelKey(enclaveNameLabelKeyStr) -var EnclaveCreationTimeLabelKey = docker_label_key.MustCreateNewDockerLabelKey(enclaveCreationTime) -var PrivateIPDockerLabelKey = docker_label_key.MustCreateNewDockerLabelKey(privateIpAddrLabelKeyStr) -var UserServiceGUIDDockerLabelKey = docker_label_key.MustCreateNewDockerLabelKey(userServiceGuidDockerLabelKeyStr) -var LogsEnclaveUUIDDockerLabelKey = docker_label_key.MustCreateNewDockerLabelKey(logsEnclaveUuidLabelKeyStr) -var LogsServiceUUIDDockerLabelKey = docker_label_key.MustCreateNewDockerLabelKey(logsServiceUuidDockerLabelKey) -var LogsServiceShortUUIDDockerLabelKey = docker_label_key.MustCreateNewDockerLabelKey(logsServiceShortUuidDockerLabelKey) -var LogsServiceNameDockerLabelKey = docker_label_key.MustCreateNewDockerLabelKey(logsServiceNameDockerLabelKey) +var ContainerTypeDockerLabelKey = MustCreateNewDockerLabelKey(containerTypeLabelKeyStr) +var VolumeTypeDockerLabelKey = MustCreateNewDockerLabelKey(volumeTypeLabelKeyStr) +var IDDockerLabelKey = MustCreateNewDockerLabelKey(idLabelKeyStr) +var GUIDDockerLabelKey = MustCreateNewDockerLabelKey(guidLabelKeyStr) +var PortSpecsDockerLabelKey = MustCreateNewDockerLabelKey(portSpecsLabelKeyStr) +var EnclaveUUIDDockerLabelKey = MustCreateNewDockerLabelKey(enclaveIdLabelKeyStr) +var EnclaveNameDockerLabelKey = MustCreateNewDockerLabelKey(enclaveNameLabelKeyStr) +var EnclaveCreationTimeLabelKey = MustCreateNewDockerLabelKey(enclaveCreationTime) +var PrivateIPDockerLabelKey = MustCreateNewDockerLabelKey(privateIpAddrLabelKeyStr) +var UserServiceGUIDDockerLabelKey = MustCreateNewDockerLabelKey(userServiceGuidDockerLabelKeyStr) +var LogsEnclaveUUIDDockerLabelKey = MustCreateNewDockerLabelKey(logsEnclaveUuidLabelKeyStr) +var LogsServiceUUIDDockerLabelKey = MustCreateNewDockerLabelKey(logsServiceUuidDockerLabelKey) +var LogsServiceShortUUIDDockerLabelKey = MustCreateNewDockerLabelKey(logsServiceShortUuidDockerLabelKey) +var LogsServiceNameDockerLabelKey = MustCreateNewDockerLabelKey(logsServiceNameDockerLabelKey) diff --git a/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/label_key_consts/label_key_consts_test.go b/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_label_key/label_key_consts_test.go similarity index 77% rename from container-engine-lib/lib/backend_impls/docker/object_attributes_provider/label_key_consts/label_key_consts_test.go rename to container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_label_key/label_key_consts_test.go index 67ae313598..62726c3ffb 100644 --- a/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/label_key_consts/label_key_consts_test.go +++ b/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_label_key/label_key_consts_test.go @@ -1,27 +1,28 @@ -package label_key_consts +package docker_label_key import ( - "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_label_key" "github.com/stretchr/testify/require" "testing" ) // We expect these strings to be reliable between versions. const ( - expectedLabelNamespaceStr = "com.kurtosistech." - expectedAppIdLabelKeyStr = "com.kurtosistech.app-id" + expectedLabelNamespaceStr = "com.kurtosistech." + expectedAppIdLabelKeyStr = "com.kurtosistech.app-id" + expectedCustomUserLabelKeyPrefixStr = expectedLabelNamespaceStr + "custom." ) // When Kurtosis versions change, these particular label key strings must be equal. // If these change between versions, Kurtosis will not be able to find and manage resources with these label keys. // They will effectively be lost to Kurtosis and the user will have to clean up any mess. var crossVersionLabelKeyStringsToEnsure = map[string]string{ - labelNamespaceStr: expectedLabelNamespaceStr, - appIdLabelKeyStr: expectedAppIdLabelKeyStr, + labelNamespaceStr: expectedLabelNamespaceStr, + appIdLabelKeyStr: expectedAppIdLabelKeyStr, + customUserLabelsKeyPrefixStr: expectedCustomUserLabelKeyPrefixStr, } // These are the publicly accessible keys that correspond to the private string constants. They need to stay the same. -var crossVersionLabelKeysToEnsure = map[*docker_label_key.DockerLabelKey]string{ +var crossVersionLabelKeysToEnsure = map[*DockerLabelKey]string{ AppIDDockerLabelKey: expectedAppIdLabelKeyStr, } diff --git a/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_label_value/docker_label_value.go b/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_label_value/docker_label_value.go index 30cc81948b..5926e25921 100644 --- a/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_label_value/docker_label_value.go +++ b/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_label_value/docker_label_value.go @@ -32,22 +32,29 @@ func MustCreateNewDockerLabelValue(str string) *DockerLabelValue { } func CreateNewDockerLabelValue(str string) (*DockerLabelValue, error) { + if err := ValidateDockerLabelValue(str); err != nil { + return nil, stacktrace.Propagate(err, "Invalid Docker label value '%s'", str) + } + + return &DockerLabelValue{value: str}, nil +} + +func ValidateDockerLabelValue(str string) error { if !dockerLabelValueRegex.MatchString(str) { - return nil, stacktrace.NewError("Label value string '%v' doesn't match Docker label value regex '%v'", str, dockerLabelValueRegexStr) + return stacktrace.NewError("Label value string '%v' doesn't match Docker label value regex '%v'", str, dockerLabelValueRegexStr) } strBytes := []byte(str) numBytes := len(strBytes) if numBytes > maxLabelValueBytes { - return nil, stacktrace.NewError( + return stacktrace.NewError( "The following label value string is '%v' bytes, which is greater than the max limit '%v':\n%v", numBytes, maxLabelValueBytes, str, ) } - - return &DockerLabelValue{value: str}, nil + return nil } func (key *DockerLabelValue) GetString() string { diff --git a/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_labels_for_logs/docker_labels_for_logs.go b/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_labels_for_logs/docker_labels_for_logs.go index 030f3dc59d..37a72beacc 100644 --- a/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_labels_for_logs/docker_labels_for_logs.go +++ b/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_labels_for_logs/docker_labels_for_logs.go @@ -2,17 +2,16 @@ package docker_labels_for_logs import ( "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_label_key" - "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/label_key_consts" ) // The following docker labels will be added into the logs stream // These are necessary for propagating information for log filtering and retrieval through the logging pipeline var LogsDatabaseKurtosisTrackedDockerLabelsForIdentifyLogsStream = []*docker_label_key.DockerLabelKey{ - label_key_consts.ContainerTypeDockerLabelKey, - label_key_consts.LogsEnclaveUUIDDockerLabelKey, - label_key_consts.LogsServiceUUIDDockerLabelKey, - label_key_consts.LogsServiceShortUUIDDockerLabelKey, - label_key_consts.LogsServiceNameDockerLabelKey, + docker_label_key.ContainerTypeDockerLabelKey, + docker_label_key.LogsEnclaveUUIDDockerLabelKey, + docker_label_key.LogsServiceUUIDDockerLabelKey, + docker_label_key.LogsServiceShortUUIDDockerLabelKey, + docker_label_key.LogsServiceNameDockerLabelKey, } // These are all the logs database Kurtosis tracked Docker Labels used diff --git a/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/enclave_object_attributes_provider.go b/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/enclave_object_attributes_provider.go index 6dcacbc8e8..9335d2bbf1 100644 --- a/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/enclave_object_attributes_provider.go +++ b/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/enclave_object_attributes_provider.go @@ -7,7 +7,6 @@ import ( "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_label_value" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_object_name" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_port_spec_serializer" - "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/label_key_consts" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/label_value_consts" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/port_spec" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/service" @@ -45,6 +44,7 @@ type DockerEnclaveObjectAttributesProvider interface { serviceUuid service.ServiceUUID, privateIpAddr net.IP, privatePorts map[string]*port_spec.PortSpec, + userLabels map[string]string, ) (DockerObjectAttributes, error) ForFilesArtifactsExpanderContainer( serviceUUID service.ServiceUUID, @@ -110,8 +110,8 @@ func (provider *dockerEnclaveObjectAttributesProviderImpl) ForEnclaveNetwork(enc return nil, stacktrace.Propagate(err, "An error occurred getting labels for enclave network using ID '%v'", provider.enclaveId) } - labels[label_key_consts.EnclaveCreationTimeLabelKey] = creationTimeLabelValue - labels[label_key_consts.EnclaveNameDockerLabelKey] = enclaveNameLabelValue + labels[docker_label_key.EnclaveCreationTimeLabelKey] = creationTimeLabelValue + labels[docker_label_key.EnclaveNameDockerLabelKey] = enclaveNameLabelValue objectAttributes, err := newDockerObjectAttributesImpl(name, labels) if err != nil { @@ -134,7 +134,7 @@ func (provider *dockerEnclaveObjectAttributesProviderImpl) ForEnclaveDataVolume( } labels := provider.getLabelsForEnclaveObject() - labels[label_key_consts.VolumeTypeDockerLabelKey] = label_value_consts.EnclaveDataVolumeTypeDockerLabelValue + labels[docker_label_key.VolumeTypeDockerLabelKey] = label_value_consts.EnclaveDataVolumeTypeDockerLabelValue objectAttributes, err := newDockerObjectAttributesImpl(name, labels) if err != nil { @@ -173,8 +173,8 @@ func (provider *dockerEnclaveObjectAttributesProviderImpl) ForApiContainer( } labels := provider.getLabelsForEnclaveObject() - labels[label_key_consts.ContainerTypeDockerLabelKey] = label_value_consts.APIContainerContainerTypeDockerLabelValue - labels[label_key_consts.PrivateIPDockerLabelKey] = privateIpLabelValue + labels[docker_label_key.ContainerTypeDockerLabelKey] = label_value_consts.APIContainerContainerTypeDockerLabelValue + labels[docker_label_key.PrivateIPDockerLabelKey] = privateIpLabelValue usedPorts := map[string]*port_spec.PortSpec{ privateGrpcPortId: privateGrpcPortSpec, @@ -183,7 +183,7 @@ func (provider *dockerEnclaveObjectAttributesProviderImpl) ForApiContainer( if err != nil { return nil, stacktrace.Propagate(err, "An error occurred serializing the following API container ports object to a string for storing in the ports label: %+v", usedPorts) } - labels[label_key_consts.PortSpecsDockerLabelKey] = serializedPortsSpec + labels[docker_label_key.PortSpecsDockerLabelKey] = serializedPortsSpec objectAttributes, err := newDockerObjectAttributesImpl(name, labels) if err != nil { @@ -203,6 +203,7 @@ func (provider *dockerEnclaveObjectAttributesProviderImpl) ForUserServiceContain serviceUuid service.ServiceUUID, privateIpAddr net.IP, privatePorts map[string]*port_spec.PortSpec, + userLabels map[string]string, ) (DockerObjectAttributes, error) { name, err := provider.getNameForUserServiceContainer( serviceName, @@ -232,9 +233,22 @@ func (provider *dockerEnclaveObjectAttributesProviderImpl) ForUserServiceContain if err != nil { return nil, stacktrace.Propagate(err, "An error occurred getting labels for enclave object with UUID '%v'", serviceUuid) } - labels[label_key_consts.ContainerTypeDockerLabelKey] = label_value_consts.UserServiceContainerTypeDockerLabelValue - labels[label_key_consts.PortSpecsDockerLabelKey] = serializedPortsSpec - labels[label_key_consts.PrivateIPDockerLabelKey] = privateIpLabelValue + labels[docker_label_key.ContainerTypeDockerLabelKey] = label_value_consts.UserServiceContainerTypeDockerLabelValue + labels[docker_label_key.PortSpecsDockerLabelKey] = serializedPortsSpec + labels[docker_label_key.PrivateIPDockerLabelKey] = privateIpLabelValue + + // add user custom label + for userLabelKey, userLabelValue := range userLabels { + dockerLabelKey, err := docker_label_key.CreateNewDockerUserCustomLabelKey(userLabelKey) + if err != nil { + return nil, stacktrace.Propagate(err, "An error occurred creating a new user custom Docker label key '%s'", userLabelKey) + } + dockerLabelValue, err := docker_label_value.CreateNewDockerLabelValue(userLabelValue) + if err != nil { + return nil, stacktrace.Propagate(err, "An error occurred creating a new user custom Docker label value '%s'", userLabelValue) + } + labels[dockerLabelKey] = dockerLabelValue + } objectAttributes, err := newDockerObjectAttributesImpl(name, labels) if err != nil { @@ -280,8 +294,8 @@ func (provider *dockerEnclaveObjectAttributesProviderImpl) ForSingleFilesArtifac if err != nil { return nil, stacktrace.Propagate(err, "An error occurred creating a Docker label value from service GUID string '%v'", serviceUuidStr) } - labels[label_key_consts.UserServiceGUIDDockerLabelKey] = serviceUuidLabelValue - labels[label_key_consts.VolumeTypeDockerLabelKey] = label_value_consts.FilesArtifactExpansionVolumeTypeDockerLabelValue + labels[docker_label_key.UserServiceGUIDDockerLabelKey] = serviceUuidLabelValue + labels[docker_label_key.VolumeTypeDockerLabelKey] = label_value_consts.FilesArtifactExpansionVolumeTypeDockerLabelValue // TODO Create a KurtosisResourceDockerLabelKey object, like Kubernetes, and apply the "user-service" label here? objectAttributes, err := newDockerObjectAttributesImpl(name, labels) @@ -329,8 +343,8 @@ func (provider *dockerEnclaveObjectAttributesProviderImpl) ForSinglePersistentDi if err != nil { return nil, stacktrace.Propagate(err, "An error occurred creating a Docker label value from service GUID string '%v'", serviceUuidStr) } - labels[label_key_consts.UserServiceGUIDDockerLabelKey] = serviceUuidLabelValue - labels[label_key_consts.VolumeTypeDockerLabelKey] = label_value_consts.PersistentDirectoryVolumeTypeDockerLabelValue + labels[docker_label_key.UserServiceGUIDDockerLabelKey] = serviceUuidLabelValue + labels[docker_label_key.VolumeTypeDockerLabelKey] = label_value_consts.PersistentDirectoryVolumeTypeDockerLabelValue // TODO Create a KurtosisResourceDockerLabelKey object, like Kubernetes, and apply the "user-service" label here? objectAttributes, err := newDockerObjectAttributesImpl(name, labels) @@ -373,8 +387,8 @@ func (provider *dockerEnclaveObjectAttributesProviderImpl) ForFilesArtifactsExpa if err != nil { return nil, stacktrace.Propagate(err, "An error occurred creating a Docker label value from service GUID string '%v'", serviceUuidStr) } - labels[label_key_consts.UserServiceGUIDDockerLabelKey] = serviceUuidLabelValue - labels[label_key_consts.ContainerTypeDockerLabelKey] = label_value_consts.FilesArtifactExpanderContainerTypeDockerLabelValue + labels[docker_label_key.UserServiceGUIDDockerLabelKey] = serviceUuidLabelValue + labels[docker_label_key.ContainerTypeDockerLabelKey] = label_value_consts.FilesArtifactExpanderContainerTypeDockerLabelValue objectAttributes, err := newDockerObjectAttributesImpl(name, labels) if err != nil { @@ -401,8 +415,8 @@ func (provider *dockerEnclaveObjectAttributesProviderImpl) ForLogsCollector(tcpP return nil, stacktrace.Propagate(err, "An error occurred serializing the following logs-collector-server-ports to a string for storing in the ports label: %+v", usedPorts) } - labels[label_key_consts.ContainerTypeDockerLabelKey] = label_value_consts.LogsCollectorTypeDockerLabelValue - labels[label_key_consts.PortSpecsDockerLabelKey] = serializedPortsSpec + labels[docker_label_key.ContainerTypeDockerLabelKey] = label_value_consts.LogsCollectorTypeDockerLabelValue + labels[docker_label_key.PortSpecsDockerLabelKey] = serializedPortsSpec objectAttributes, err := newDockerObjectAttributesImpl(name, labels) if err != nil { @@ -420,7 +434,7 @@ func (provider *dockerEnclaveObjectAttributesProviderImpl) ForLogsCollectorVolum labels := provider.getLabelsForEnclaveObject() - labels[label_key_consts.VolumeTypeDockerLabelKey] = label_value_consts.LogsCollectorVolumeTypeDockerLabelValue + labels[docker_label_key.VolumeTypeDockerLabelKey] = label_value_consts.LogsCollectorVolumeTypeDockerLabelValue objectAttributes, err := newDockerObjectAttributesImpl(name, labels) if err != nil { @@ -466,8 +480,8 @@ func (provider *dockerEnclaveObjectAttributesProviderImpl) getNameForUserService func (provider *dockerEnclaveObjectAttributesProviderImpl) getLabelsForEnclaveObject() map[*docker_label_key.DockerLabelKey]*docker_label_value.DockerLabelValue { return map[*docker_label_key.DockerLabelKey]*docker_label_value.DockerLabelValue{ - label_key_consts.EnclaveUUIDDockerLabelKey: provider.enclaveId, - label_key_consts.LogsEnclaveUUIDDockerLabelKey: provider.enclaveId, + docker_label_key.EnclaveUUIDDockerLabelKey: provider.enclaveId, + docker_label_key.LogsEnclaveUUIDDockerLabelKey: provider.enclaveId, } } @@ -482,9 +496,9 @@ func (provider *dockerEnclaveObjectAttributesProviderImpl) getLabelsForEnclaveOb if err != nil { return nil, stacktrace.Propagate(err, "An error occurred creating a short GUID Docker label value from GUID string '%v'", guid) } - labels[label_key_consts.GUIDDockerLabelKey] = guidLabelValue - labels[label_key_consts.LogsServiceUUIDDockerLabelKey] = guidLabelValue - labels[label_key_consts.LogsServiceShortUUIDDockerLabelKey] = shortGuidLabelValue + labels[docker_label_key.GUIDDockerLabelKey] = guidLabelValue + labels[docker_label_key.LogsServiceUUIDDockerLabelKey] = guidLabelValue + labels[docker_label_key.LogsServiceShortUUIDDockerLabelKey] = shortGuidLabelValue return labels, nil } @@ -497,8 +511,8 @@ func (provider *dockerEnclaveObjectAttributesProviderImpl) getLabelsForEnclaveOb if err != nil { return nil, stacktrace.Propagate(err, "An error occurred creating a Docker label value from ID string '%v'", id) } - labels[label_key_consts.IDDockerLabelKey] = idLabelValue - labels[label_key_consts.LogsServiceNameDockerLabelKey] = idLabelValue + labels[docker_label_key.IDDockerLabelKey] = idLabelValue + labels[docker_label_key.LogsServiceNameDockerLabelKey] = idLabelValue return labels, nil } diff --git a/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/object_attributes.go b/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/object_attributes.go index ed8662e5f0..17c50af4d6 100644 --- a/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/object_attributes.go +++ b/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/object_attributes.go @@ -4,14 +4,13 @@ import ( "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_label_key" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_label_value" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_object_name" - "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/label_key_consts" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/label_value_consts" "github.com/kurtosis-tech/stacktrace" ) // Labels that get attached to EVERY Kurtosis object var globalLabels = map[*docker_label_key.DockerLabelKey]*docker_label_value.DockerLabelValue{ - label_key_consts.AppIDDockerLabelKey: label_value_consts.AppIDDockerLabelValue, + docker_label_key.AppIDDockerLabelKey: label_value_consts.AppIDDockerLabelValue, // TODO container engine lib version?? } diff --git a/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/object_attributes_provider.go b/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/object_attributes_provider.go index 8263316234..a68ee396f2 100644 --- a/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/object_attributes_provider.go +++ b/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/object_attributes_provider.go @@ -5,7 +5,6 @@ import ( "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_label_value" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_object_name" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_port_spec_serializer" - "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/label_key_consts" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/label_value_consts" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/enclave" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/engine" @@ -78,10 +77,10 @@ func (provider *dockerObjectAttributesProviderImpl) ForEngineServer( } labels := map[*docker_label_key.DockerLabelKey]*docker_label_value.DockerLabelValue{ - label_key_consts.ContainerTypeDockerLabelKey: label_value_consts.EngineContainerTypeDockerLabelValue, - label_key_consts.PortSpecsDockerLabelKey: serializedPortsSpec, - label_key_consts.IDDockerLabelKey: idLabelValue, - label_key_consts.GUIDDockerLabelKey: guidLabelValue, + docker_label_key.ContainerTypeDockerLabelKey: label_value_consts.EngineContainerTypeDockerLabelValue, + docker_label_key.PortSpecsDockerLabelKey: serializedPortsSpec, + docker_label_key.IDDockerLabelKey: idLabelValue, + docker_label_key.GUIDDockerLabelKey: guidLabelValue, } objectAttributes, err := newDockerObjectAttributesImpl(name, labels) @@ -109,7 +108,7 @@ func (provider *dockerObjectAttributesProviderImpl) ForLogsAggregator() (DockerO } labels := map[*docker_label_key.DockerLabelKey]*docker_label_value.DockerLabelValue{ - label_key_consts.ContainerTypeDockerLabelKey: label_value_consts.LogsAggregatorTypeDockerLabelValue, + docker_label_key.ContainerTypeDockerLabelKey: label_value_consts.LogsAggregatorTypeDockerLabelValue, } objectAttributes, err := newDockerObjectAttributesImpl(name, labels) @@ -126,7 +125,7 @@ func (provider *dockerObjectAttributesProviderImpl) ForLogsStorageVolume() (Dock } labels := map[*docker_label_key.DockerLabelKey]*docker_label_value.DockerLabelValue{ - label_key_consts.VolumeTypeDockerLabelKey: label_value_consts.LogsStorageVolumeTypeDockerLabelValue, + docker_label_key.VolumeTypeDockerLabelKey: label_value_consts.LogsStorageVolumeTypeDockerLabelValue, } objectAttributes, err := newDockerObjectAttributesImpl(name, labels) diff --git a/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_kurtosis_backend/engine_functions/engine_logs.go b/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_kurtosis_backend/engine_functions/engine_logs.go index c58b51529e..3274c92534 100644 --- a/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_kurtosis_backend/engine_functions/engine_logs.go +++ b/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_kurtosis_backend/engine_functions/engine_logs.go @@ -5,7 +5,7 @@ import ( "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_kurtosis_backend/shared_helpers" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_manager" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_resource_collectors" - "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/label_key_consts" + "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_label_key" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/engine" "github.com/kurtosis-tech/stacktrace" apiv1 "k8s.io/api/core/v1" @@ -27,7 +27,7 @@ func GetEngineLogs( ctx, kubernetesManager, engineMatchLabels, - label_key_consts.IDKubernetesLabelKey.GetString(), + kubernetes_label_key.IDKubernetesLabelKey.GetString(), engineGuidStrs, ) if err != nil { @@ -63,7 +63,7 @@ func GetEngineLogs( kubernetesManager, namespaceName, engineMatchLabels, - label_key_consts.IDKubernetesLabelKey.GetString(), + kubernetes_label_key.IDKubernetesLabelKey.GetString(), map[string]bool{ engineGuidStr: true, }, diff --git a/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_kurtosis_backend/engine_functions/shared_helpers.go b/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_kurtosis_backend/engine_functions/shared_helpers.go index 4e1e106c97..4d1ecbd53b 100644 --- a/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_kurtosis_backend/engine_functions/shared_helpers.go +++ b/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_kurtosis_backend/engine_functions/shared_helpers.go @@ -5,7 +5,7 @@ import ( "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_kurtosis_backend/shared_helpers" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_manager" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_resource_collectors" - "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/label_key_consts" + "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_label_key" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/label_value_consts" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/engine" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/port_spec" @@ -104,7 +104,7 @@ func getMatchingEngineKubernetesResources( ctx, kubernetesManager, engineMatchLabels, - label_key_consts.IDKubernetesLabelKey.GetString(), + kubernetes_label_key.IDKubernetesLabelKey.GetString(), engineGuidStrs, ) if err != nil { @@ -139,7 +139,7 @@ func getMatchingEngineKubernetesResources( ctx, kubernetesManager, engineMatchLabels, - label_key_consts.IDKubernetesLabelKey.GetString(), + kubernetes_label_key.IDKubernetesLabelKey.GetString(), engineGuidStrs, ) if err != nil { @@ -174,7 +174,7 @@ func getMatchingEngineKubernetesResources( ctx, kubernetesManager, engineMatchLabels, - label_key_consts.IDKubernetesLabelKey.GetString(), + kubernetes_label_key.IDKubernetesLabelKey.GetString(), engineGuidStrs, ) if err != nil { @@ -219,7 +219,7 @@ func getMatchingEngineKubernetesResources( kubernetesManager, namespaceName, engineMatchLabels, - label_key_consts.IDKubernetesLabelKey.GetString(), + kubernetes_label_key.IDKubernetesLabelKey.GetString(), map[string]bool{ engineGuidStr: true, }, @@ -247,7 +247,7 @@ func getMatchingEngineKubernetesResources( kubernetesManager, namespaceName, engineMatchLabels, - label_key_consts.IDKubernetesLabelKey.GetString(), + kubernetes_label_key.IDKubernetesLabelKey.GetString(), map[string]bool{ engineGuidStr: true, }, @@ -275,7 +275,7 @@ func getMatchingEngineKubernetesResources( kubernetesManager, namespaceName, engineMatchLabels, - label_key_consts.IDKubernetesLabelKey.GetString(), + kubernetes_label_key.IDKubernetesLabelKey.GetString(), map[string]bool{ engineGuidStr: true, }, @@ -307,8 +307,8 @@ func getMatchingEngineKubernetesResources( func getEngineMatchLabels() map[string]string { engineMatchLabels := map[string]string{ - label_key_consts.AppIDKubernetesLabelKey.GetString(): label_value_consts.AppIDKubernetesLabelValue.GetString(), - label_key_consts.KurtosisResourceTypeKubernetesLabelKey.GetString(): label_value_consts.EngineKurtosisResourceTypeKubernetesLabelValue.GetString(), + kubernetes_label_key.AppIDKubernetesLabelKey.GetString(): label_value_consts.AppIDKubernetesLabelValue.GetString(), + kubernetes_label_key.KurtosisResourceTypeKubernetesLabelKey.GetString(): label_value_consts.EngineKurtosisResourceTypeKubernetesLabelValue.GetString(), } return engineMatchLabels } diff --git a/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_kurtosis_backend/kubernetes_kurtosis_backend.go b/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_kurtosis_backend/kubernetes_kurtosis_backend.go index c997c9c845..fb4bb19355 100644 --- a/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_kurtosis_backend/kubernetes_kurtosis_backend.go +++ b/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_kurtosis_backend/kubernetes_kurtosis_backend.go @@ -7,7 +7,7 @@ import ( "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_kurtosis_backend/user_services_functions" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_manager" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider" - "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/label_key_consts" + "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_label_key" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/label_value_consts" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/compute_resources" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/enclave" @@ -472,7 +472,7 @@ func (backend *KubernetesKurtosisBackend) getEnclaveNamespaceName(ctx context.Co var namespaceName string if backend.cliModeArgs != nil || backend.engineServerModeArgs != nil { matchLabels := getEnclaveMatchLabels() - matchLabels[label_key_consts.EnclaveUUIDKubernetesLabelKey.GetString()] = string(enclaveUuid) + matchLabels[kubernetes_label_key.EnclaveUUIDKubernetesLabelKey.GetString()] = string(enclaveUuid) namespaces, err := backend.kubernetesManager.GetNamespacesByLabels(ctx, matchLabels) if err != nil { @@ -507,8 +507,8 @@ func (backend *KubernetesKurtosisBackend) getEnclaveNamespaceName(ctx context.Co func getEnclaveMatchLabels() map[string]string { matchLabels := map[string]string{ - label_key_consts.AppIDKubernetesLabelKey.GetString(): label_value_consts.AppIDKubernetesLabelValue.GetString(), - label_key_consts.KurtosisResourceTypeKubernetesLabelKey.GetString(): label_value_consts.EnclaveKurtosisResourceTypeKubernetesLabelValue.GetString(), + kubernetes_label_key.AppIDKubernetesLabelKey.GetString(): label_value_consts.AppIDKubernetesLabelValue.GetString(), + kubernetes_label_key.KurtosisResourceTypeKubernetesLabelKey.GetString(): label_value_consts.EnclaveKurtosisResourceTypeKubernetesLabelValue.GetString(), } return matchLabels } diff --git a/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_kurtosis_backend/kubernetes_kurtosis_backend_api_container_functions.go b/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_kurtosis_backend/kubernetes_kurtosis_backend_api_container_functions.go index c568f1e672..977d3fe44d 100644 --- a/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_kurtosis_backend/kubernetes_kurtosis_backend_api_container_functions.go +++ b/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_kurtosis_backend/kubernetes_kurtosis_backend_api_container_functions.go @@ -6,7 +6,7 @@ import ( "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_kurtosis_backend/shared_helpers" kubernetes_manager_consts "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_manager/consts" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_resource_collectors" - "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/label_key_consts" + "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_label_key" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/label_value_consts" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/api_container" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/enclave" @@ -714,7 +714,7 @@ func (backend *KubernetesKurtosisBackend) getMatchingApiContainerKubernetesResou ctx, backend.kubernetesManager, enclaveMatchLabels, - label_key_consts.EnclaveUUIDKubernetesLabelKey.GetString(), + kubernetes_label_key.EnclaveUUIDKubernetesLabelKey.GetString(), enclaveIdsStrSet, ) if err != nil { @@ -742,7 +742,7 @@ func (backend *KubernetesKurtosisBackend) getMatchingApiContainerKubernetesResou backend.kubernetesManager, namespaceName, apiContainerMatchLabels, - label_key_consts.EnclaveUUIDKubernetesLabelKey.GetString(), + kubernetes_label_key.EnclaveUUIDKubernetesLabelKey.GetString(), map[string]bool{ enclaveIdStr: true, }, @@ -781,7 +781,7 @@ func (backend *KubernetesKurtosisBackend) getMatchingApiContainerKubernetesResou backend.kubernetesManager, namespaceName, apiContainerMatchLabels, - label_key_consts.EnclaveUUIDKubernetesLabelKey.GetString(), + kubernetes_label_key.EnclaveUUIDKubernetesLabelKey.GetString(), map[string]bool{ enclaveIdStr: true, }, @@ -817,7 +817,7 @@ func (backend *KubernetesKurtosisBackend) getMatchingApiContainerKubernetesResou backend.kubernetesManager, namespaceName, apiContainerMatchLabels, - label_key_consts.EnclaveUUIDKubernetesLabelKey.GetString(), + kubernetes_label_key.EnclaveUUIDKubernetesLabelKey.GetString(), map[string]bool{ enclaveIdStr: true, }, @@ -853,7 +853,7 @@ func (backend *KubernetesKurtosisBackend) getMatchingApiContainerKubernetesResou backend.kubernetesManager, namespaceName, apiContainerMatchLabels, - label_key_consts.EnclaveUUIDKubernetesLabelKey.GetString(), + kubernetes_label_key.EnclaveUUIDKubernetesLabelKey.GetString(), map[string]bool{ enclaveIdStr: true, }, @@ -889,7 +889,7 @@ func (backend *KubernetesKurtosisBackend) getMatchingApiContainerKubernetesResou backend.kubernetesManager, namespaceName, apiContainerMatchLabels, - label_key_consts.EnclaveUUIDKubernetesLabelKey.GetString(), + kubernetes_label_key.EnclaveUUIDKubernetesLabelKey.GetString(), map[string]bool{ enclaveIdStr: true, }, @@ -1087,8 +1087,8 @@ func getApiContainerContainersAndVolumes( func getApiContainerMatchLabels() map[string]string { engineMatchLabels := map[string]string{ - label_key_consts.AppIDKubernetesLabelKey.GetString(): label_value_consts.AppIDKubernetesLabelValue.GetString(), - label_key_consts.KurtosisResourceTypeKubernetesLabelKey.GetString(): label_value_consts.APIContainerKurtosisResourceTypeKubernetesLabelValue.GetString(), + kubernetes_label_key.AppIDKubernetesLabelKey.GetString(): label_value_consts.AppIDKubernetesLabelValue.GetString(), + kubernetes_label_key.KurtosisResourceTypeKubernetesLabelKey.GetString(): label_value_consts.APIContainerKurtosisResourceTypeKubernetesLabelValue.GetString(), } return engineMatchLabels } diff --git a/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_kurtosis_backend/kubernetes_kurtosis_backend_enclave_functions.go b/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_kurtosis_backend/kubernetes_kurtosis_backend_enclave_functions.go index 46d46b74fe..c651cb4480 100644 --- a/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_kurtosis_backend/kubernetes_kurtosis_backend_enclave_functions.go +++ b/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_kurtosis_backend/kubernetes_kurtosis_backend_enclave_functions.go @@ -3,13 +3,13 @@ package kubernetes_kurtosis_backend import ( "context" "fmt" + "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_label_key" "strings" "time" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_kurtosis_backend/shared_helpers" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_resource_collectors" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_annotation_key_consts" - "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/label_key_consts" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/label_value_consts" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/container" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/enclave" @@ -59,8 +59,8 @@ func (backend *KubernetesKurtosisBackend) CreateEnclave( teardownContext := context.Background() searchNamespaceLabels := map[string]string{ - label_key_consts.AppIDKubernetesLabelKey.GetString(): label_value_consts.AppIDKubernetesLabelValue.GetString(), - label_key_consts.EnclaveUUIDKubernetesLabelKey.GetString(): string(enclaveUuid), + kubernetes_label_key.AppIDKubernetesLabelKey.GetString(): label_value_consts.AppIDKubernetesLabelValue.GetString(), + kubernetes_label_key.EnclaveUUIDKubernetesLabelKey.GetString(): string(enclaveUuid), } namespaceList, err := backend.kubernetesManager.GetNamespacesByLabels(ctx, searchNamespaceLabels) if err != nil { @@ -449,7 +449,7 @@ func (backend *KubernetesKurtosisBackend) getMatchingEnclaveKubernetesResources( ctx, backend.kubernetesManager, enclaveMatchLabels, - label_key_consts.EnclaveUUIDKubernetesLabelKey.GetString(), + kubernetes_label_key.EnclaveUUIDKubernetesLabelKey.GetString(), enclaveIdsStrSet, ) if err != nil { @@ -514,8 +514,8 @@ func (backend *KubernetesKurtosisBackend) createGetEnclaveResourcesOperation( namespaceName := namespace.GetName() enclaveWithIDMatchLabels := map[string]string{ - label_key_consts.AppIDKubernetesLabelKey.GetString(): label_value_consts.AppIDKubernetesLabelValue.GetString(), - label_key_consts.EnclaveUUIDKubernetesLabelKey.GetString(): enclaveIdStr, + kubernetes_label_key.AppIDKubernetesLabelKey.GetString(): label_value_consts.AppIDKubernetesLabelValue.GetString(), + kubernetes_label_key.EnclaveUUIDKubernetesLabelKey.GetString(): enclaveIdStr, } // Pods and Services diff --git a/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_kurtosis_backend/kubernetes_kurtosis_backend_helper.go b/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_kurtosis_backend/kubernetes_kurtosis_backend_helper.go index 4f08d0dc9d..e079dce607 100644 --- a/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_kurtosis_backend/kubernetes_kurtosis_backend_helper.go +++ b/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_kurtosis_backend/kubernetes_kurtosis_backend_helper.go @@ -3,7 +3,7 @@ package kubernetes_kurtosis_backend import ( "context" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_manager" - "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/label_key_consts" + "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_label_key" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/metrics_reporting" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/enclave" @@ -89,11 +89,11 @@ func GetApiContainerBackend( } namespaceLabels := namespace.GetLabels() - enclaveIdStr, found := namespaceLabels[label_key_consts.IDKubernetesLabelKey.GetString()] + enclaveIdStr, found := namespaceLabels[kubernetes_label_key.IDKubernetesLabelKey.GetString()] if !found { return nil, stacktrace.NewError( "Expected to find enclave ID label '%v' on namespace '%v' but none was found", - label_key_consts.IDKubernetesLabelKey.GetString(), + kubernetes_label_key.IDKubernetesLabelKey.GetString(), namespaceName, ) } diff --git a/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_kurtosis_backend/shared_helpers/shared_helpers.go b/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_kurtosis_backend/shared_helpers/shared_helpers.go index 4839628b4c..e2a65bd116 100644 --- a/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_kurtosis_backend/shared_helpers/shared_helpers.go +++ b/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_kurtosis_backend/shared_helpers/shared_helpers.go @@ -6,7 +6,6 @@ import ( "encoding/json" "errors" "fmt" - "github.com/gammazero/workerpool" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_kurtosis_backend/consts" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_manager" @@ -17,7 +16,6 @@ import ( "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_label_key" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_label_value" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_port_spec_serializer" - "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/label_key_consts" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/label_value_consts" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/container" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/enclave" @@ -160,7 +158,7 @@ func GetEnclaveNamespaceName( var namespaceName string if cliModeArgs != nil || engineServerModeArgs != nil { matchLabels := getEnclaveMatchLabels() - matchLabels[label_key_consts.EnclaveUUIDKubernetesLabelKey.GetString()] = string(enclaveId) + matchLabels[kubernetes_label_key.EnclaveUUIDKubernetesLabelKey.GetString()] = string(enclaveId) namespaces, err := kubernetesManager.GetNamespacesByLabels(ctx, matchLabels) if err != nil { @@ -287,9 +285,9 @@ func GetUserServiceKubernetesResourcesMatchingGuids( } kubernetesResourceSearchLabels := map[string]string{ - label_key_consts.AppIDKubernetesLabelKey.GetString(): label_value_consts.AppIDKubernetesLabelValue.GetString(), - label_key_consts.EnclaveUUIDKubernetesLabelKey.GetString(): string(enclaveId), - label_key_consts.KurtosisResourceTypeKubernetesLabelKey.GetString(): label_value_consts.UserServiceKurtosisResourceTypeKubernetesLabelValue.GetString(), + kubernetes_label_key.AppIDKubernetesLabelKey.GetString(): label_value_consts.AppIDKubernetesLabelValue.GetString(), + kubernetes_label_key.EnclaveUUIDKubernetesLabelKey.GetString(): string(enclaveId), + kubernetes_label_key.KurtosisResourceTypeKubernetesLabelKey.GetString(): label_value_consts.UserServiceKurtosisResourceTypeKubernetesLabelValue.GetString(), } results := map[service.ServiceUUID]*UserServiceKubernetesResources{} @@ -300,7 +298,7 @@ func GetUserServiceKubernetesResourcesMatchingGuids( kubernetesManager, namespaceName, kubernetesResourceSearchLabels, - label_key_consts.GUIDKubernetesLabelKey.GetString(), + kubernetes_label_key.GUIDKubernetesLabelKey.GetString(), postFilterLabelValues, ) if err != nil { @@ -337,7 +335,7 @@ func GetUserServiceKubernetesResourcesMatchingGuids( kubernetesManager, namespaceName, kubernetesResourceSearchLabels, - label_key_consts.GUIDKubernetesLabelKey.GetString(), + kubernetes_label_key.GUIDKubernetesLabelKey.GetString(), postFilterLabelValues, ) if err != nil { @@ -399,9 +397,9 @@ func GetUserServiceObjectsFromKubernetesResources( } serviceLabels := kubernetesService.Labels - idLabelStr, found := serviceLabels[label_key_consts.IDKubernetesLabelKey.GetString()] + idLabelStr, found := serviceLabels[kubernetes_label_key.IDKubernetesLabelKey.GetString()] if !found { - return nil, stacktrace.NewError("Expected to find label '%v' on the Kubernetes service but none was found", label_key_consts.IDKubernetesLabelKey.GetString()) + return nil, stacktrace.NewError("Expected to find label '%v' on the Kubernetes service but none was found", kubernetes_label_key.IDKubernetesLabelKey.GetString()) } serviceId := service.ServiceName(idLabelStr) @@ -810,8 +808,8 @@ func BuildCombinedError(errorsById map[string]error, titleStr string) error { // ==================================================================================================== func getEnclaveMatchLabels() map[string]string { matchLabels := map[string]string{ - label_key_consts.AppIDKubernetesLabelKey.GetString(): label_value_consts.AppIDKubernetesLabelValue.GetString(), - label_key_consts.KurtosisResourceTypeKubernetesLabelKey.GetString(): label_value_consts.EnclaveKurtosisResourceTypeKubernetesLabelValue.GetString(), + kubernetes_label_key.AppIDKubernetesLabelKey.GetString(): label_value_consts.AppIDKubernetesLabelValue.GetString(), + kubernetes_label_key.KurtosisResourceTypeKubernetesLabelKey.GetString(): label_value_consts.EnclaveKurtosisResourceTypeKubernetesLabelValue.GetString(), } return matchLabels } diff --git a/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_kurtosis_backend/user_services_functions/start_user_services.go b/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_kurtosis_backend/user_services_functions/start_user_services.go index 8026583ea8..0328da7290 100644 --- a/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_kurtosis_backend/user_services_functions/start_user_services.go +++ b/container-engine-lib/lib/backend_impls/kubernetes/kubernetes_kurtosis_backend/user_services_functions/start_user_services.go @@ -9,7 +9,6 @@ import ( "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_label_key" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_label_value" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_port_spec_serializer" - "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/label_key_consts" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/label_value_consts" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/enclave" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/port_spec" @@ -376,7 +375,7 @@ func createStartServiceOperation( }() // Create the pod - podAttributes, err := enclaveObjAttributesProvider.ForUserServicePod(serviceUuid, serviceName, privatePorts) + podAttributes, err := enclaveObjAttributesProvider.ForUserServicePod(serviceUuid, serviceName, privatePorts, serviceConfig.GetLabels()) if err != nil { return nil, stacktrace.Propagate(err, "An error occurred getting attributes for new pod for service with UUID '%v'", serviceUuid) } @@ -796,9 +795,9 @@ func createRegisterUserServiceOperation( return nil, stacktrace.Propagate(err, "An error occurred creating a Kubernetes pod match label value for the enclave ID '%v'", enclaveID) } matchedPodLabels := map[*kubernetes_label_key.KubernetesLabelKey]*kubernetes_label_value.KubernetesLabelValue{ - label_key_consts.AppIDKubernetesLabelKey: label_value_consts.AppIDKubernetesLabelValue, - label_key_consts.EnclaveUUIDKubernetesLabelKey: enclaveIdLabelValue, - label_key_consts.GUIDKubernetesLabelKey: serviceUuidLabelValue, + kubernetes_label_key.AppIDKubernetesLabelKey: label_value_consts.AppIDKubernetesLabelValue, + kubernetes_label_key.EnclaveUUIDKubernetesLabelKey: enclaveIdLabelValue, + kubernetes_label_key.GUIDKubernetesLabelKey: serviceUuidLabelValue, } matchedPodLabelStrs := shared_helpers.GetStringMapFromLabelMap(matchedPodLabels) diff --git a/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/api_container_object_attributes_provider.go b/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/api_container_object_attributes_provider.go index c7b4ba0669..79e9707318 100644 --- a/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/api_container_object_attributes_provider.go +++ b/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/api_container_object_attributes_provider.go @@ -8,7 +8,6 @@ import ( "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_label_value" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_object_name" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_port_spec_serializer" - "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/label_key_consts" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/label_value_consts" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/enclave" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/port_spec" @@ -211,7 +210,7 @@ func (provider *kubernetesApiContainerObjectAttributesProviderImpl) getLabelsFor return nil, stacktrace.Propagate(err, "Failed to create Kubernetes label value from enclaveId '%v'", provider.enclaveId) } return map[*kubernetes_label_key.KubernetesLabelKey]*kubernetes_label_value.KubernetesLabelValue{ - label_key_consts.KurtosisResourceTypeKubernetesLabelKey: label_value_consts.APIContainerKurtosisResourceTypeKubernetesLabelValue, - label_key_consts.EnclaveUUIDKubernetesLabelKey: enclaveIdLabelValue, + kubernetes_label_key.KurtosisResourceTypeKubernetesLabelKey: label_value_consts.APIContainerKurtosisResourceTypeKubernetesLabelValue, + kubernetes_label_key.EnclaveUUIDKubernetesLabelKey: enclaveIdLabelValue, }, nil } diff --git a/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/enclave_object_attributes_provider.go b/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/enclave_object_attributes_provider.go index 620220dd79..d50c547d35 100644 --- a/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/enclave_object_attributes_provider.go +++ b/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/enclave_object_attributes_provider.go @@ -10,7 +10,6 @@ import ( "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_label_value" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_object_name" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_port_spec_serializer" - "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/label_key_consts" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/label_value_consts" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/enclave" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/port_spec" @@ -37,6 +36,7 @@ type KubernetesEnclaveObjectAttributesProvider interface { uuid service.ServiceUUID, id service.ServiceName, privatePorts map[string]*port_spec.PortSpec, + userLabels map[string]string, ) (KubernetesObjectAttributes, error) ForSinglePersistentDirectoryVolume( serviceUUID service.ServiceUUID, @@ -134,7 +134,7 @@ func (provider *kubernetesEnclaveObjectAttributesProviderImpl) ForUserServiceSer string(serviceUUID), ) } - labels[label_key_consts.KurtosisResourceTypeKubernetesLabelKey] = label_value_consts.UserServiceKurtosisResourceTypeKubernetesLabelValue + labels[kubernetes_label_key.KurtosisResourceTypeKubernetesLabelKey] = label_value_consts.UserServiceKurtosisResourceTypeKubernetesLabelValue //No userServiceService annotations. annotations := map[*kubernetes_annotation_key.KubernetesAnnotationKey]*kubernetes_annotation_value.KubernetesAnnotationValue{} @@ -151,6 +151,7 @@ func (provider *kubernetesEnclaveObjectAttributesProviderImpl) ForUserServicePod serviceUUID service.ServiceUUID, serviceName service.ServiceName, privatePorts map[string]*port_spec.PortSpec, + userLabels map[string]string, ) (KubernetesObjectAttributes, error) { name, err := getKubernetesObjectName(serviceName) if err != nil { @@ -171,7 +172,20 @@ func (provider *kubernetesEnclaveObjectAttributesProviderImpl) ForUserServicePod serviceUUID, ) } - labels[label_key_consts.KurtosisResourceTypeKubernetesLabelKey] = label_value_consts.UserServiceKurtosisResourceTypeKubernetesLabelValue + labels[kubernetes_label_key.KurtosisResourceTypeKubernetesLabelKey] = label_value_consts.UserServiceKurtosisResourceTypeKubernetesLabelValue + + // add user custom label + for userLabelKey, userLabelValue := range userLabels { + kubernetesLabelKey, err := kubernetes_label_key.CreateNewKubernetesUserCustomLabelKey(userLabelKey) + if err != nil { + return nil, stacktrace.Propagate(err, "An error occurred creating a new user custom Kubernetes label key '%s'", userLabelKey) + } + kubernetesLabelValue, err := kubernetes_label_value.CreateNewKubernetesLabelValue(userLabelValue) + if err != nil { + return nil, stacktrace.Propagate(err, "An error occurred creating a new user custom Kubernetes label value '%s'", userLabelValue) + } + labels[kubernetesLabelKey] = kubernetesLabelValue + } annotations := map[*kubernetes_annotation_key.KubernetesAnnotationKey]*kubernetes_annotation_value.KubernetesAnnotationValue{ kubernetes_annotation_key_consts.PortSpecsKubernetesAnnotationKey: serializedPortSpecsAnnotationValue, @@ -249,8 +263,8 @@ func (provider *kubernetesEnclaveObjectAttributesProviderImpl) getLabelsForEncla return nil, stacktrace.Propagate(err, "Failed to create Kubernetes label value from enclaveId '%v'", provider.enclaveId) } return map[*kubernetes_label_key.KubernetesLabelKey]*kubernetes_label_value.KubernetesLabelValue{ - label_key_consts.KurtosisResourceTypeKubernetesLabelKey: label_value_consts.EnclaveKurtosisResourceTypeKubernetesLabelValue, - label_key_consts.EnclaveUUIDKubernetesLabelKey: enclaveIdLabelValue, + kubernetes_label_key.KurtosisResourceTypeKubernetesLabelKey: label_value_consts.EnclaveKurtosisResourceTypeKubernetesLabelValue, + kubernetes_label_key.EnclaveUUIDKubernetesLabelKey: enclaveIdLabelValue, }, nil } @@ -263,7 +277,7 @@ func (provider *kubernetesEnclaveObjectAttributesProviderImpl) getLabelsForEncla if err != nil { return nil, stacktrace.Propagate(err, "An error occurred creating a Kubernetes label value from UUID string '%v'", uuid) } - labels[label_key_consts.GUIDKubernetesLabelKey] = uuidLabelValue + labels[kubernetes_label_key.GUIDKubernetesLabelKey] = uuidLabelValue return labels, nil } @@ -276,7 +290,7 @@ func (provider *kubernetesEnclaveObjectAttributesProviderImpl) getLabelsForEncla if err != nil { return nil, stacktrace.Propagate(err, "An error occurred creating a Kubernetes label value from ID string '%v'", id) } - labels[label_key_consts.IDKubernetesLabelKey] = idLabelValue + labels[kubernetes_label_key.IDKubernetesLabelKey] = idLabelValue return labels, nil } diff --git a/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/engine_object_attributes_provider.go b/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/engine_object_attributes_provider.go index c6035ce879..4cb9e48494 100644 --- a/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/engine_object_attributes_provider.go +++ b/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/engine_object_attributes_provider.go @@ -8,7 +8,6 @@ import ( "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_label_value" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_object_name" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_port_spec_serializer" - "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/label_key_consts" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/label_value_consts" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/engine" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/port_spec" @@ -218,9 +217,9 @@ func (provider *kubernetesEngineObjectAttributesProviderImpl) getEngineObjectLab // ID and GUID are the same here labels := map[*kubernetes_label_key.KubernetesLabelKey]*kubernetes_label_value.KubernetesLabelValue{ - label_key_consts.KurtosisResourceTypeKubernetesLabelKey: label_value_consts.EngineKurtosisResourceTypeKubernetesLabelValue, - label_key_consts.IDKubernetesLabelKey: guidLabelValue, - label_key_consts.GUIDKubernetesLabelKey: guidLabelValue, + kubernetes_label_key.KurtosisResourceTypeKubernetesLabelKey: label_value_consts.EngineKurtosisResourceTypeKubernetesLabelValue, + kubernetes_label_key.IDKubernetesLabelKey: guidLabelValue, + kubernetes_label_key.GUIDKubernetesLabelKey: guidLabelValue, } return labels, nil } diff --git a/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_label_key/kubernetes_label_key.go b/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_label_key/kubernetes_label_key.go index c1315ac756..8efed6cbb6 100644 --- a/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_label_key/kubernetes_label_key.go +++ b/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_label_key/kubernetes_label_key.go @@ -12,16 +12,37 @@ type KubernetesLabelKey struct { } // NOTE: This is ONLY for areas where the label is declared statically!! Any sort of dynamic/runtime label creation -// should use CreateNewKubernetesLabelKey +// should use createNewKubernetesLabelKey func MustCreateNewKubernetesLabelKey(str string) *KubernetesLabelKey { - key, err := CreateNewKubernetesLabelKey(str) + key, err := createNewKubernetesLabelKey(str) if err != nil { panic(err) } return key } -func CreateNewKubernetesLabelKey(str string) (*KubernetesLabelKey, error) { - if err := validateLabelKey(str); err != nil { + +// CreateNewKubernetesUserCustomLabelKey creates a custom uer Kubernetes label with the Kurtosis custom user prefix +func CreateNewKubernetesUserCustomLabelKey(str string) (*KubernetesLabelKey, error) { + if err := validateNotEmptyUserCustomLabelKey(str); err != nil { + return nil, stacktrace.NewError("Received an empty user custom label key") + } + labelKeyStr := customUserLabelsKeyPrefixStr + str + return createNewKubernetesLabelKey(labelKeyStr) +} + +func ValidateUserCustomLabelKey(str string) error { + if err := validateNotEmptyUserCustomLabelKey(str); err != nil { + return stacktrace.Propagate(err, "Received an empty user custom label key") + } + labelKeyStr := customUserLabelsKeyPrefixStr + str + if err := validate(labelKeyStr); err != nil { + return stacktrace.Propagate(err, "User custom label key '%s' is not valid", str) + } + return nil +} + +func createNewKubernetesLabelKey(str string) (*KubernetesLabelKey, error) { + if err := validate(str); err != nil { return nil, stacktrace.Propagate(err, "Label value string '%v' doesn't pass validation of being a Kubernetes label key", str) } @@ -31,12 +52,19 @@ func (key *KubernetesLabelKey) GetString() string { return key.value } -func validateLabelKey(str string) error { +func validateNotEmptyUserCustomLabelKey(str string) error { + str = strings.TrimSpace(str) + if str == "" { + return stacktrace.NewError("User custom label key can't be an empty string") + } + return nil +} + +func validate(str string) error { validationErrs := validation.IsQualifiedName(str) if len(validationErrs) > 0 { errString := strings.Join(validationErrs, "\n\n") return stacktrace.NewError("Expected label string '%v' to be a valid Kubernetes label key, instead it failed validation:\n%+v", str, errString) } return nil - } diff --git a/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_label_key/kubernetes_label_key_test.go b/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_label_key/kubernetes_label_key_test.go index fab9fe17fd..6b9c769253 100644 --- a/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_label_key/kubernetes_label_key_test.go +++ b/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_label_key/kubernetes_label_key_test.go @@ -6,28 +6,58 @@ import ( "testing" ) -var testLabelsWithValidity = map[string]bool{ - "": false, - " ": false, // whitespace not allowed - "a": true, - "aaa": true, - "aAa": true, // caps allowed - "a99a9": true, - "a.7.3.5": true, - "kurtosistech.com/app-id": true, - "foo_blah": true, +const ( + oneRandomChar = "a" + maxLabelLength = 63 +) + +var testLabelsWithValidity = map[string][]bool{ + "": {false, false}, + " ": {false, false}, // whitespace not allowed + "a": {true, true}, + "aaa": {true, true}, + "aAa": {true, true}, // caps allowed + "a99a9": {true, true}, + "a.7.3.5": {true, true}, + "kurtosistech.com/app-id": {true, false}, + "kurtosistech.com/app_id": {true, false}, + "foo_blah": {true, true}, + "com.kurtosistech.app-id": {true, true}, // Docker labels standard allowed } func TestEdgeCaseLabels(t *testing.T) { for label, shouldPass := range testLabelsWithValidity { - _, err := CreateNewKubernetesLabelKey(label) + _, err := createNewKubernetesLabelKey(label) didPass := err == nil - require.Equal(t, shouldPass, didPass, "Expected label key string '%v' validity to be '%v' but was '%v'", label, shouldPass, didPass) + require.Equal(t, shouldPass[0], didPass, "Expected label key string '%v' validity to be '%v' but was '%v'", label, shouldPass[0], didPass) + _, err = CreateNewKubernetesUserCustomLabelKey(label) + didPass = err == nil + require.Equal(t, shouldPass[1], didPass, "Expected user custom label key string '%v' validity to be '%v' but was '%v'", label, shouldPass[1], didPass) } } func TestTooLongLabel(t *testing.T) { - invalidLabel := strings.Repeat("a", 9999) - _, err := CreateNewKubernetesLabelKey(invalidLabel) + invalidLabel := strings.Repeat(oneRandomChar, 9999) + _, err := createNewKubernetesLabelKey(invalidLabel) + require.Error(t, err) + _, err = CreateNewKubernetesUserCustomLabelKey(invalidLabel) + require.Error(t, err) +} + +func TestMaxAllowedLabel(t *testing.T) { + validMaxLabel := strings.Repeat(oneRandomChar, maxLabelLength) + _, err := createNewKubernetesLabelKey(validMaxLabel) + require.NoError(t, err) + + overValidMaxLabel := validMaxLabel + oneRandomChar + _, err = createNewKubernetesLabelKey(overValidMaxLabel) + require.Error(t, err) + + userCustomValidMaxLabel := strings.Repeat(oneRandomChar, maxLabelLength) + _, err = CreateNewKubernetesUserCustomLabelKey(userCustomValidMaxLabel) + require.NoError(t, err) + + overUserCustomValidMaxLabel := userCustomValidMaxLabel + oneRandomChar + _, err = CreateNewKubernetesUserCustomLabelKey(overUserCustomValidMaxLabel) require.Error(t, err) } diff --git a/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/label_key_consts/label_key_consts.go b/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_label_key/label_key_consts.go similarity index 55% rename from container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/label_key_consts/label_key_consts.go rename to container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_label_key/label_key_consts.go index 88ad040312..8cbd634e3b 100644 --- a/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/label_key_consts/label_key_consts.go +++ b/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_label_key/label_key_consts.go @@ -1,8 +1,4 @@ -package label_key_consts - -import ( - "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_label_key" -) +package kubernetes_label_key const ( // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! DO NOT CHANGE THESE VALUES !!!!!!!!!!!!!!!!!!!!!!!!!!!!! @@ -11,9 +7,11 @@ const ( // // If you add new immutable values to this section, MAKE SURE TO UPDATE THE UNIT TEST! // These immutable values track resources between Kurtosis versions. - labelKeyPrefixStr = "kurtosistech.com/" - appIdLabelKeyStr = labelKeyPrefixStr + "app-id" - resourceTypeLabelKeyStr = labelKeyPrefixStr + "resource-type" + kurtosisDomain = "kurtosistech.com" + labelKeyPrefixStr = kurtosisDomain + "/" + appIdLabelKeyStr = labelKeyPrefixStr + "app-id" + resourceTypeLabelKeyStr = labelKeyPrefixStr + "resource-type" + customUserLabelsKeyPrefixStr = kurtosisDomain + ".custom/" // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! DO NOT CHANGE THESE VALUES !!!!!!!!!!!!!!!!!!!!!!!!!!!!! volumeTypeLabelKeyStr = labelKeyPrefixStr + "volume-type" @@ -38,14 +36,14 @@ const ( // which will cause a resource leak on the user's cluster! // // If you add new immutable values to this section, MAKE SURE TO UPDATE THE UNIT TEST! -var AppIDKubernetesLabelKey = kubernetes_label_key.MustCreateNewKubernetesLabelKey(appIdLabelKeyStr) -var KurtosisResourceTypeKubernetesLabelKey = kubernetes_label_key.MustCreateNewKubernetesLabelKey(resourceTypeLabelKeyStr) +var AppIDKubernetesLabelKey = MustCreateNewKubernetesLabelKey(appIdLabelKeyStr) +var KurtosisResourceTypeKubernetesLabelKey = MustCreateNewKubernetesLabelKey(resourceTypeLabelKeyStr) // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! DO NOT CHANGE THESE VALUES !!!!!!!!!!!!!!!!!!!!!!!!!!!!! -var KurtosisVolumeTypeKubernetesLabelKey = kubernetes_label_key.MustCreateNewKubernetesLabelKey(volumeTypeLabelKeyStr) -var IDKubernetesLabelKey = kubernetes_label_key.MustCreateNewKubernetesLabelKey(idLabelKeyStr) -var GUIDKubernetesLabelKey = kubernetes_label_key.MustCreateNewKubernetesLabelKey(guidLabelKeyStr) -var EnclaveUUIDKubernetesLabelKey = kubernetes_label_key.MustCreateNewKubernetesLabelKey(enclaveIdLabelKeyStr) -var EnclaveNameKubernetesLabelKey = kubernetes_label_key.MustCreateNewKubernetesLabelKey(enclaveNameLabelKeyStr) -var UserServiceGUIDKubernetesLabelKey = kubernetes_label_key.MustCreateNewKubernetesLabelKey(userServiceGuidKeyStr) +var KurtosisVolumeTypeKubernetesLabelKey = MustCreateNewKubernetesLabelKey(volumeTypeLabelKeyStr) +var IDKubernetesLabelKey = MustCreateNewKubernetesLabelKey(idLabelKeyStr) +var GUIDKubernetesLabelKey = MustCreateNewKubernetesLabelKey(guidLabelKeyStr) +var EnclaveUUIDKubernetesLabelKey = MustCreateNewKubernetesLabelKey(enclaveIdLabelKeyStr) +var EnclaveNameKubernetesLabelKey = MustCreateNewKubernetesLabelKey(enclaveNameLabelKeyStr) +var UserServiceGUIDKubernetesLabelKey = MustCreateNewKubernetesLabelKey(userServiceGuidKeyStr) diff --git a/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/label_key_consts/label_key_consts_test.go b/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_label_key/label_key_consts_test.go similarity index 89% rename from container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/label_key_consts/label_key_consts_test.go rename to container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_label_key/label_key_consts_test.go index c29deeb77b..ea5610e641 100644 --- a/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/label_key_consts/label_key_consts_test.go +++ b/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_label_key/label_key_consts_test.go @@ -1,7 +1,6 @@ -package label_key_consts +package kubernetes_label_key import ( - "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_label_key" "github.com/stretchr/testify/require" "testing" ) @@ -23,7 +22,7 @@ var crossVersionLabelKeyStringsToEnsure = map[string]string{ } // These are the publicly accessible keys that correspond to the private string constants. They need to stay the same. -var crossVersionLabelKeysToEnsure = map[*kubernetes_label_key.KubernetesLabelKey]string{ +var crossVersionLabelKeysToEnsure = map[*KubernetesLabelKey]string{ AppIDKubernetesLabelKey: expectedAppIdLabelKeyStr, KurtosisResourceTypeKubernetesLabelKey: expectedResourceTypeLabelKeyStr, } diff --git a/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_label_value/kubernetes_label_value.go b/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_label_value/kubernetes_label_value.go index fc748c0665..7099115c9e 100644 --- a/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_label_value/kubernetes_label_value.go +++ b/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_label_value/kubernetes_label_value.go @@ -23,7 +23,7 @@ func MustCreateNewKubernetesLabelValue(str string) *KubernetesLabelValue { } func CreateNewKubernetesLabelValue(labelValue string) (*KubernetesLabelValue, error) { - if err := validateLabelValue(labelValue); err != nil { + if err := ValidateKubernetesLabelValue(labelValue); err != nil { return nil, stacktrace.Propagate(err, "Label value string '%v' doesn't pass validation of being a Kubernetes label value", labelValue) } @@ -34,8 +34,8 @@ func (key *KubernetesLabelValue) GetString() string { return key.value } -// validateLabelStr throws an error if str isn't a "qualified name" in Kubernetes -func validateLabelValue(str string) error { +// ValidateKubernetesLabelValue throws an error if str isn't a "qualified name" in Kubernetes +func ValidateKubernetesLabelValue(str string) error { validationErrs := validation.IsValidLabelValue(str) if len(validationErrs) > 0 { errString := strings.Join(validationErrs, "\n\n") diff --git a/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/object_attributes.go b/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/object_attributes.go index 7051fc843c..507e99487e 100644 --- a/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/object_attributes.go +++ b/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/object_attributes.go @@ -6,14 +6,13 @@ import ( "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_label_key" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_label_value" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_object_name" - "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/label_key_consts" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/label_value_consts" "github.com/kurtosis-tech/stacktrace" ) // Labels that get attached to EVERY Kurtosis object var globalLabels = map[*kubernetes_label_key.KubernetesLabelKey]*kubernetes_label_value.KubernetesLabelValue{ - label_key_consts.AppIDKubernetesLabelKey: label_value_consts.AppIDKubernetesLabelValue, + kubernetes_label_key.AppIDKubernetesLabelKey: label_value_consts.AppIDKubernetesLabelValue, // TODO container engine lib version?? } diff --git a/container-engine-lib/lib/backend_interface/objects/service/service_config.go b/container-engine-lib/lib/backend_interface/objects/service/service_config.go index 6d28d04aae..c1514f1407 100644 --- a/container-engine-lib/lib/backend_interface/objects/service/service_config.go +++ b/container-engine-lib/lib/backend_interface/objects/service/service_config.go @@ -41,9 +41,11 @@ type privateServiceConfig struct { MinCpuAllocationMilliCpus uint64 MinMemoryAllocationMegabytes uint64 + + Labels map[string]string } -func NewServiceConfig( +func CreateServiceConfig( containerImageName string, privatePorts map[string]*port_spec.PortSpec, publicPorts map[string]*port_spec.PortSpec, @@ -57,7 +59,13 @@ func NewServiceConfig( privateIPAddrPlaceholder string, minCpuMilliCores uint64, minMemoryMegaBytes uint64, -) *ServiceConfig { + labels map[string]string, +) (*ServiceConfig, error) { + + if err := ValidateServiceConfigLabels(labels); err != nil { + return nil, stacktrace.Propagate(err, "Invalid service config labels '%+v'", labels) + } + internalServiceConfig := &privateServiceConfig{ ContainerImageName: containerImageName, PrivatePorts: privatePorts, @@ -73,8 +81,9 @@ func NewServiceConfig( // The minimum resources specification is only available for kubernetes MinCpuAllocationMilliCpus: minCpuMilliCores, MinMemoryAllocationMegabytes: minMemoryMegaBytes, + Labels: labels, } - return &ServiceConfig{internalServiceConfig} + return &ServiceConfig{internalServiceConfig}, nil } func (serviceConfig *ServiceConfig) GetContainerImageName() string { @@ -131,6 +140,10 @@ func (serviceConfig *ServiceConfig) GetMinMemoryAllocationMegabytes() uint64 { return serviceConfig.privateServiceConfig.MinMemoryAllocationMegabytes } +func (serviceConfig *ServiceConfig) GetLabels() map[string]string { + return serviceConfig.privateServiceConfig.Labels +} + func (serviceConfig *ServiceConfig) MarshalJSON() ([]byte, error) { return json.Marshal(serviceConfig.privateServiceConfig) } diff --git a/container-engine-lib/lib/backend_interface/objects/service/service_config_test.go b/container-engine-lib/lib/backend_interface/objects/service/service_config_test.go index 952d72b73a..17091924a6 100644 --- a/container-engine-lib/lib/backend_interface/objects/service/service_config_test.go +++ b/container-engine-lib/lib/backend_interface/objects/service/service_config_test.go @@ -51,10 +51,11 @@ func TestServiceConfigMarshallers(t *testing.T) { require.Equal(t, originalServiceConfig.GetPrivateIPAddrPlaceholder(), newServiceConfig.GetPrivateIPAddrPlaceholder()) require.Equal(t, originalServiceConfig.GetMinCPUAllocationMillicpus(), newServiceConfig.GetMinCPUAllocationMillicpus()) require.Equal(t, originalServiceConfig.GetMinMemoryAllocationMegabytes(), newServiceConfig.GetMinMemoryAllocationMegabytes()) + require.Equal(t, originalServiceConfig.GetLabels(), newServiceConfig.GetLabels()) } func getServiceConfigForTest(t *testing.T, imageName string) *ServiceConfig { - return NewServiceConfig( + serviceConfig, err := CreateServiceConfig( imageName, testPrivatePorts(t), testPublicPorts(t), @@ -68,7 +69,13 @@ func getServiceConfigForTest(t *testing.T, imageName string) *ServiceConfig { "IP-ADDRESS", 100, 512, + map[string]string{ + "test-label-key": "test-label-value", + "test-second-label-key": "test-second-label-value", + }, ) + require.NoError(t, err) + return serviceConfig } func testPersistentDirectory() *service_directory.PersistentDirectories { diff --git a/container-engine-lib/lib/backend_interface/objects/service/service_config_validators.go b/container-engine-lib/lib/backend_interface/objects/service/service_config_validators.go new file mode 100644 index 0000000000..b38443cbde --- /dev/null +++ b/container-engine-lib/lib/backend_interface/objects/service/service_config_validators.go @@ -0,0 +1,31 @@ +package service + +import ( + "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_label_key" + "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_label_value" + "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_label_key" + "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_label_value" + "github.com/kurtosis-tech/stacktrace" +) + +func ValidateServiceConfigLabels(labels map[string]string) error { + for labelKey, labelValue := range labels { + + // key validations + if err := docker_label_key.ValidateUserCustomLabelKey(labelKey); err != nil { + return stacktrace.Propagate(err, "Invalid service config label key '%s'", labelKey) + } + if err := kubernetes_label_key.ValidateUserCustomLabelKey(labelKey); err != nil { + return stacktrace.Propagate(err, "Invalid service config label key '%s'", labelKey) + } + + // values validations + if err := docker_label_value.ValidateDockerLabelValue(labelValue); err != nil { + return stacktrace.Propagate(err, "Invalid service config label value '%s'", labelValue) + } + if err := kubernetes_label_value.ValidateKubernetesLabelValue(labelValue); err != nil { + return stacktrace.Propagate(err, "Invalid service config label value '%s'", labelValue) + } + } + return nil +} diff --git a/container-engine-lib/lib/backend_interface/objects/service/service_config_validators_test.go b/container-engine-lib/lib/backend_interface/objects/service/service_config_validators_test.go new file mode 100644 index 0000000000..c6ffb4d31c --- /dev/null +++ b/container-engine-lib/lib/backend_interface/objects/service/service_config_validators_test.go @@ -0,0 +1,67 @@ +package service + +import ( + "github.com/stretchr/testify/require" + "testing" +) + +var testValidUserCustomLabels = map[string]string{ + "a": "a", + "aa": "", // empty value is allowed + "aaa": "aaa", + "a99a9": "a99a9", + "99aa9": "99aa9", + "a.7.3.5": "a.7.3.5", + "environment": "RaNdoM", // allowed caps on values + "system_environment": "random_random", + "system.environment": "random.random", + "system-environment": "random-random", + "keys-with-63-chars-are-allowed-000000000000000000000000000000": "values-with-63-chars-are-allowed-000000000000000000000000000000", +} + +var testInvalidUserCustomLabels = []map[string]string{ + // NOT VALID KEYS + { + "": "random", // empty key not allowed + }, + { + " ": "random", // whitespace key not allowed + }, + { + "SystemEnvironment": "random", // caps on key not allowed for both Docker and K8s + }, + { + "system/environment": "random", // slash on key not allowed for both Docker and K8s + }, + { + "_system_environment": "random", // not valid for K8s because it starts with a non-alphanumerical char + }, + { + "system_environment-": "random", // not valid for K8s because it ends with a non-alphanumerical char + }, + { + "more-than-63-chars-is-not-allowed-in-keys-0000000000000000000000": "random", // key exceeds max value + }, + // NOT VALID VALUES + { + "system_environment": " ", // whitespace value not allowed + }, + { + "system_environment": "more-than-63-chars-is-not-allowed-in-values-00000000000000000000", // value exceeds max value + }, + { + "system_environment": "_random", // not valid for K8s because it starts with a non-alphanumerical char + }, + { + "system_environment": "random-", // not valid for K8s because it ends with a non-alphanumerical char + }, +} + +func TestServiceConfigValidators(t *testing.T) { + err := ValidateServiceConfigLabels(testValidUserCustomLabels) + require.NoError(t, err) + for _, notAllowedLabels := range testInvalidUserCustomLabels { + err := ValidateServiceConfigLabels(notAllowedLabels) + require.Error(t, err) + } +} diff --git a/container-engine-lib/lib/database_accessors/enclave_db/service_registration/repository_test.go b/container-engine-lib/lib/database_accessors/enclave_db/service_registration/repository_test.go index f899777ace..1fc8207fd7 100644 --- a/container-engine-lib/lib/database_accessors/enclave_db/service_registration/repository_test.go +++ b/container-engine-lib/lib/database_accessors/enclave_db/service_registration/repository_test.go @@ -302,7 +302,7 @@ func getServiceRegistrationWithDataForTest( } func getServiceConfigForTest(t *testing.T, imageName string) *service.ServiceConfig { - return service.NewServiceConfig( + serviceConfig, err := service.CreateServiceConfig( imageName, testPrivatePorts(t), testPublicPorts(t), @@ -316,7 +316,13 @@ func getServiceConfigForTest(t *testing.T, imageName string) *service.ServiceCon "IP-ADDRESS", 100, 512, + map[string]string{ + "test-label-key": "test-label-value", + "test-second-label-key": "test-second-label-value", + }, ) + require.NoError(t, err) + return serviceConfig } func testPersistentDirectory() *service_directory.PersistentDirectories { diff --git a/core/server/api_container/server/service_network/default_service_network_test.go b/core/server/api_container/server/service_network/default_service_network_test.go index 76740a6da2..7c7e1e4fe6 100644 --- a/core/server/api_container/server/service_network/default_service_network_test.go +++ b/core/server/api_container/server/service_network/default_service_network_test.go @@ -67,7 +67,7 @@ func TestAddService_Successful(t *testing.T) { successfulServiceIp := testIpFromInt(serviceInternalTestId) serviceRegistration := service.NewServiceRegistration(serviceName, serviceUuid, enclaveName, successfulServiceIp, string(serviceName)) serviceObj := service.NewService(serviceRegistration, map[string]*port_spec.PortSpec{}, successfulServiceIp, map[string]*port_spec.PortSpec{}, container.NewContainer(container.ContainerStatus_Running, testContainerImageName, nil, nil, nil)) - serviceConfig := testServiceConfig(testContainerImageName) + serviceConfig := testServiceConfig(t, testContainerImageName) file, err := os.CreateTemp("/tmp", "*.db") defer os.Remove(file.Name()) @@ -148,7 +148,7 @@ func TestAddService_FailedToStart(t *testing.T) { serviceUuid := testServiceUuidFromInt(serviceInternalTestId) serviceIp := testIpFromInt(serviceInternalTestId) serviceRegistration := service.NewServiceRegistration(serviceName, serviceUuid, enclaveName, serviceIp, string(serviceName)) - serviceConfig := testServiceConfig(testContainerImageName) + serviceConfig := testServiceConfig(t, testContainerImageName) file, err := os.CreateTemp("/tmp", "*.db") defer os.Remove(file.Name()) @@ -242,7 +242,7 @@ func TestAddServices_Success(t *testing.T) { successfulServiceIp := testIpFromInt(successfulServiceIndex) successfulServiceRegistration := service.NewServiceRegistration(successfulServiceName, successfulServiceUuid, enclaveName, successfulServiceIp, string(successfulServiceName)) successfulService := service.NewService(successfulServiceRegistration, map[string]*port_spec.PortSpec{}, successfulServiceIp, map[string]*port_spec.PortSpec{}, container.NewContainer(container.ContainerStatus_Running, testContainerImageName, nil, nil, nil)) - successfulServiceConfig := testServiceConfig(testContainerImageName) + successfulServiceConfig := testServiceConfig(t, testContainerImageName) file, err := os.CreateTemp("/tmp", "*.db") defer os.Remove(file.Name()) @@ -327,7 +327,7 @@ func TestAddServices_FailureRollsBackTheEntireBatch(t *testing.T) { successfulServiceIp := testIpFromInt(successfulServiceIndex) successfulServiceRegistration := service.NewServiceRegistration(successfulServiceName, successfulServiceUuid, enclaveName, successfulServiceIp, string(successfulServiceName)) successfulService := service.NewService(successfulServiceRegistration, map[string]*port_spec.PortSpec{}, successfulServiceIp, map[string]*port_spec.PortSpec{}, container.NewContainer(container.ContainerStatus_Running, testContainerImageName, nil, nil, nil)) - successfulServiceConfig := testServiceConfig(testContainerImageName) + successfulServiceConfig := testServiceConfig(t, testContainerImageName) // One service will fail to be started failedServiceIndex := 2 @@ -335,7 +335,7 @@ func TestAddServices_FailureRollsBackTheEntireBatch(t *testing.T) { failedServiceUuid := testServiceUuidFromInt(failedServiceIndex) failedServiceIp := testIpFromInt(failedServiceIndex) failedServiceRegistration := service.NewServiceRegistration(failedServiceName, failedServiceUuid, enclaveName, failedServiceIp, string(failedServiceName)) - failedServiceConfig := testServiceConfig(testContainerImageName) + failedServiceConfig := testServiceConfig(t, testContainerImageName) file, err := os.CreateTemp("/tmp", "*.db") defer os.Remove(file.Name()) @@ -486,7 +486,7 @@ func TestAddServices_FailedToRegisterService(t *testing.T) { // One service will fail to be started failedServiceIndex := 1 failedServiceName := testServiceNameFromInt(failedServiceIndex) - failedServiceConfig := testServiceConfig(testContainerImageName) + failedServiceConfig := testServiceConfig(t, testContainerImageName) file, err := os.CreateTemp("/tmp", "*.db") defer os.Remove(file.Name()) @@ -704,7 +704,7 @@ func TestStartService_Successful(t *testing.T) { successfulServiceIp := testIpFromInt(serviceInternalTestId) serviceRegistration := service.NewServiceRegistration(serviceName, serviceUuid, enclaveName, successfulServiceIp, string(serviceName)) serviceRegistration.SetStatus(service.ServiceStatus_Stopped) - serviceConfig := testServiceConfig(testContainerImageName) + serviceConfig := testServiceConfig(t, testContainerImageName) serviceRegistration.SetConfig(serviceConfig) serviceObj := service.NewService(serviceRegistration, map[string]*port_spec.PortSpec{}, successfulServiceIp, map[string]*port_spec.PortSpec{}, container.NewContainer(container.ContainerStatus_Running, testContainerImageName, nil, nil, nil)) @@ -759,7 +759,7 @@ func TestStartService_StartRegisteredUserServicesFailed(t *testing.T) { successfulServiceIp := testIpFromInt(serviceInternalTestId) serviceRegistration := service.NewServiceRegistration(serviceName, serviceUuid, enclaveName, successfulServiceIp, string(serviceName)) serviceRegistration.SetStatus(service.ServiceStatus_Stopped) - serviceConfig := testServiceConfig(testContainerImageName) + serviceConfig := testServiceConfig(t, testContainerImageName) serviceRegistration.SetConfig(serviceConfig) file, err := os.CreateTemp("/tmp", "*.db") @@ -812,7 +812,7 @@ func TestStartService_ServiceAlreadyStarted(t *testing.T) { successfulServiceIp := testIpFromInt(serviceInternalTestId) serviceRegistration := service.NewServiceRegistration(serviceName, serviceUuid, enclaveName, successfulServiceIp, string(serviceName)) serviceRegistration.SetStatus(service.ServiceStatus_Started) - serviceConfig := testServiceConfig(testContainerImageName) + serviceConfig := testServiceConfig(t, testContainerImageName) serviceRegistration.SetConfig(serviceConfig) file, err := os.CreateTemp("/tmp", "*.db") @@ -871,8 +871,8 @@ func TestUpdateService(t *testing.T) { ) require.Nil(t, err) - initialServiceConfig := testServiceConfig(testContainerImageName) - updatedServiceConfig := testServiceConfig("kurtosistech/new-service-image") + initialServiceConfig := testServiceConfig(t, testContainerImageName) + updatedServiceConfig := testServiceConfig(t, "kurtosistech/new-service-image") // service that will be successfully updated existingServiceIndex := 1 @@ -1190,8 +1190,8 @@ func openFreeTCPAndUDPLocalHostPortAddressesForTesting() (*netip.AddrPort, *neti return &tcpAddressPort, &udpAddressPort, closeBothListenersFunc, nil } -func testServiceConfig(imageName string) *service.ServiceConfig { - return service.NewServiceConfig( +func testServiceConfig(t *testing.T, imageName string) *service.ServiceConfig { + serviceConfig, err := service.CreateServiceConfig( imageName, nil, nil, @@ -1205,7 +1205,10 @@ func testServiceConfig(imageName string) *service.ServiceConfig { "", 0, 0, + map[string]string{}, ) + require.NoError(t, err) + return serviceConfig } func testIpFromInt(i int) net.IP { diff --git a/core/server/api_container/server/startosis_engine/kurtosis_instruction/add_service/add_service_shared.go b/core/server/api_container/server/startosis_engine/kurtosis_instruction/add_service/add_service_shared.go index b9497e9235..6178286635 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_instruction/add_service/add_service_shared.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_instruction/add_service/add_service_shared.go @@ -165,7 +165,7 @@ func replaceMagicStrings( } } - renderedServiceConfig := service.NewServiceConfig( + renderedServiceConfig, err := service.CreateServiceConfig( serviceConfig.GetContainerImageName(), serviceConfig.GetPrivatePorts(), serviceConfig.GetPublicPorts(), @@ -179,7 +179,12 @@ func replaceMagicStrings( serviceConfig.GetPrivateIPAddrPlaceholder(), serviceConfig.GetMinCPUAllocationMillicpus(), serviceConfig.GetMinMemoryAllocationMegabytes(), + serviceConfig.GetLabels(), ) + if err != nil { + return "", nil, stacktrace.Propagate(err, "An error occurred creating a service config") + } + return service.ServiceName(serviceNameStr), renderedServiceConfig, nil } diff --git a/core/server/api_container/server/startosis_engine/kurtosis_instruction/add_service/add_service_shared_test.go b/core/server/api_container/server/startosis_engine/kurtosis_instruction/add_service/add_service_shared_test.go index 0597850526..178f0b8169 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_instruction/add_service/add_service_shared_test.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_instruction/add_service/add_service_shared_test.go @@ -36,7 +36,7 @@ func TestAddServiceShared_EntryPointArgsRuntimeValueAreReplaced(t *testing.T) { runtimeValue := fmt.Sprintf(magic_string_helper.RuntimeValueReplacementPlaceholderFormat, stringValueUuid, runtimeValueName) serviceName := service.ServiceName("example-datastore-server-2") - serviceConfig := service.NewServiceConfig( + serviceConfig, err := service.CreateServiceConfig( testContainerImageName, nil, nil, @@ -50,7 +50,9 @@ func TestAddServiceShared_EntryPointArgsRuntimeValueAreReplaced(t *testing.T) { "", 0, 0, + map[string]string{}, ) + require.NoError(t, err) replacedServiceName, replacedServiceConfig, err := replaceMagicStrings(runtimeValueStore, serviceName, serviceConfig) require.Nil(t, err) @@ -75,7 +77,7 @@ func TestAddServiceShared_CmdArgsRuntimeValueAreReplaced(t *testing.T) { runtimeValue := fmt.Sprintf(magic_string_helper.RuntimeValueReplacementPlaceholderFormat, stringValueUuid, runtimeValueName) serviceName := service.ServiceName("example-datastore-server-2") - serviceConfig := service.NewServiceConfig( + serviceConfig, err := service.CreateServiceConfig( testContainerImageName, nil, nil, @@ -89,7 +91,9 @@ func TestAddServiceShared_CmdArgsRuntimeValueAreReplaced(t *testing.T) { "", 0, 0, + map[string]string{}, ) + require.NoError(t, err) replacedServiceName, replacedServiceConfig, err := replaceMagicStrings(runtimeValueStore, serviceName, serviceConfig) require.Nil(t, err) @@ -114,7 +118,7 @@ func TestAddServiceShared_EnvVarsWithRuntimeValueAreReplaced(t *testing.T) { runtimeValue := fmt.Sprintf(magic_string_helper.RuntimeValueReplacementPlaceholderFormat, stringValueUuid, runtimeValueName) serviceName := service.ServiceName("example-datastore-server-2") - serviceConfig := service.NewServiceConfig( + serviceConfig, err := service.CreateServiceConfig( testContainerImageName, nil, nil, @@ -130,7 +134,9 @@ func TestAddServiceShared_EnvVarsWithRuntimeValueAreReplaced(t *testing.T) { "", 0, 0, + map[string]string{}, ) + require.NoError(t, err) replacedServiceName, replacedServiceConfig, err := replaceMagicStrings(runtimeValueStore, serviceName, serviceConfig) require.Nil(t, err) @@ -158,7 +164,7 @@ func TestAddServiceShared_ServiceNameWithRuntimeValuesAreReplaced(t *testing.T) stringRuntimeValue := fmt.Sprintf(magic_string_helper.RuntimeValueReplacementPlaceholderFormat, stringValueUuid, valueName) serviceName := service.ServiceName(stringRuntimeValue) - serviceConfig := service.NewServiceConfig( + serviceConfig, err := service.CreateServiceConfig( testContainerImageName, nil, nil, @@ -172,7 +178,9 @@ func TestAddServiceShared_ServiceNameWithRuntimeValuesAreReplaced(t *testing.T) "", 0, 0, + map[string]string{}, ) + require.NoError(t, err) replacedServiceName, _, err := replaceMagicStrings(runtimeValueStore, serviceName, serviceConfig) require.Nil(t, err) diff --git a/core/server/api_container/server/startosis_engine/kurtosis_instruction/tasks/run_python.go b/core/server/api_container/server/startosis_engine/kurtosis_instruction/tasks/run_python.go index 87d601cc59..4c22a22859 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_instruction/tasks/run_python.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_instruction/tasks/run_python.go @@ -232,7 +232,10 @@ func (builtin *RunPythonCapabilities) Interpret(_ string, arguments *builtin_arg } // build a service config from image and files artifacts expansion. - builtin.serviceConfig = getServiceConfig(image, filesArtifactExpansion) + builtin.serviceConfig, err = getServiceConfig(image, filesArtifactExpansion) + if err != nil { + return nil, startosis_errors.WrapWithInterpretationError(err, "An error occurred creating service config using image '%s'", image) + } if arguments.IsSet(StoreFilesArgName) { storeSpecList, interpretationErr := parseStoreFilesArg(builtin.serviceNetwork, arguments) diff --git a/core/server/api_container/server/startosis_engine/kurtosis_instruction/tasks/run_sh.go b/core/server/api_container/server/startosis_engine/kurtosis_instruction/tasks/run_sh.go index 5cc4050dcc..4a98779b84 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_instruction/tasks/run_sh.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_instruction/tasks/run_sh.go @@ -145,7 +145,10 @@ func (builtin *RunShCapabilities) Interpret(_ string, arguments *builtin_argumen } // build a service config from image and files artifacts expansion. - builtin.serviceConfig = getServiceConfig(image, filesArtifactExpansion) + builtin.serviceConfig, err = getServiceConfig(image, filesArtifactExpansion) + if err != nil { + return nil, startosis_errors.WrapWithInterpretationError(err, "An error occurred creating service config using image '%s'", image) + } if arguments.IsSet(StoreFilesArgName) { storeSpecList, interpretationErr := parseStoreFilesArg(builtin.serviceNetwork, arguments) diff --git a/core/server/api_container/server/startosis_engine/kurtosis_instruction/tasks/tasks_shared.go b/core/server/api_container/server/startosis_engine/kurtosis_instruction/tasks/tasks_shared.go index 6b146e6a5d..3804ac1a4e 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_instruction/tasks/tasks_shared.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_instruction/tasks/tasks_shared.go @@ -246,8 +246,8 @@ func resultMapToString(resultMap map[string]starlark.Comparable, builtinNameForL return fmt.Sprintf("Command returned with exit code '%v' and the following output: %v", exitCode, outputStr) } -func getServiceConfig(image string, filesArtifactExpansion *service_directory.FilesArtifactsExpansion) *service.ServiceConfig { - return service.NewServiceConfig( +func getServiceConfig(image string, filesArtifactExpansion *service_directory.FilesArtifactsExpansion) (*service.ServiceConfig, error) { + serviceConfig, err := service.CreateServiceConfig( image, nil, nil, @@ -266,7 +266,12 @@ func getServiceConfig(image string, filesArtifactExpansion *service_directory.Fi service_config.DefaultPrivateIPAddrPlaceholder, 0, 0, + map[string]string{}, ) + if err != nil { + return nil, stacktrace.Propagate(err, "An error occurred creating service config") + } + return serviceConfig, nil } func formatErrorMessage(errorMessage string, errorFromExec string) string { diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/builtin_argument/validators.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/builtin_argument/validators.go index 2ec22580d4..96d8cb166e 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/builtin_argument/validators.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/builtin_argument/validators.go @@ -1,6 +1,7 @@ package builtin_argument import ( + "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/service" "github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/startosis_errors" "go.starlark.net/starlark" "reflect" @@ -110,3 +111,33 @@ func DurationOrNone(value starlark.Value, attributeName string) *startosis_error } return nil } + +func ServiceConfigLabels(value starlark.Value, attributeName string) *startosis_errors.InterpretationError { + labelsMap := map[string]string{} + labelsDict, ok := value.(*starlark.Dict) + if !ok { + return startosis_errors.NewInterpretationError("Attribute '%s' is expected to be a dictionary of strings, got '%s'", attributeName, reflect.TypeOf(value)) + } + for _, labelKey := range labelsDict.Keys() { + labelValue, found, err := labelsDict.Get(labelKey) + if err != nil { + return startosis_errors.WrapWithInterpretationError(err, "Unexpected error iterating on dictionary. Value associated to key '%v' could not be found", labelKey) + } else if !found { + return startosis_errors.NewInterpretationError("Unexpected error iterating on dictionary. Value associated to key '%v' could not be found", labelKey) + } + + labelKeyStr, ok := labelKey.(starlark.String) + if !ok { + return startosis_errors.NewInterpretationError("Key in '%s' dictionary was expected to be a string, got '%s'", attributeName, reflect.TypeOf(labelKey)) + } + labelValueStr, ok := labelValue.(starlark.String) + if !ok { + return startosis_errors.NewInterpretationError("Value associated to key '%s' in dictionary '%s' was expected to be a string, got '%s'", labelKeyStr, attributeName, reflect.TypeOf(value)) + } + labelsMap[labelKeyStr.GoString()] = labelValueStr.GoString() + } + if err := service.ValidateServiceConfigLabels(labelsMap); err != nil { + return startosis_errors.WrapWithInterpretationError(err, "An error occurred validating service config labels '%+v'", labelsMap) + } + return nil +} diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/add_service_framework_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/add_service_framework_test.go index aa5589091b..642a9fbd92 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/add_service_framework_test.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/add_service_framework_test.go @@ -30,7 +30,7 @@ func (suite *KurtosisPlanInstructionTestSuite) TestAddService() { mock.Anything, testServiceName, mock.MatchedBy(func(serviceConfig *service.ServiceConfig) bool { - expectedServiceConfig := service.NewServiceConfig( + expectedServiceConfig, err := service.CreateServiceConfig( testContainerImageName, map[string]*port_spec.PortSpec{}, map[string]*port_spec.PortSpec{}, @@ -44,7 +44,9 @@ func (suite *KurtosisPlanInstructionTestSuite) TestAddService() { service_config.DefaultPrivateIPAddrPlaceholder, 0, 0, + map[string]string{}, ) + require.NoError(suite.T(), err) actualServiceConfig := serviceConfig suite.Assert().Equal(expectedServiceConfig, actualServiceConfig) diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/add_services_framework_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/add_services_framework_test.go index 58fa695f1e..7fd09264a8 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/add_services_framework_test.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/add_services_framework_test.go @@ -46,7 +46,7 @@ func (suite *KurtosisPlanInstructionTestSuite) TestAddServices() { suite.Require().Contains(configs, testServiceName) suite.Require().Contains(configs, testServiceName2) - expectedServiceConfig1 := service.NewServiceConfig( + expectedServiceConfig1, err := service.CreateServiceConfig( testContainerImageName, map[string]*port_spec.PortSpec{}, map[string]*port_spec.PortSpec{}, @@ -60,11 +60,14 @@ func (suite *KurtosisPlanInstructionTestSuite) TestAddServices() { service_config.DefaultPrivateIPAddrPlaceholder, 0, 0, + map[string]string{}, ) + require.NoError(suite.T(), err) + actualServiceConfig1 := configs[testServiceName] suite.Assert().Equal(expectedServiceConfig1, actualServiceConfig1) - expectedServiceConfig2 := service.NewServiceConfig( + expectedServiceConfig2, err := service.CreateServiceConfig( testContainerImageName, map[string]*port_spec.PortSpec{}, map[string]*port_spec.PortSpec{}, @@ -78,7 +81,10 @@ func (suite *KurtosisPlanInstructionTestSuite) TestAddServices() { service_config.DefaultPrivateIPAddrPlaceholder, 0, 0, + map[string]string{}, ) + require.NoError(suite.T(), err) + actualServiceConfig2 := configs[testServiceName2] suite.Assert().Equal(expectedServiceConfig2, actualServiceConfig2) return true diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/service_config_full_framework_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/service_config_full_framework_test.go index 72577f11cc..561aa9de2f 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/service_config_full_framework_test.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/service_config_full_framework_test.go @@ -34,7 +34,7 @@ func (t *serviceConfigFullTestCase) GetStarlarkCode() string { fileArtifact1 := fmt.Sprintf("%s(%s=%q)", directory.DirectoryTypeName, directory.ArtifactNameAttr, testFilesArtifactName1) fileArtifact2 := fmt.Sprintf("%s(%s=%q)", directory.DirectoryTypeName, directory.ArtifactNameAttr, testFilesArtifactName2) persistentDirectory := fmt.Sprintf("%s(%s=%q)", directory.DirectoryTypeName, directory.PersistentKeyAttr, testPersistentDirectoryKey) - starlarkCode := fmt.Sprintf("%s(%s=%q, %s=%s, %s=%s, %s=%s, %s=%s, %s=%s, %s=%s, %s=%q, %s=%d, %s=%d, %s=%d, %s=%d, %s=%s)", + starlarkCode := fmt.Sprintf("%s(%s=%q, %s=%s, %s=%s, %s=%s, %s=%s, %s=%s, %s=%s, %s=%q, %s=%d, %s=%d, %s=%d, %s=%d, %s=%s, %s=%v)", service_config.ServiceConfigTypeName, service_config.ImageAttr, testContainerImageName, service_config.PortsAttr, fmt.Sprintf("{%q: PortSpec(number=%d, transport_protocol=%q, application_protocol=%q, wait=%q)}", testPrivatePortId, testPrivatePortNumber, testPrivatePortProtocolStr, testPrivateApplicationProtocol, testWaitConfiguration), @@ -50,6 +50,7 @@ func (t *serviceConfigFullTestCase) GetStarlarkCode() string { service_config.MinMemoryMegaBytesAttr, testMinMemoryMegabytes, service_config.ReadyConditionsAttr, getDefaultReadyConditionsScriptPart(), + service_config.LabelsAttr, fmt.Sprintf("{%q: %q, %q: %q}", testServiceConfigLabelsKey1, testServiceConfigLabelsValue1, testServiceConfigLabelsKey2, testServiceConfigLabelsValue2), ) return starlarkCode } @@ -107,4 +108,6 @@ func (t *serviceConfigFullTestCase) Assert(typeValue builtin_argument.KurtosisVa require.Equal(t, testCpuAllocation, serviceConfig.GetCPUAllocationMillicpus()) require.Equal(t, testMinMemoryMegabytes, serviceConfig.GetMinMemoryAllocationMegabytes()) require.Equal(t, testMinCpuMilliCores, serviceConfig.GetMinCPUAllocationMillicpus()) + + require.Equal(t, testServiceConfigLabels, serviceConfig.GetLabels()) } diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/service_config_minimal_framework_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/service_config_minimal_framework_test.go index 538fe735ee..a246369f44 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/service_config_minimal_framework_test.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/service_config_minimal_framework_test.go @@ -33,10 +33,10 @@ func (t *serviceConfigMinimalTestCase) Assert(typeValue builtin_argument.Kurtosi serviceConfigStarlark, ok := typeValue.(*service_config.ServiceConfig) require.True(t, ok) - serviceConfig, err := serviceConfigStarlark.ToKurtosisType(t.serviceNetwork) - require.Nil(t, err) + serviceConfig, interpretationErr := serviceConfigStarlark.ToKurtosisType(t.serviceNetwork) + require.Nil(t, interpretationErr) - expectedServiceConfig := service.NewServiceConfig( + expectedServiceConfig, err := service.CreateServiceConfig( testContainerImageName, map[string]*port_spec.PortSpec{}, map[string]*port_spec.PortSpec{}, @@ -50,6 +50,8 @@ func (t *serviceConfigMinimalTestCase) Assert(typeValue builtin_argument.Kurtosi service_config.DefaultPrivateIPAddrPlaceholder, 0, 0, + map[string]string{}, ) + require.NoError(t, err) require.Equal(t, expectedServiceConfig, serviceConfig) } diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/static_constants.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/static_constants.go index 7d407abcf6..bca3eb8c22 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/static_constants.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/static_constants.go @@ -94,4 +94,14 @@ var ( testGetRequestMethod = "GET" testNoPackageReplaceOptions = map[string]string{} + + testServiceConfigLabelsKey1 = "app-version" + testServiceConfigLabelsValue1 = "2.4" + testServiceConfigLabelsKey2 = "environment" + testServiceConfigLabelsValue2 = "production" + + testServiceConfigLabels = map[string]string{ + testServiceConfigLabelsKey1: testServiceConfigLabelsValue1, + testServiceConfigLabelsKey2: testServiceConfigLabelsValue2, + } ) diff --git a/core/server/api_container/server/startosis_engine/kurtosis_types/service_config/service_config.go b/core/server/api_container/server/startosis_engine/kurtosis_types/service_config/service_config.go index 49b1cb3167..2729612a78 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_types/service_config/service_config.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_types/service_config/service_config.go @@ -38,6 +38,7 @@ const ( MinMemoryMegaBytesAttr = "min_memory" MaxCpuMilliCoresAttr = "max_cpu" MaxMemoryMegaBytesAttr = "max_memory" + LabelsAttr = "labels" DefaultPrivateIPAddrPlaceholder = "KURTOSIS_IP_ADDR_PLACEHOLDER" @@ -170,6 +171,14 @@ func NewServiceConfigType() *kurtosis_type_constructor.KurtosisTypeConstructor { ZeroValueProvider: builtin_argument.ZeroValueProvider[*ReadyCondition], Validator: nil, }, + { + Name: LabelsAttr, + IsOptional: true, + ZeroValueProvider: builtin_argument.ZeroValueProvider[*starlark.Dict], + Validator: func(value starlark.Value) *startosis_errors.InterpretationError { + return builtin_argument.ServiceConfigLabels(value, LabelsAttr) + }, + }, }, }, @@ -442,7 +451,19 @@ func (config *ServiceConfig) ToKurtosisType(serviceNetwork service_network.Servi minMemory = 0 } - return service.NewServiceConfig( + labels := map[string]string{} + labelsStarlark, found, interpretationErr := kurtosis_type_constructor.ExtractAttrValue[*starlark.Dict](config.KurtosisValueTypeDefault, LabelsAttr) + if interpretationErr != nil { + return nil, interpretationErr + } + if found && labelsStarlark.Len() > 0 { + labels, interpretationErr = kurtosis_types.SafeCastToMapStringString(labelsStarlark, LabelsAttr) + if interpretationErr != nil { + return nil, interpretationErr + } + } + + serviceConfig, err := service.CreateServiceConfig( imageName, privatePorts, publicPorts, @@ -456,7 +477,12 @@ func (config *ServiceConfig) ToKurtosisType(serviceNetwork service_network.Servi privateIpAddressPlaceholder, minCpu, minMemory, - ), nil + labels, + ) + if err != nil { + return nil, startosis_errors.WrapWithInterpretationError(err, "An error occurred creating a service config") + } + return serviceConfig, nil } func (config *ServiceConfig) GetReadyCondition() (*ReadyCondition, *startosis_errors.InterpretationError) { diff --git a/docs/docs/starlark-reference/service-config.md b/docs/docs/starlark-reference/service-config.md index da1694786e..e7c2012ec9 100644 --- a/docs/docs/starlark-reference/service-config.md +++ b/docs/docs/starlark-reference/service-config.md @@ -94,7 +94,22 @@ config = ServiceConfig( # This field can be used to check the service's readiness after the service has started, # to confirm that it is ready to receive connections and traffic # OPTIONAL (Default: no ready conditions) - ready_conditions = ReadyCondition(...) + ready_conditions = ReadyCondition(...), + + # This field is used to specify custom labels at the container level in Docker and Pod level in Kubernetes. + # For Docker, the label syntax and format will follow: "com.kurtosistech.custom.key": "value" + # For Kubernetes, the label syntax & format will follow: kurtosistech.com.custom/key=value + + # Labels must follow the label standards outlined in [RFC-1035](https://datatracker.ietf.org/doc/html/rfc1035), + # meaning that both the label key and label value must contain at most 63 characters, contain only lowercase + # alphanumeric characters, dashes (-), underscores (_) or dots (.), start with an alphabetic character, and end with an alphanumeric character. + # Empty value and capital letters are valid on label values. + # OPTIONAL + labels = { + "key": "value", + # Examples + "name": "alice", + } ) ``` The `ports` dictionary argument accepts a key value pair, where `key` is a user defined unique port identifier and `value` is a [PortSpec][port-spec] object. @@ -109,6 +124,37 @@ If you are trying to use a more complex versions of `cmd` and are running into i set the `entrypoint` to `["/bin/sh", "-c"]` and then set the `cmd` to the command as you would type it in your shell. For example, `cmd = ["echo foo | grep foo"]` ::: +:::tip Example of a rendered label +If you have defined the pod label key:value pair in `ServiceConfig` to be: + +```py +config = ServiceConfig( + ... + labels = { + "name": "alice", + "age": "20", + "height": "175" + } +) +``` + +then the labels for the pods on Kubernetes will look like: +``` +labels: + kurtosistech.com.custom/name=alice + kurtosistech.com.custom/age=20 + kurotsistech.com.custom/height=175 +``` + +while on Docker, the container labels will look like: +``` +labels: + "com.kurtosistech.custom.name": "alice" + "com.kurtosistech.custom.age": "20" + "com.kurtosistech.custom.height": "175" +``` +::: + [add-service-reference]: ./plan.md#add_service [directory]: ./directory.md