Skip to content

Commit

Permalink
Added support for static LoadBalancerIP and NodePort
Browse files Browse the repository at this point in the history
  • Loading branch information
fra98 committed Oct 27, 2023
1 parent fd77f16 commit 7ef4440
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 2 deletions.
7 changes: 7 additions & 0 deletions apis/networking/v1alpha1/gatewayserver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ type Endpoint struct {
// +kubebuilder:default=ClusterIP
// +kubebuilder:validation:Enum=ClusterIP;NodePort;LoadBalancer;ExternalName
ServiceType corev1.ServiceType `json:"serviceType,omitempty"`
// NodePort specifies the node port of the endpoint.
// +optional
NodePort *int32 `json:"nodePort,omitempty"`
// LoadBalancerIP override the LoadBalancer IP to use a specific IP address (e.g., static LB). It is used only if service type is LoadBalancer.
// LoadBalancer provider must support this feature.
// +optional
LoadBalancerIP *string `json:"loadBalancerIP,omitempty"`
}

// GatewayServerSpec defines the desired state of GatewayServer.
Expand Down
14 changes: 12 additions & 2 deletions apis/networking/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions cmd/liqoctl/cmd/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ func newNetworkConnectCommand(ctx context.Context, options *network.Options) *co
fmt.Sprintf("Service type of the Gateway Server. Default: %s", gatewayserver.DefaultServiceType))
cmd.Flags().Int32Var(&options.ServerPort, "server-port", gatewayserver.DefaultPort,
fmt.Sprintf("Port of the Gateway Server. Default: %d", gatewayserver.DefaultPort))
cmd.Flags().Int32Var(&options.ServerNodePort, "node-port", 0,
"Force NodePort of Gateway Server")
cmd.Flags().StringVar(&options.ServerLoadBalancerIP, "load-balancer-ip", "",
"Force LoadBalancer IP of Gateway Server")

// Client flags
cmd.Flags().StringVar(&options.ClientGatewayType, "client-type", gatewayclient.DefaultGatewayType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ spec:
endpoint:
description: Endpoint specifies the endpoint of the tunnel.
properties:
loadBalancerIP:
description: LoadBalancerIP override the LoadBalancer IP to use
a specific IP address (e.g., static LB). It is used only if
service type is LoadBalancer. LoadBalancer provider must support
this feature.
type: string
nodePort:
description: NodePort specifies the node port of the endpoint.
format: int32
type: integer
port:
description: Port specifies the port of the endpoint.
format: int32
Expand Down
5 changes: 5 additions & 0 deletions pkg/liqoctl/network/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

v1 "k8s.io/api/core/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/utils/ptr"

networkingv1alpha1 "github.com/liqotech/liqo/apis/networking/v1alpha1"
"github.com/liqotech/liqo/pkg/liqoctl/factory"
Expand All @@ -43,6 +44,8 @@ type Options struct {
ServerTemplateNamespace string
ServerServiceType *argsutils.StringEnum
ServerPort int32
ServerNodePort int32
ServerLoadBalancerIP string

ClientGatewayType string
ClientTemplateName string
Expand Down Expand Up @@ -282,6 +285,8 @@ func (o *Options) newGatewayServerForgeOptions(kubeClient kubernetes.Interface,
ServiceType: v1.ServiceType(o.ServerServiceType.Value),
MTU: o.MTU,
Port: o.ServerPort,
NodePort: ptr.To(o.ServerNodePort),
LoadBalancerIP: ptr.To(o.ServerLoadBalancerIP),
Proxy: o.Proxy,
}
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/liqoctl/rest/gatewayserver/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ func (o *Options) Create(ctx context.Context, options *rest.CreateOptions) *cobr
cmd.Flags().Var(o.ServiceType, "service-type", fmt.Sprintf("Service type of Gateway Server. Default: %s", DefaultServiceType))
cmd.Flags().IntVar(&o.MTU, "mtu", DefaultMTU, "MTU of Gateway Server")
cmd.Flags().Int32Var(&o.Port, "port", DefaultPort, "Port of Gateway Server")
cmd.Flags().Int32Var(&o.NodePort, "node-port", 0, "Force NodePort of Gateway Server")
cmd.Flags().StringVar(&o.LoadBalancerIP, "load-balancer-ip", "", "Force LoadBalancer IP of Gateway Server")
cmd.Flags().BoolVar(&o.Proxy, "proxy", DefaultProxy, "Enable proxy for the Gateway Server")
cmd.Flags().BoolVar(&o.Wait, "wait", DefaultWait, "Wait for the Gateway Server to be ready")

Expand Down
7 changes: 7 additions & 0 deletions pkg/liqoctl/rest/gatewayserver/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package gatewayserver
import (
corev1 "k8s.io/api/core/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/utils/ptr"

"github.com/liqotech/liqo/pkg/liqoctl/rest"
argsutils "github.com/liqotech/liqo/pkg/utils/args"
Expand Down Expand Up @@ -46,6 +47,8 @@ type Options struct {
ServiceType *argsutils.StringEnum
MTU int
Port int32
NodePort int32
LoadBalancerIP string
Proxy bool
Wait bool
}
Expand Down Expand Up @@ -78,6 +81,8 @@ type ForgeOptions struct {
ServiceType corev1.ServiceType
MTU int
Port int32
NodePort *int32
LoadBalancerIP *string
Proxy bool
}

Expand All @@ -91,6 +96,8 @@ func (o *Options) getForgeOptions() *ForgeOptions {
ServiceType: corev1.ServiceType(o.ServiceType.Value),
MTU: o.MTU,
Port: o.Port,
NodePort: ptr.To(o.NodePort),
LoadBalancerIP: ptr.To(o.LoadBalancerIP),
Proxy: o.Proxy,
}
}
11 changes: 11 additions & 0 deletions pkg/liqoctl/rest/gatewayserver/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func ForgeGatewayServer(name, namespace string, o *ForgeOptions) (*networkingv1a

// MutateGatewayServer mutates a GatewayServer.
func MutateGatewayServer(gwServer *networkingv1alpha1.GatewayServer, o *ForgeOptions) error {
// Metadata
gwServer.Kind = networkingv1alpha1.GatewayServerKind
gwServer.APIVersion = networkingv1alpha1.GroupVersion.String()

Expand All @@ -56,12 +57,22 @@ func MutateGatewayServer(gwServer *networkingv1alpha1.GatewayServer, o *ForgeOpt
}
gwServer.Labels[liqoconsts.RemoteClusterID] = o.RemoteClusterID

// MTU
gwServer.Spec.MTU = o.MTU

// Server Endpoint
gwServer.Spec.Endpoint = networkingv1alpha1.Endpoint{
Port: o.Port,
ServiceType: o.ServiceType,
}
if o.NodePort != nil && *o.NodePort != 0 {
gwServer.Spec.Endpoint.NodePort = o.NodePort
}
if o.LoadBalancerIP != nil && *o.LoadBalancerIP != "" {
gwServer.Spec.Endpoint.LoadBalancerIP = o.LoadBalancerIP
}

// Server Template Reference
gvr, err := enutils.ParseGroupVersionResource(o.GatewayType)
if err != nil {
return err
Expand Down

0 comments on commit 7ef4440

Please sign in to comment.