Skip to content

Commit

Permalink
feat: allow override gateway client address and port
Browse files Browse the repository at this point in the history
This patch introduces the `--client-address` and `--client-port`
to the `peer` and `connect` commands of `liqoctl` to override the
value written in the endpoint field of the status of the GatewayServer
resource, which is used to configure the GatewayClient resource.
This is useful especially when the gateway server is not directly
reachable by the client (e.g. it is behind a NAT).
  • Loading branch information
claudiolor authored and fra98 committed Nov 28, 2024
1 parent 1194534 commit 194c2f7
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
8 changes: 8 additions & 0 deletions cmd/liqoctl/cmd/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@ func newNetworkConnectCommand(ctx context.Context, options *network.Options) *co
// Client flags
cmd.Flags().StringVar(&options.ClientGatewayType, "client-type", forge.DefaultGwClientType,
"Type of Gateway Client. Leave empty to use default Liqo implementation of WireGuard")
cmd.Flags().StringVar(&options.ClientConnectAddress, "client-address", "",
"Define the address used by the gateway client to connect to the gateway server."+
"This value overrides the one automatically retrieved by Liqo and it is useful when the server is "+
"not directly reachable (e.g. the server is behind a NAT)")
cmd.Flags().Int32Var(&options.ClientConnectPort, "client-port", 0,
"Define the port used by the gateway client to connect to the gateway server."+
"This value overrides the one automatically retrieved by Liqo and it is useful when the server is "+
"not directly reachable (e.g. the server is behind a NAT)")
cmd.Flags().StringVar(&options.ClientTemplateName, "client-template-name", forge.DefaultGwClientTemplateName,
"Name of the Gateway Client template")
cmd.Flags().StringVar(&options.ClientTemplateNamespace, "client-template-namespace", "",
Expand Down
12 changes: 10 additions & 2 deletions cmd/liqoctl/cmd/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ provider), but not vice versa. Bidirectional peerings can be achieved through
their combination. The same cluster can play the role of provider and consumer
in multiple peerings.
This commands enables a peering towards a remote provider cluster, performing
This commands enables a peering towards a remote provider cluster, performing
the following operations:
- [optional] ensure networking between the two clusters
- ensure authentication between the two clusters (Identity in consumer cluster,
Tenant in provider cluster)
- [optional] create ResourceSlice in consumer cluster and wait for it to be
- [optional] create ResourceSlice in consumer cluster and wait for it to be
accepted by the provider cluster
- [optional] create VirtualNode in consumer cluster
Expand Down Expand Up @@ -100,6 +100,14 @@ func newPeerCommand(ctx context.Context, f *factory.Factory) *cobra.Command {
"Force the NodePort of the Gateway Server service. Leave empty to let Kubernetes allocate a random NodePort")
cmd.Flags().StringVar(&options.ServerServiceLoadBalancerIP, "server-service-loadbalancerip", "",
"IP of the LoadBalancer for the Gateway Server service")
cmd.Flags().StringVar(&options.ClientConnectAddress, "client-address", "",
"Define the address used by the gateway client to connect to the gateway server."+
"This value overrides the one automatically retrieved by Liqo and it is useful when the server is "+
"not directly reachable (e.g. the server is behind a NAT)")
cmd.Flags().Int32Var(&options.ClientConnectPort, "client-port", 0,
"Define the port used by the gateway client to connect to the gateway server."+
"This value overrides the one automatically retrieved by Liqo and it is useful when the server is "+
"not directly reachable (e.g. the server is behind a NAT)")
cmd.Flags().IntVar(&options.MTU, "mtu", nwforge.DefaultMTU,
fmt.Sprintf("MTU of the Gateway server and client. Default: %d", nwforge.DefaultMTU))

Expand Down
20 changes: 19 additions & 1 deletion pkg/liqoctl/network/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ type Options struct {
ClientGatewayType string
ClientTemplateName string
ClientTemplateNamespace string
// ClientConnectAddress is the address used by the client to connect to the gateway server. When this value is specified
// liqoctl ignores the values of server and port written in the GatewayServer status.
ClientConnectAddress string
// ClientConnectPort is the port used by the client to connect to the gateway server. When this value is specified
// liqoctl ignores the values of server and port written in the GatewayServer status.
ClientConnectPort int32

MTU int
DisableSharingKeys bool
Expand Down Expand Up @@ -227,8 +233,20 @@ func (o *Options) RunConnect(ctx context.Context) error {
}

// Create gateway client on cluster 1

// By default address and port used by the GatewayClient are the ones written in the endpoint field of the status of the GatewayServer,
// unless address or port are manually overwritten
endpoint := gwServer.Status.Endpoint
if o.ClientConnectAddress != "" {
endpoint.Addresses = []string{o.ClientConnectAddress}
}

if o.ClientConnectPort != 0 {
endpoint.Port = o.ClientConnectPort
}

gwClient, err := cluster1.EnsureGatewayClient(ctx,
o.newGatewayClientForgeOptions(o.LocalFactory.KubeClient, cluster2.localClusterID, gwServer.Status.Endpoint))
o.newGatewayClientForgeOptions(o.LocalFactory.KubeClient, cluster2.localClusterID, endpoint))
if err != nil {
return err
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/liqoctl/peer/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ type Options struct {
ServerServicePort int32
ServerServiceNodePort int32
ServerServiceLoadBalancerIP string
ClientConnectAddress string
ClientConnectPort int32
MTU int

// Authentication options
Expand Down Expand Up @@ -119,6 +121,8 @@ func ensureNetworking(ctx context.Context, o *Options) error {
ClientGatewayType: nwforge.DefaultGwClientType,
ClientTemplateName: nwforge.DefaultGwClientTemplateName,
ClientTemplateNamespace: o.LocalFactory.LiqoNamespace,
ClientConnectAddress: o.ClientConnectAddress,
ClientConnectPort: o.ClientConnectPort,

MTU: o.MTU,
DisableSharingKeys: false,
Expand Down

0 comments on commit 194c2f7

Please sign in to comment.