Skip to content

Commit

Permalink
feat(liqoctl): peer command choose Gateway Server Service position (c…
Browse files Browse the repository at this point in the history
…ons or prov)
  • Loading branch information
fra98 committed Jan 31, 2025
1 parent d03e24a commit 730d807
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
7 changes: 6 additions & 1 deletion cmd/liqoctl/cmd/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/util/runtime"

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

// Networking flags
cmd.Flags().BoolVar(&options.NetworkingDisabled, "networking-disabled", false, "Disable networking between the two clusters")
cmd.Flags().Var(options.ServerServicePosition, "server-service-position",
fmt.Sprintf("Position of the Gateway Server service (%q or %q). Default: %q",
liqov1beta1.ConsumerRole, liqov1beta1.ProviderRole, nwforge.DefaultGwServerPosition))
cmd.Flags().Var(options.ServerServiceType, "server-service-type",
fmt.Sprintf("Service type of the Gateway Server service. Default: %s."+
fmt.Sprintf("Service type of the Gateway Server service. Default: %q."+
" Note: use ClusterIP only if you know what you are doing and you have a proper network configuration",
nwforge.DefaultGwServerServiceType))
cmd.Flags().Int32Var(&options.ServerServicePort, "server-service-port", nwforge.DefaultGwServerPort,
Expand All @@ -111,6 +115,7 @@ func newPeerCommand(ctx context.Context, f *factory.Factory) *cobra.Command {
cmd.Flags().IntVar(&options.MTU, "mtu", nwforge.DefaultMTU,
fmt.Sprintf("MTU of the Gateway server and client. Default: %d", nwforge.DefaultMTU))

runtime.Must(cmd.RegisterFlagCompletionFunc("server-service-position", completion.Enumeration(options.ServerServicePosition.Allowed)))
runtime.Must(cmd.RegisterFlagCompletionFunc("server-service-type", completion.Enumeration(options.ServerServiceType.Allowed)))

// Authentication flags
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
const (
DefaultGwServerType = "networking.liqo.io/v1beta1/wggatewayservertemplates"
DefaultGwServerTemplateName = "wireguard-server"
DefaultGwServerPosition = liqov1beta1.ProviderRole
DefaultGwServerServiceType = corev1.ServiceTypeLoadBalancer
DefaultGwServerPort = 51840
DefaultKeysDir = "/etc/wireguard/keys"
Expand Down
22 changes: 18 additions & 4 deletions pkg/liqoctl/peer/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

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

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

// Networking options
NetworkingDisabled bool
ServerServicePosition *argsutils.StringEnum
ServerServiceType *argsutils.StringEnum
ServerServicePort int32
ServerServiceNodePort int32
Expand All @@ -65,6 +67,9 @@ type Options struct {
func NewOptions(localFactory *factory.Factory) *Options {
return &Options{
LocalFactory: localFactory,
ServerServicePosition: argsutils.NewEnum(
[]string{string(liqov1beta1.ConsumerRole), string(liqov1beta1.ProviderRole)},
string(nwforge.DefaultGwServerPosition)),
ServerServiceType: argsutils.NewEnum(
[]string{string(corev1.ServiceTypeLoadBalancer), string(corev1.ServiceTypeNodePort), string(corev1.ServiceTypeClusterIP)},
string(nwforge.DefaultGwServerServiceType)),
Expand Down Expand Up @@ -109,25 +114,34 @@ func (o *Options) RunPeer(ctx context.Context) error {
}

func ensureNetworking(ctx context.Context, o *Options) error {
localFactory := o.LocalFactory
remoteFactory := o.RemoteFactory

// Invert the local and remote factories if the server service position is Consumer.
if o.ServerServicePosition.Value == string(liqov1beta1.ConsumerRole) {
localFactory = o.RemoteFactory
remoteFactory = o.LocalFactory
}

networkOptions := network.Options{
LocalFactory: o.LocalFactory,
RemoteFactory: o.RemoteFactory,
LocalFactory: localFactory,
RemoteFactory: remoteFactory,

Timeout: o.Timeout,
Wait: true,
SkipValidation: o.SkipValidation,

ServerGatewayType: nwforge.DefaultGwServerType,
ServerTemplateName: nwforge.DefaultGwServerTemplateName,
ServerTemplateNamespace: o.RemoteFactory.LiqoNamespace,
ServerTemplateNamespace: remoteFactory.LiqoNamespace,
ServerServiceType: o.ServerServiceType,
ServerServicePort: o.ServerServicePort,
ServerServiceNodePort: o.ServerServiceNodePort,
ServerServiceLoadBalancerIP: o.ServerServiceLoadBalancerIP,

ClientGatewayType: nwforge.DefaultGwClientType,
ClientTemplateName: nwforge.DefaultGwClientTemplateName,
ClientTemplateNamespace: o.LocalFactory.LiqoNamespace,
ClientTemplateNamespace: localFactory.LiqoNamespace,
ClientConnectAddress: o.ClientConnectAddress,
ClientConnectPort: o.ClientConnectPort,

Expand Down

0 comments on commit 730d807

Please sign in to comment.