Skip to content

Commit

Permalink
switch between internal and host connection for APIC
Browse files Browse the repository at this point in the history
  • Loading branch information
lostbean committed Nov 19, 2023
1 parent 7298781 commit 1130aec
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion engine/server/engine/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ func restApiServer(

// Use our validation middleware to check all requests against the
// e.Use(middleware.OapiRequestValidator(swagger_enclave))
enclaveRuntime, err := restApi.NewEnclaveRuntime(ctx, enclave_manager)
enclaveRuntime, err := restApi.NewEnclaveRuntime(ctx, enclave_manager, false)
if err != nil {
// TODO(edgar) fix error handling
}
Expand Down
16 changes: 9 additions & 7 deletions engine/server/engine/server/enclave_rest_api_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ type enclaveRuntime struct {
remoteApiContainerClient map[string]kurtosis_core_rpc_api_bindings.ApiContainerServiceClient
}

func NewEnclaveRuntime(ctx context.Context, manager *enclave_manager.EnclaveManager) (*enclaveRuntime, error) {
func NewEnclaveRuntime(ctx context.Context, manager *enclave_manager.EnclaveManager, connectOnHostMachine bool) (*enclaveRuntime, error) {
enclaves, err := manager.GetEnclaves(ctx)
if err != nil {
return nil, err
}

clients := map[string]kurtosis_core_rpc_api_bindings.ApiContainerServiceClient{}
for uuid, info := range enclaves {
conn, err := getGrpcClientConn(info)
conn, err := getGrpcClientConn(info, connectOnHostMachine)
if err != nil {
logrus.Errorf("Failed to establish gRPC connection with enclave manager service on enclave %s", uuid)
return nil, err
Expand Down Expand Up @@ -572,11 +572,13 @@ func (manager *enclaveRuntime) PostEnclavesEnclaveIdentifierStarlarkScripts(ctx

// GetGrpcClientConn returns a client conn dialed in to the local port
// It is the caller's responsibility to call resultClientConn.close()
func getGrpcClientConn(enclaveInfo *types.EnclaveInfo) (resultClientConn *grpc.ClientConn, resultErr error) {
// apiContainerGrpcPort := enclaveInfo.ApiContainerInfo.GrpcPortInsideEnclave
// apiContainerIP := enclaveInfo.ApiContainerInfo.ContainerId
apiContainerGrpcPort := enclaveInfo.ApiContainerHostMachineInfo.GrpcPortOnHostMachine
apiContainerIP := enclaveInfo.ApiContainerHostMachineInfo.IpOnHostMachine
func getGrpcClientConn(enclaveInfo *types.EnclaveInfo, connectOnHostMachine bool) (resultClientConn *grpc.ClientConn, resultErr error) {
apiContainerGrpcPort := enclaveInfo.ApiContainerInfo.GrpcPortInsideEnclave
apiContainerIP := enclaveInfo.ApiContainerInfo.BridgeIpAddress
if connectOnHostMachine {
apiContainerGrpcPort = enclaveInfo.ApiContainerHostMachineInfo.GrpcPortOnHostMachine
apiContainerIP = enclaveInfo.ApiContainerHostMachineInfo.IpOnHostMachine
}
grpcServerAddress := fmt.Sprintf("%v:%v", apiContainerIP, apiContainerGrpcPort)
grpcConnection, err := grpc.Dial(grpcServerAddress, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
Expand Down

0 comments on commit 1130aec

Please sign in to comment.