-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add GRPC reverse tunnel server
Allow Omni API clients to receive GRPC calls in the reverse direction, `Omni->Client`. Might be used by the infra providers, e.g., bare-metal infra provider. Signed-off-by: Utku Ozdemir <[email protected]>
- Loading branch information
1 parent
5a26d4c
commit 8c4d44b
Showing
10 changed files
with
242 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,43 @@ | ||
// Copyright (c) 2024 Sidero Labs, Inc. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the LICENSE file. | ||
|
||
// Package baremetal provides a client to interact with the bare-metal infra provider. | ||
package baremetal | ||
|
||
import ( | ||
"github.com/jhump/grpctunnel" | ||
"go.uber.org/zap" | ||
"google.golang.org/grpc/metadata" | ||
) | ||
|
||
const ( | ||
// ProviderIDMetadataKey is the key used to identify the infra provider ID in the GRPC metadata (header). | ||
ProviderIDMetadataKey = "provider-id" | ||
|
||
unknownProviderID = "unknown" | ||
) | ||
|
||
// GetAffinityKey extracts the AffinityKey from the given GRPC tunnel context. | ||
func GetAffinityKey(channel grpctunnel.TunnelChannel, logger *zap.Logger) string { | ||
md, ok := metadata.FromIncomingContext(channel.Context()) | ||
if !ok { | ||
logger.Warn("no metadata found in channel context") | ||
|
||
return unknownProviderID | ||
} | ||
|
||
vals := md.Get(ProviderIDMetadataKey) | ||
if len(vals) == 0 { | ||
logger.Warn("no provider ID found in metadata") | ||
|
||
return unknownProviderID | ||
} | ||
|
||
if len(vals) > 1 { | ||
logger.Warn("multiple provider IDs found in metadata, using the first one", zap.Strings("provider_ids", vals)) | ||
} | ||
|
||
return vals[0] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (c) 2024 Sidero Labs, Inc. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the LICENSE file. | ||
|
||
package grpc | ||
|
||
import ( | ||
"context" | ||
|
||
gateway "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" | ||
"github.com/jhump/grpctunnel" | ||
"github.com/jhump/grpctunnel/tunnelpb" | ||
"google.golang.org/grpc" | ||
) | ||
|
||
type tunnelServer struct { | ||
handler *grpctunnel.TunnelServiceHandler | ||
} | ||
|
||
func (t *tunnelServer) register(server grpc.ServiceRegistrar) { | ||
service := t.handler.Service() | ||
|
||
tunnelpb.RegisterTunnelServiceServer(server, service) | ||
} | ||
|
||
func (t *tunnelServer) gateway(context.Context, *gateway.ServeMux, string, []grpc.DialOption) error { | ||
// no-op - don't register a gateway for the tunnel service | ||
return 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