Skip to content

Commit

Permalink
support cluster ip in gateway services
Browse files Browse the repository at this point in the history
  • Loading branch information
aleoli authored and adamjensenbot committed Oct 1, 2024
1 parent 05b16db commit 523cbc0
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
4 changes: 3 additions & 1 deletion cmd/liqoctl/cmd/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ func newNetworkConnectCommand(ctx context.Context, options *network.Options) *co
cmd.Flags().StringVar(&options.ServerTemplateNamespace, "server-template-namespace", "",
"Namespace of the Gateway Server template")
cmd.Flags().Var(options.ServerServiceType, "server-service-type",
fmt.Sprintf("Service type of the Gateway Server. Default: %s", forge.DefaultGwServerServiceType))
fmt.Sprintf("Service type of the Gateway Server. Default: %s."+
" Note: use ClusterIP only if you know what you are doing and you have a proper network configuration",
forge.DefaultGwServerServiceType))
cmd.Flags().Int32Var(&options.ServerPort, "server-port", forge.DefaultGwServerPort,
fmt.Sprintf("Port of the Gateway Server. Default: %d", forge.DefaultGwServerPort))
cmd.Flags().Int32Var(&options.ServerNodePort, "node-port", 0,
Expand Down
4 changes: 3 additions & 1 deletion cmd/liqoctl/cmd/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ 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.ServerServiceType, "server-service-type",
fmt.Sprintf("Service type of the Gateway Server. Default: %s", nwforge.DefaultGwServerServiceType))
fmt.Sprintf("Service type of the Gateway Server. Default: %s."+
" Note: use ClusterIP only if you know what you are doing and you have a proper network configuration",
nwforge.DefaultGwServerServiceType))
cmd.Flags().Int32Var(&options.ServerPort, "server-port", nwforge.DefaultGwServerPort,
fmt.Sprintf("Port of the Gateway Server. Default: %d", nwforge.DefaultGwServerPort))
cmd.Flags().IntVar(&options.MTU, "mtu", nwforge.DefaultMTU,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ func (r *WgGatewayServerReconciler) handleEndpointStatus(ctx context.Context, wg
// Put service endpoint in WireGuard server status
var endpointStatus *networkingv1beta1.EndpointStatus
switch service.Spec.Type {
case corev1.ServiceTypeClusterIP:
endpointStatus, err = r.forgeEndpointStatusClusterIP(&service)
case corev1.ServiceTypeNodePort:
endpointStatus, _, err = r.forgeEndpointStatusNodePort(ctx, &service, dep)
case corev1.ServiceTypeLoadBalancer:
Expand All @@ -282,6 +284,28 @@ func (r *WgGatewayServerReconciler) handleEndpointStatus(ctx context.Context, wg
return nil
}

func (r *WgGatewayServerReconciler) forgeEndpointStatusClusterIP(service *corev1.Service) (*networkingv1beta1.EndpointStatus, error) {
if len(service.Spec.Ports) == 0 {
err := fmt.Errorf("service %s/%s has no ports", service.Namespace, service.Name)
klog.Error(err)
return nil, err
}

port := service.Spec.Ports[0].Port
protocol := &service.Spec.Ports[0].Protocol
addresses := service.Spec.ClusterIPs

if err := checkServiceOverrides(service, &addresses, &port); err != nil {
return nil, err
}

return &networkingv1beta1.EndpointStatus{
Protocol: protocol,
Port: port,
Addresses: addresses,
}, nil
}

func (r *WgGatewayServerReconciler) forgeEndpointStatusNodePort(ctx context.Context, service *corev1.Service,
dep *appsv1.Deployment) (*networkingv1beta1.EndpointStatus, *networkingv1beta1.InternalGatewayEndpoint, error) {
if len(service.Spec.Ports) == 0 {
Expand Down
3 changes: 2 additions & 1 deletion pkg/liqoctl/network/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ func NewOptions(localFactory *factory.Factory) *Options {
return &Options{
LocalFactory: localFactory,
ServerServiceType: argsutils.NewEnum(
[]string{string(corev1.ServiceTypeLoadBalancer), string(corev1.ServiceTypeNodePort)}, string(forge.DefaultGwServerServiceType)),
[]string{string(corev1.ServiceTypeLoadBalancer), string(corev1.ServiceTypeNodePort), string(corev1.ServiceTypeClusterIP)},
string(forge.DefaultGwServerServiceType)),
}
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/liqoctl/peer/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ func NewOptions(localFactory *factory.Factory) *Options {
return &Options{
LocalFactory: localFactory,
ServerServiceType: argsutils.NewEnum(
[]string{string(corev1.ServiceTypeLoadBalancer), string(corev1.ServiceTypeNodePort)}, string(nwforge.DefaultGwServerServiceType)),
[]string{string(corev1.ServiceTypeLoadBalancer), string(corev1.ServiceTypeNodePort), string(corev1.ServiceTypeClusterIP)},
string(nwforge.DefaultGwServerServiceType)),
}
}

Expand Down

0 comments on commit 523cbc0

Please sign in to comment.