Skip to content

Commit 40abdb7

Browse files
claudioloradamjensenbot
authored andcommitted
feat: allow override gateway client address and port
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).
1 parent 1194534 commit 40abdb7

File tree

4 files changed

+41
-3
lines changed

4 files changed

+41
-3
lines changed

cmd/liqoctl/cmd/network.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,14 @@ func newNetworkConnectCommand(ctx context.Context, options *network.Options) *co
165165
// Client flags
166166
cmd.Flags().StringVar(&options.ClientGatewayType, "client-type", forge.DefaultGwClientType,
167167
"Type of Gateway Client. Leave empty to use default Liqo implementation of WireGuard")
168+
cmd.Flags().StringVar(&options.ClientConnectAddress, "client-address", "",
169+
"Define the address used by the gateway client to connect to the gateway server."+
170+
"This value overrides the one automatically retrieved by Liqo and it is useful when the server is "+
171+
"not directly reachable (e.g. the server is behind a NAT)")
172+
cmd.Flags().Int32Var(&options.ClientConnectPort, "client-port", 0,
173+
"Define the port used by the gateway client to connect to the gateway server."+
174+
"This value overrides the one automatically retrieved by Liqo and it is useful when the server is "+
175+
"not directly reachable (e.g. the server is behind a NAT)")
168176
cmd.Flags().StringVar(&options.ClientTemplateName, "client-template-name", forge.DefaultGwClientTemplateName,
169177
"Name of the Gateway Client template")
170178
cmd.Flags().StringVar(&options.ClientTemplateNamespace, "client-template-namespace", "",

cmd/liqoctl/cmd/peer.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ provider), but not vice versa. Bidirectional peerings can be achieved through
3838
their combination. The same cluster can play the role of provider and consumer
3939
in multiple peerings.
4040
41-
This commands enables a peering towards a remote provider cluster, performing
41+
This commands enables a peering towards a remote provider cluster, performing
4242
the following operations:
4343
- [optional] ensure networking between the two clusters
4444
- ensure authentication between the two clusters (Identity in consumer cluster,
4545
Tenant in provider cluster)
46-
- [optional] create ResourceSlice in consumer cluster and wait for it to be
46+
- [optional] create ResourceSlice in consumer cluster and wait for it to be
4747
accepted by the provider cluster
4848
- [optional] create VirtualNode in consumer cluster
4949
@@ -100,6 +100,14 @@ func newPeerCommand(ctx context.Context, f *factory.Factory) *cobra.Command {
100100
"Force the NodePort of the Gateway Server service. Leave empty to let Kubernetes allocate a random NodePort")
101101
cmd.Flags().StringVar(&options.ServerServiceLoadBalancerIP, "server-service-loadbalancerip", "",
102102
"IP of the LoadBalancer for the Gateway Server service")
103+
cmd.Flags().StringVar(&options.ClientConnectAddress, "client-address", "",
104+
"Define the address used by the gateway client to connect to the gateway server."+
105+
"This value overrides the one automatically retrieved by Liqo and it is useful when the server is "+
106+
"not directly reachable (e.g. the server is behind a NAT)")
107+
cmd.Flags().Int32Var(&options.ClientConnectPort, "client-port", 0,
108+
"Define the port used by the gateway client to connect to the gateway server."+
109+
"This value overrides the one automatically retrieved by Liqo and it is useful when the server is "+
110+
"not directly reachable (e.g. the server is behind a NAT)")
103111
cmd.Flags().IntVar(&options.MTU, "mtu", nwforge.DefaultMTU,
104112
fmt.Sprintf("MTU of the Gateway server and client. Default: %d", nwforge.DefaultMTU))
105113

pkg/liqoctl/network/handler.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ type Options struct {
5050
ClientGatewayType string
5151
ClientTemplateName string
5252
ClientTemplateNamespace string
53+
// ClientConnectAddress is the address used by the client to connect to the gateway server. When this value is specified
54+
// liqoctl ignores the values of server and port written in the GatewayServer status.
55+
ClientConnectAddress string
56+
// ClientConnectPort is the port used by the client to connect to the gateway server. When this value is specified
57+
// liqoctl ignores the values of server and port written in the GatewayServer status.
58+
ClientConnectPort int32
5359

5460
MTU int
5561
DisableSharingKeys bool
@@ -227,8 +233,20 @@ func (o *Options) RunConnect(ctx context.Context) error {
227233
}
228234

229235
// Create gateway client on cluster 1
236+
237+
// By default address and port used by the GatewayClient are the ones written in the endpoint field of the status of the GatewayServer,
238+
// unless address or port are manually overwritten
239+
endpoint := gwServer.Status.Endpoint
240+
if o.ClientConnectAddress != "" {
241+
endpoint.Addresses = []string{o.ClientConnectAddress}
242+
}
243+
244+
if o.ClientConnectPort != 0 {
245+
endpoint.Port = o.ClientConnectPort
246+
}
247+
230248
gwClient, err := cluster1.EnsureGatewayClient(ctx,
231-
o.newGatewayClientForgeOptions(o.LocalFactory.KubeClient, cluster2.localClusterID, gwServer.Status.Endpoint))
249+
o.newGatewayClientForgeOptions(o.LocalFactory.KubeClient, cluster2.localClusterID, endpoint))
232250
if err != nil {
233251
return err
234252
}

pkg/liqoctl/peer/handler.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ type Options struct {
4444
ServerServicePort int32
4545
ServerServiceNodePort int32
4646
ServerServiceLoadBalancerIP string
47+
ClientConnectAddress string
48+
ClientConnectPort int32
4749
MTU int
4850

4951
// Authentication options
@@ -119,6 +121,8 @@ func ensureNetworking(ctx context.Context, o *Options) error {
119121
ClientGatewayType: nwforge.DefaultGwClientType,
120122
ClientTemplateName: nwforge.DefaultGwClientTemplateName,
121123
ClientTemplateNamespace: o.LocalFactory.LiqoNamespace,
124+
ClientConnectAddress: o.ClientConnectAddress,
125+
ClientConnectPort: o.ClientConnectPort,
122126

123127
MTU: o.MTU,
124128
DisableSharingKeys: false,

0 commit comments

Comments
 (0)