Skip to content

Commit

Permalink
Append engine guid to the reverse proxy container name for uniqueness.
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentluce committed Dec 28, 2023
1 parent eb65da8 commit 6f0ec6b
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ func CreateEngine(
reverseProxyContainer := traefik.NewTraefikReverseProxyContainer()
_, removeReverseProxyFunc, err := reverse_proxy_functions.CreateReverseProxy(
ctx,
engineGuid,
reverseProxyContainer,
dockerManager,
objAttrsProvider)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
Expand Down Expand Up @@ -59,6 +62,7 @@ func CreateReverseProxy(

containerId, containerLabels, removeReverseProxyContainerFunc, err := reverseProxyContainer.CreateAndStart(
ctx,
engineGuid,
defaultReverseProxyHttpPortNum,
defaultReverseProxyDashboardPortNum,
targetNetworkId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@ 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{}
}

func (traefikContainer *traefikReverseProxyContainer) CreateAndStart(
ctx context.Context,
engineGuid engine.EngineGUID,
httpPort uint16,
dashboardPort uint16,
targetNetworkId string,
Expand All @@ -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.")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
31 changes: 16 additions & 15 deletions container-engine-lib/lib/backend_interface/mock_kurtosis_backend.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6f0ec6b

Please sign in to comment.