diff --git a/cmd/liqoctl/cmd/network.go b/cmd/liqoctl/cmd/network.go index 489c9af8a4..a498dfeb75 100644 --- a/cmd/liqoctl/cmd/network.go +++ b/cmd/liqoctl/cmd/network.go @@ -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", "", diff --git a/cmd/liqoctl/cmd/peer.go b/cmd/liqoctl/cmd/peer.go index 6057cebedf..96e1de9380 100644 --- a/cmd/liqoctl/cmd/peer.go +++ b/cmd/liqoctl/cmd/peer.go @@ -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 @@ -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)) diff --git a/pkg/liqoctl/network/handler.go b/pkg/liqoctl/network/handler.go index cf8ea4b46d..8b0fcae421 100644 --- a/pkg/liqoctl/network/handler.go +++ b/pkg/liqoctl/network/handler.go @@ -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 @@ -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 } diff --git a/pkg/liqoctl/peer/handler.go b/pkg/liqoctl/peer/handler.go index 2048dbcf92..adf2f539fc 100644 --- a/pkg/liqoctl/peer/handler.go +++ b/pkg/liqoctl/peer/handler.go @@ -44,6 +44,8 @@ type Options struct { ServerServicePort int32 ServerServiceNodePort int32 ServerServiceLoadBalancerIP string + ClientConnectAddress string + ClientConnectPort int32 MTU int // Authentication options @@ -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,