Skip to content

Commit f27bbc4

Browse files
committed
feat(liqoctl): peer command choose Gateway Server Service position (cons or prov)
1 parent 5284147 commit f27bbc4

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

cmd/liqoctl/cmd/peer.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/spf13/cobra"
2323
"k8s.io/apimachinery/pkg/util/runtime"
2424

25+
liqov1beta1 "github.com/liqotech/liqo/apis/core/v1beta1"
2526
nwforge "github.com/liqotech/liqo/pkg/liqo-controller-manager/networking/forge"
2627
"github.com/liqotech/liqo/pkg/liqoctl/completion"
2728
"github.com/liqotech/liqo/pkg/liqoctl/factory"
@@ -90,8 +91,11 @@ func newPeerCommand(ctx context.Context, f *factory.Factory) *cobra.Command {
9091

9192
// Networking flags
9293
cmd.Flags().BoolVar(&options.NetworkingDisabled, "networking-disabled", false, "Disable networking between the two clusters")
94+
cmd.Flags().Var(options.ServerServiceLocation, "server-service-location",
95+
fmt.Sprintf("Location of the service to expose the Gateway Server (%q or %q). Default: %q",
96+
liqov1beta1.ConsumerRole, liqov1beta1.ProviderRole, nwforge.DefaultGwServerLocation))
9397
cmd.Flags().Var(options.ServerServiceType, "server-service-type",
94-
fmt.Sprintf("Service type of the Gateway Server service. Default: %s."+
98+
fmt.Sprintf("Service type of the Gateway Server service. Default: %q."+
9599
" Note: use ClusterIP only if you know what you are doing and you have a proper network configuration",
96100
nwforge.DefaultGwServerServiceType))
97101
cmd.Flags().Int32Var(&options.ServerServicePort, "server-service-port", nwforge.DefaultGwServerPort,
@@ -111,6 +115,7 @@ func newPeerCommand(ctx context.Context, f *factory.Factory) *cobra.Command {
111115
cmd.Flags().IntVar(&options.MTU, "mtu", nwforge.DefaultMTU,
112116
fmt.Sprintf("MTU of the Gateway server and client. Default: %d", nwforge.DefaultMTU))
113117

118+
runtime.Must(cmd.RegisterFlagCompletionFunc("server-service-location", completion.Enumeration(options.ServerServiceLocation.Allowed)))
114119
runtime.Must(cmd.RegisterFlagCompletionFunc("server-service-type", completion.Enumeration(options.ServerServiceType.Allowed)))
115120

116121
// Authentication flags

pkg/liqo-controller-manager/networking/forge/gatewayserver.go

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
const (
3131
DefaultGwServerType = "networking.liqo.io/v1beta1/wggatewayservertemplates"
3232
DefaultGwServerTemplateName = "wireguard-server"
33+
DefaultGwServerLocation = liqov1beta1.ProviderRole
3334
DefaultGwServerServiceType = corev1.ServiceTypeLoadBalancer
3435
DefaultGwServerPort = 51840
3536
DefaultKeysDir = "/etc/wireguard/keys"

pkg/liqoctl/peer/handler.go

+18-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020

2121
corev1 "k8s.io/api/core/v1"
2222

23+
liqov1beta1 "github.com/liqotech/liqo/apis/core/v1beta1"
2324
nwforge "github.com/liqotech/liqo/pkg/liqo-controller-manager/networking/forge"
2425
"github.com/liqotech/liqo/pkg/liqoctl/authenticate"
2526
"github.com/liqotech/liqo/pkg/liqoctl/factory"
@@ -40,6 +41,7 @@ type Options struct {
4041

4142
// Networking options
4243
NetworkingDisabled bool
44+
ServerServiceLocation *argsutils.StringEnum
4345
ServerServiceType *argsutils.StringEnum
4446
ServerServicePort int32
4547
ServerServiceNodePort int32
@@ -65,6 +67,9 @@ type Options struct {
6567
func NewOptions(localFactory *factory.Factory) *Options {
6668
return &Options{
6769
LocalFactory: localFactory,
70+
ServerServiceLocation: argsutils.NewEnum(
71+
[]string{string(liqov1beta1.ConsumerRole), string(liqov1beta1.ProviderRole)},
72+
string(nwforge.DefaultGwServerLocation)),
6873
ServerServiceType: argsutils.NewEnum(
6974
[]string{string(corev1.ServiceTypeLoadBalancer), string(corev1.ServiceTypeNodePort), string(corev1.ServiceTypeClusterIP)},
7075
string(nwforge.DefaultGwServerServiceType)),
@@ -109,25 +114,34 @@ func (o *Options) RunPeer(ctx context.Context) error {
109114
}
110115

111116
func ensureNetworking(ctx context.Context, o *Options) error {
117+
localFactory := o.LocalFactory
118+
remoteFactory := o.RemoteFactory
119+
120+
// Invert the local and remote factories if the server service position is Consumer.
121+
if o.ServerServiceLocation.Value == string(liqov1beta1.ConsumerRole) {
122+
localFactory = o.RemoteFactory
123+
remoteFactory = o.LocalFactory
124+
}
125+
112126
networkOptions := network.Options{
113-
LocalFactory: o.LocalFactory,
114-
RemoteFactory: o.RemoteFactory,
127+
LocalFactory: localFactory,
128+
RemoteFactory: remoteFactory,
115129

116130
Timeout: o.Timeout,
117131
Wait: true,
118132
SkipValidation: o.SkipValidation,
119133

120134
ServerGatewayType: nwforge.DefaultGwServerType,
121135
ServerTemplateName: nwforge.DefaultGwServerTemplateName,
122-
ServerTemplateNamespace: o.RemoteFactory.LiqoNamespace,
136+
ServerTemplateNamespace: remoteFactory.LiqoNamespace,
123137
ServerServiceType: o.ServerServiceType,
124138
ServerServicePort: o.ServerServicePort,
125139
ServerServiceNodePort: o.ServerServiceNodePort,
126140
ServerServiceLoadBalancerIP: o.ServerServiceLoadBalancerIP,
127141

128142
ClientGatewayType: nwforge.DefaultGwClientType,
129143
ClientTemplateName: nwforge.DefaultGwClientTemplateName,
130-
ClientTemplateNamespace: o.LocalFactory.LiqoNamespace,
144+
ClientTemplateNamespace: localFactory.LiqoNamespace,
131145
ClientConnectAddress: o.ClientConnectAddress,
132146
ClientConnectPort: o.ClientConnectPort,
133147

0 commit comments

Comments
 (0)