-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Connect and disconnect the reverse proxy to/from the enclave network.
- Loading branch information
1 parent
1537d3b
commit e9982ed
Showing
7 changed files
with
352 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
...end_impls/docker/docker_kurtosis_backend/reverse_proxy_functions/network_reverse_proxy.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package reverse_proxy_functions | ||
|
||
import ( | ||
"context" | ||
"net" | ||
|
||
"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_operation_parallelizer" | ||
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/enclave" | ||
"github.com/kurtosis-tech/stacktrace" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
const ( | ||
emptyAliasForLogsCollector = "" | ||
) | ||
|
||
var ( | ||
autoAssignIpAddressToLogsCollector net.IP = nil | ||
) | ||
|
||
func ConnectReverseProxyToNetwork(ctx context.Context, dockerManager *docker_manager.DockerManager, networkId string) error { | ||
_, maybeReverseProxyContainerId, err := getReverseProxyObjectAndContainerId(ctx, dockerManager) | ||
if err != nil { | ||
logrus.Warnf("Attempted to connect reverse proxy to a network but no reverse proxy container was found.") | ||
return nil | ||
} | ||
|
||
if maybeReverseProxyContainerId == "" { | ||
return nil | ||
} | ||
|
||
if err = dockerManager.ConnectContainerToNetwork(ctx, networkId, maybeReverseProxyContainerId, autoAssignIpAddressToLogsCollector, emptyAliasForLogsCollector); err != nil { | ||
return stacktrace.Propagate(err, "An error occurred while connecting container '%v' to the enclave network '%v'", maybeReverseProxyContainerId, networkId) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func DisconnectReverseProxyFromNetwork(ctx context.Context, dockerManager *docker_manager.DockerManager, networkId string) error { | ||
_, maybeReverseProxyContainerId, err := getReverseProxyObjectAndContainerId(ctx, dockerManager) | ||
if err != nil { | ||
logrus.Warnf("Attempted to disconnect reverse proxy from a network but no reverse proxy container was found.") | ||
return nil | ||
} | ||
|
||
if maybeReverseProxyContainerId == "" { | ||
return nil | ||
} | ||
|
||
if err = dockerManager.DisconnectContainerFromNetwork(ctx, maybeReverseProxyContainerId, networkId); err != nil { | ||
return stacktrace.Propagate(err, "An error occurred while disconnecting container '%v' from the enclave network '%v'", maybeReverseProxyContainerId, networkId) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func DisconnectReverseProxyFromEnclaveNetworks( | ||
ctx context.Context, | ||
dockerManager *docker_manager.DockerManager, | ||
enclaveNetworkIds map[enclave.EnclaveUUID]string, | ||
) ( | ||
map[enclave.EnclaveUUID]bool, | ||
map[enclave.EnclaveUUID]error, | ||
error, | ||
) { | ||
networkIdsToRemove := map[string]bool{} | ||
enclaveUuidsForNetworkIds := map[string]enclave.EnclaveUUID{} | ||
for enclaveUuid, networkId := range enclaveNetworkIds { | ||
networkIdsToRemove[networkId] = true | ||
enclaveUuidsForNetworkIds[networkId] = enclaveUuid | ||
} | ||
|
||
var disconnectNetworkOperation docker_operation_parallelizer.DockerOperation = func(ctx context.Context, dockerManager *docker_manager.DockerManager, dockerObjectId string) error { | ||
if err := DisconnectReverseProxyFromNetwork(ctx, dockerManager, dockerObjectId); err != nil { | ||
return stacktrace.Propagate(err, "An error occurred disconnecting the reverse proxy from the enclave network with ID '%v'", dockerObjectId) | ||
} | ||
return nil | ||
} | ||
|
||
successfulNetworkIds, erroredNetworkIds := docker_operation_parallelizer.RunDockerOperationInParallel( | ||
ctx, | ||
networkIdsToRemove, | ||
dockerManager, | ||
disconnectNetworkOperation, | ||
) | ||
|
||
successfulEnclaveUuids := map[enclave.EnclaveUUID]bool{} | ||
for networkId := range successfulNetworkIds { | ||
enclaveUuid, found := enclaveUuidsForNetworkIds[networkId] | ||
if !found { | ||
return nil, nil, stacktrace.NewError("The reverse proxy was successfully disconnected from the Docker network '%v', but wasn't requested to be disconnected", networkId) | ||
} | ||
successfulEnclaveUuids[enclaveUuid] = true | ||
} | ||
|
||
erroredEnclaveUuids := map[enclave.EnclaveUUID]error{} | ||
for networkId, networkRemovalErr := range erroredNetworkIds { | ||
enclaveUuid, found := enclaveUuidsForNetworkIds[networkId] | ||
if !found { | ||
return nil, nil, stacktrace.NewError("Docker network '%v' had the following error during disconnect, but wasn't requested to be disconnected:\n%v", networkId, networkRemovalErr) | ||
} | ||
erroredEnclaveUuids[enclaveUuid] = networkRemovalErr | ||
} | ||
return successfulEnclaveUuids, erroredEnclaveUuids, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.