From 6f0ec6b6349624769bc08ce06db7aee6b40765fa Mon Sep 17 00:00:00 2001 From: Laurent Luce Date: Thu, 28 Dec 2023 18:41:37 -0400 Subject: [PATCH] Append engine guid to the reverse proxy container name for uniqueness. --- .../docker_kurtosis_backend.go | 3 +- .../engine_functions/create_engine.go | 1 + .../create_reverse_proxy.go | 4 +++ .../traefik_reverse_proxy_container.go | 5 ++- .../reverse_proxy_container.go | 3 ++ .../object_attributes_provider.go | 32 +++++++++++++++---- .../kubernetes_kurtosis_backend.go | 2 +- .../metrics_reporting_kurtosis_backend.go | 4 +-- .../lib/backend_interface/kurtosis_backend.go | 2 +- .../mock_kurtosis_backend.go | 31 +++++++++--------- 10 files changed, 60 insertions(+), 27 deletions(-) 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 d9b47c32d4..d57c539b47 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 @@ -475,11 +475,12 @@ func (backend *DockerKurtosisBackend) DestroyLogsCollectorForEnclave(ctx context return nil } -func (backend *DockerKurtosisBackend) CreateReverseProxy(ctx context.Context) (*reverse_proxy.ReverseProxy, error) { +func (backend *DockerKurtosisBackend) CreateReverseProxy(ctx context.Context, engineGuid engine.EngineGUID) (*reverse_proxy.ReverseProxy, error) { reverseProxyContainer := traefik.NewTraefikReverseProxyContainer() reverseProxy, _, err := reverse_proxy_functions.CreateReverseProxy( ctx, + engineGuid, reverseProxyContainer, backend.dockerManager, backend.objAttrsProvider, diff --git a/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/engine_functions/create_engine.go b/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/engine_functions/create_engine.go index 6a1d021e1e..b21ddc68a2 100644 --- a/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/engine_functions/create_engine.go +++ b/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/engine_functions/create_engine.go @@ -116,6 +116,7 @@ func CreateEngine( reverseProxyContainer := traefik.NewTraefikReverseProxyContainer() _, removeReverseProxyFunc, err := reverse_proxy_functions.CreateReverseProxy( ctx, + engineGuid, reverseProxyContainer, dockerManager, objAttrsProvider) diff --git a/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/reverse_proxy_functions/create_reverse_proxy.go b/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/reverse_proxy_functions/create_reverse_proxy.go index 2c29325b7b..7161410c46 100644 --- a/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/reverse_proxy_functions/create_reverse_proxy.go +++ b/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/reverse_proxy_functions/create_reverse_proxy.go @@ -2,10 +2,12 @@ package reverse_proxy_functions import ( "context" + "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/docker_manager/types" "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_interface/objects/engine" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/reverse_proxy" "github.com/kurtosis-tech/stacktrace" "github.com/sirupsen/logrus" @@ -18,6 +20,7 @@ const ( // Create reverse proxy idempotently, if existing reverse proxy is found, then it is returned func CreateReverseProxy( ctx context.Context, + engineGuid engine.EngineGUID, reverseProxyContainer ReverseProxyContainer, dockerManager *docker_manager.DockerManager, objAttrsProvider object_attributes_provider.DockerObjectAttributesProvider, @@ -59,6 +62,7 @@ func CreateReverseProxy( containerId, containerLabels, removeReverseProxyContainerFunc, err := reverseProxyContainer.CreateAndStart( ctx, + engineGuid, defaultReverseProxyHttpPortNum, defaultReverseProxyDashboardPortNum, targetNetworkId, diff --git a/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/reverse_proxy_functions/implementations/traefik/traefik_reverse_proxy_container.go b/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/reverse_proxy_functions/implementations/traefik/traefik_reverse_proxy_container.go index ebe3f1ac48..5a509975f9 100644 --- a/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/reverse_proxy_functions/implementations/traefik/traefik_reverse_proxy_container.go +++ b/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/reverse_proxy_functions/implementations/traefik/traefik_reverse_proxy_container.go @@ -5,11 +5,13 @@ 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/object_attributes_provider" + "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/engine" "github.com/kurtosis-tech/stacktrace" "github.com/sirupsen/logrus" ) type traefikReverseProxyContainer struct{} +// TODO: Add uuid in here. func NewTraefikReverseProxyContainer() *traefikReverseProxyContainer { return &traefikReverseProxyContainer{} @@ -17,6 +19,7 @@ func NewTraefikReverseProxyContainer() *traefikReverseProxyContainer { func (traefikContainer *traefikReverseProxyContainer) CreateAndStart( ctx context.Context, + engineGuid engine.EngineGUID, httpPort uint16, dashboardPort uint16, targetNetworkId string, @@ -25,7 +28,7 @@ func (traefikContainer *traefikReverseProxyContainer) CreateAndStart( ) (string, map[string]string, func(), error) { traefikContainerConfigProviderObj := createTraefikContainerConfigProvider(httpPort, dashboardPort, targetNetworkId) - reverseProxyAttrs, err := objAttrsProvider.ForReverseProxy() + reverseProxyAttrs, err := objAttrsProvider.ForReverseProxy(engineGuid) if err != nil { return "", nil, nil, stacktrace.Propagate(err, "An error occurred getting the reverse proxy container attributes.") } diff --git a/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/reverse_proxy_functions/reverse_proxy_container.go b/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/reverse_proxy_functions/reverse_proxy_container.go index 5de87e2534..98e7c0d0ac 100644 --- a/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/reverse_proxy_functions/reverse_proxy_container.go +++ b/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/reverse_proxy_functions/reverse_proxy_container.go @@ -2,13 +2,16 @@ package reverse_proxy_functions import ( "context" + "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" + "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/engine" ) type ReverseProxyContainer interface { CreateAndStart( ctx context.Context, + engineGuid engine.EngineGUID, httpPort uint16, dashboardPort uint16, targetNetworkId string, 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 52fcbc54d6..29452431a5 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 @@ -1,6 +1,8 @@ package object_attributes_provider import ( + "strings" + "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" @@ -10,14 +12,13 @@ import ( "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" "github.com/kurtosis-tech/stacktrace" - "strings" ) const ( engineServerNamePrefix = "kurtosis-engine" logsAggregatorName = "kurtosis-logs-aggregator" logsStorageVolumeName = "kurtosis-logs-storage" - reverseProxyName = "kurtosis-reverse-proxy" + reverseProxyNamePrefix = "kurtosis-reverse-proxy" ) type DockerObjectAttributesProvider interface { @@ -29,7 +30,7 @@ type DockerObjectAttributesProvider interface { ForEnclave(enclaveUuid enclave.EnclaveUUID) (DockerEnclaveObjectAttributesProvider, error) ForLogsAggregator() (DockerObjectAttributes, error) ForLogsStorageVolume() (DockerObjectAttributes, error) - ForReverseProxy() (DockerObjectAttributes, error) + ForReverseProxy(engineGuid engine.EngineGUID) (DockerObjectAttributes, error) } func GetDockerObjectAttributesProvider() DockerObjectAttributesProvider { @@ -137,14 +138,33 @@ func (provider *dockerObjectAttributesProviderImpl) ForLogsStorageVolume() (Dock return objectAttributes, nil } -func (provider *dockerObjectAttributesProviderImpl) ForReverseProxy() (DockerObjectAttributes, error) { - name, err := docker_object_name.CreateNewDockerObjectName(reverseProxyName) +func (provider *dockerObjectAttributesProviderImpl) ForReverseProxy(engineGuid engine.EngineGUID) (DockerObjectAttributes, error) { + + nameStr := strings.Join( + []string{ + reverseProxyNamePrefix, + string(engineGuid), + }, + objectNameElementSeparator, + ) + name, err := docker_object_name.CreateNewDockerObjectName(nameStr) + if err != nil { + return nil, stacktrace.Propagate(err, "An error occurred creating a Docker object name object from string '%v'", nameStr) + } + + idLabelValue, err := docker_label_value.CreateNewDockerLabelValue(string(engineGuid)) if err != nil { - return nil, stacktrace.Propagate(err, "An error occurred creating a Docker object name object from string '%v'", reverseProxyName) + return nil, stacktrace.Propagate(err, "An error occurred creating the reverse proxy GUID Docker label from string '%v'", engineGuid) + } + guidLabelValue, err := docker_label_value.CreateNewDockerLabelValue(string(engineGuid)) + if err != nil { + return nil, stacktrace.Propagate(err, "An error occurred creating the reverse proxy GUID Docker label from string '%v'", engineGuid) } labels := map[*docker_label_key.DockerLabelKey]*docker_label_value.DockerLabelValue{ docker_label_key.ContainerTypeDockerLabelKey: label_value_consts.ReverseProxyTypeDockerLabelValue, + docker_label_key.IDDockerLabelKey: idLabelValue, + docker_label_key.GUIDDockerLabelKey: guidLabelValue, } objectAttributes, err := newDockerObjectAttributesImpl(name, labels) 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 74993c20b6..68f0c109cc 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 @@ -467,7 +467,7 @@ func (backend *KubernetesKurtosisBackend) GetReverseProxy( return nil, stacktrace.NewError("Getting the reverse proxy isn't yet implemented on Kubernetes") } -func (backend *KubernetesKurtosisBackend) CreateReverseProxy(ctx context.Context) (*reverse_proxy.ReverseProxy, error) { +func (backend *KubernetesKurtosisBackend) CreateReverseProxy(ctx context.Context, engineGuid engine.EngineGUID) (*reverse_proxy.ReverseProxy, error) { // TODO IMPLEMENT return nil, stacktrace.NewError("Creating the reverse proxy isn't yet implemented on Kubernetes") } diff --git a/container-engine-lib/lib/backend_impls/metrics_reporting/metrics_reporting_kurtosis_backend.go b/container-engine-lib/lib/backend_impls/metrics_reporting/metrics_reporting_kurtosis_backend.go index 6b26c297ba..b9d4a07360 100644 --- a/container-engine-lib/lib/backend_impls/metrics_reporting/metrics_reporting_kurtosis_backend.go +++ b/container-engine-lib/lib/backend_impls/metrics_reporting/metrics_reporting_kurtosis_backend.go @@ -440,8 +440,8 @@ func (backend *MetricsReportingKurtosisBackend) DestroyLogsCollectorForEnclave(c return nil } -func (backend *MetricsReportingKurtosisBackend) CreateReverseProxy(ctx context.Context) (*reverse_proxy.ReverseProxy, error) { - return backend.underlying.CreateReverseProxy(ctx) +func (backend *MetricsReportingKurtosisBackend) CreateReverseProxy(ctx context.Context, engineGuid engine.EngineGUID) (*reverse_proxy.ReverseProxy, error) { + return backend.underlying.CreateReverseProxy(ctx, engineGuid) } func (backend *MetricsReportingKurtosisBackend) GetReverseProxy(ctx context.Context) (*reverse_proxy.ReverseProxy, error) { diff --git a/container-engine-lib/lib/backend_interface/kurtosis_backend.go b/container-engine-lib/lib/backend_interface/kurtosis_backend.go index 4ae2586ebe..bc85bb5ebe 100644 --- a/container-engine-lib/lib/backend_interface/kurtosis_backend.go +++ b/container-engine-lib/lib/backend_interface/kurtosis_backend.go @@ -339,7 +339,7 @@ type KurtosisBackend interface { // Destroy the logs collector for enclave with UUID DestroyLogsCollectorForEnclave(ctx context.Context, enclaveUuid enclave.EnclaveUUID) error - CreateReverseProxy(ctx context.Context) (*reverse_proxy.ReverseProxy, error) + CreateReverseProxy(ctx context.Context, engineGuid engine.EngineGUID) (*reverse_proxy.ReverseProxy, error) // Returns nil if logs aggregator was not found GetReverseProxy(ctx context.Context) (*reverse_proxy.ReverseProxy, error) diff --git a/container-engine-lib/lib/backend_interface/mock_kurtosis_backend.go b/container-engine-lib/lib/backend_interface/mock_kurtosis_backend.go index cbf9f7ec59..056048d9f9 100644 --- a/container-engine-lib/lib/backend_interface/mock_kurtosis_backend.go +++ b/container-engine-lib/lib/backend_interface/mock_kurtosis_backend.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.23.1. DO NOT EDIT. +// Code generated by mockery v2.26.1. DO NOT EDIT. package backend_interface @@ -431,25 +431,25 @@ func (_c *MockKurtosisBackend_CreateLogsCollectorForEnclave_Call) RunAndReturn(r return _c } -// CreateReverseProxy provides a mock function with given fields: ctx -func (_m *MockKurtosisBackend) CreateReverseProxy(ctx context.Context) (*reverse_proxy.ReverseProxy, error) { - ret := _m.Called(ctx) +// CreateReverseProxy provides a mock function with given fields: ctx, engineGuid +func (_m *MockKurtosisBackend) CreateReverseProxy(ctx context.Context, engineGuid engine.EngineGUID) (*reverse_proxy.ReverseProxy, error) { + ret := _m.Called(ctx, engineGuid) var r0 *reverse_proxy.ReverseProxy var r1 error - if rf, ok := ret.Get(0).(func(context.Context) (*reverse_proxy.ReverseProxy, error)); ok { - return rf(ctx) + if rf, ok := ret.Get(0).(func(context.Context, engine.EngineGUID) (*reverse_proxy.ReverseProxy, error)); ok { + return rf(ctx, engineGuid) } - if rf, ok := ret.Get(0).(func(context.Context) *reverse_proxy.ReverseProxy); ok { - r0 = rf(ctx) + if rf, ok := ret.Get(0).(func(context.Context, engine.EngineGUID) *reverse_proxy.ReverseProxy); ok { + r0 = rf(ctx, engineGuid) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*reverse_proxy.ReverseProxy) } } - if rf, ok := ret.Get(1).(func(context.Context) error); ok { - r1 = rf(ctx) + if rf, ok := ret.Get(1).(func(context.Context, engine.EngineGUID) error); ok { + r1 = rf(ctx, engineGuid) } else { r1 = ret.Error(1) } @@ -464,13 +464,14 @@ type MockKurtosisBackend_CreateReverseProxy_Call struct { // CreateReverseProxy is a helper method to define mock.On call // - ctx context.Context -func (_e *MockKurtosisBackend_Expecter) CreateReverseProxy(ctx interface{}) *MockKurtosisBackend_CreateReverseProxy_Call { - return &MockKurtosisBackend_CreateReverseProxy_Call{Call: _e.mock.On("CreateReverseProxy", ctx)} +// - engineGuid engine.EngineGUID +func (_e *MockKurtosisBackend_Expecter) CreateReverseProxy(ctx interface{}, engineGuid interface{}) *MockKurtosisBackend_CreateReverseProxy_Call { + return &MockKurtosisBackend_CreateReverseProxy_Call{Call: _e.mock.On("CreateReverseProxy", ctx, engineGuid)} } -func (_c *MockKurtosisBackend_CreateReverseProxy_Call) Run(run func(ctx context.Context)) *MockKurtosisBackend_CreateReverseProxy_Call { +func (_c *MockKurtosisBackend_CreateReverseProxy_Call) Run(run func(ctx context.Context, engineGuid engine.EngineGUID)) *MockKurtosisBackend_CreateReverseProxy_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context)) + run(args[0].(context.Context), args[1].(engine.EngineGUID)) }) return _c } @@ -480,7 +481,7 @@ func (_c *MockKurtosisBackend_CreateReverseProxy_Call) Return(_a0 *reverse_proxy return _c } -func (_c *MockKurtosisBackend_CreateReverseProxy_Call) RunAndReturn(run func(context.Context) (*reverse_proxy.ReverseProxy, error)) *MockKurtosisBackend_CreateReverseProxy_Call { +func (_c *MockKurtosisBackend_CreateReverseProxy_Call) RunAndReturn(run func(context.Context, engine.EngineGUID) (*reverse_proxy.ReverseProxy, error)) *MockKurtosisBackend_CreateReverseProxy_Call { _c.Call.Return(run) return _c }