Skip to content

Commit

Permalink
Tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
fra98 committed Nov 9, 2023
1 parent c9e14b5 commit c3fd686
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ spec:
type: "{{"{{ .Spec.Endpoint.ServiceType }}"}}"
ports:
- port: "{{"{{ .Spec.Endpoint.Port }}"}}"
# nodePort: "{{"{{ .Spec.Endpoint.NodePort }}"}}"
protocol: UDP
targetPort: "{{"{{ .Spec.Endpoint.Port }}"}}"
# loadBalancerIP: "{{"{{ .Spec.Endpoint.LoadBalancerIP }}"}}"
{{- if .Values.networking.gateway.server.service.allocateLoadBalancerNodePorts }}
allocateLoadBalancerNodePorts: {{ .Values.networking.gateway.server.service.allocateLoadBalancerNodePorts }}
{{- end }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (

networkingv1alpha1 "github.com/liqotech/liqo/apis/networking/v1alpha1"
"github.com/liqotech/liqo/pkg/consts"
"github.com/liqotech/liqo/pkg/gateway"
enutils "github.com/liqotech/liqo/pkg/liqo-controller-manager/external-network/utils"
mapsutil "github.com/liqotech/liqo/pkg/utils/maps"
)
Expand Down Expand Up @@ -86,7 +87,7 @@ func (r *WgGatewayClientReconciler) Reconcile(ctx context.Context, req ctrl.Requ
}

// Ensure deployment (create or update)
deployNsName := types.NamespacedName{Namespace: wgClient.Namespace, Name: wgClient.Name}
deployNsName := types.NamespacedName{Namespace: wgClient.Namespace, Name: gateway.GenerateResourceName(wgClient.Name)}
_, err = r.ensureDeployment(ctx, wgClient, deployNsName)
if err != nil {
return ctrl.Result{}, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
networkingv1alpha1 "github.com/liqotech/liqo/apis/networking/v1alpha1"
"github.com/liqotech/liqo/pkg/consts"
"github.com/liqotech/liqo/pkg/discovery"
"github.com/liqotech/liqo/pkg/gateway"
enutils "github.com/liqotech/liqo/pkg/liqo-controller-manager/external-network/utils"
"github.com/liqotech/liqo/pkg/utils"
mapsutil "github.com/liqotech/liqo/pkg/utils/maps"
Expand Down Expand Up @@ -96,14 +97,14 @@ func (r *WgGatewayServerReconciler) Reconcile(ctx context.Context, req ctrl.Requ
}

// Ensure deployment (create or update)
deployNsName := types.NamespacedName{Namespace: wgServer.Namespace, Name: wgServer.Name}
deployNsName := types.NamespacedName{Namespace: wgServer.Namespace, Name: gateway.GenerateResourceName(wgServer.Name)}
deploy, err := r.ensureDeployment(ctx, wgServer, deployNsName)
if err != nil {
return ctrl.Result{}, err
}

// Ensure service (create or update)
svcNsName := types.NamespacedName{Namespace: wgServer.Namespace, Name: wgServer.Name}
svcNsName := types.NamespacedName{Namespace: wgServer.Namespace, Name: gateway.GenerateResourceName(wgServer.Name)}
_, err = r.ensureService(ctx, wgServer, svcNsName)
if err != nil {
return ctrl.Result{}, err
Expand Down
24 changes: 24 additions & 0 deletions pkg/liqoctl/network/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ import (
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

discoveryv1alpha1 "github.com/liqotech/liqo/apis/discovery/v1alpha1"
networkingv1alpha1 "github.com/liqotech/liqo/apis/networking/v1alpha1"
"github.com/liqotech/liqo/pkg/consts"
"github.com/liqotech/liqo/pkg/gateway"
"github.com/liqotech/liqo/pkg/liqoctl/factory"
"github.com/liqotech/liqo/pkg/liqoctl/output"
"github.com/liqotech/liqo/pkg/liqoctl/rest/configuration"
Expand Down Expand Up @@ -219,6 +221,28 @@ func (c *Cluster) EnsureGatewayServer(ctx context.Context, name string, opts *ga
s.Fail(fmt.Sprintf("An error occurred while forging gateway server: %v", output.PrettyErr(err)))
return nil, err
}

// Get existing Service if present
var service corev1.Service
svcNsName := types.NamespacedName{Namespace: gwServer.Namespace, Name: gateway.GenerateResourceName(gwServer.Name)}
err = c.local.CRClient.Get(ctx, svcNsName, &service)
if client.IgnoreNotFound(err) != nil {
s.Fail(fmt.Sprintf("An error occurred while retrieving gateway server service: %v", output.PrettyErr(err)))
return nil, err
} else if err == nil {
if gwServer.Spec.Endpoint.ServiceType != service.Spec.Type ||
gwServer.Spec.Endpoint.Port != service.Spec.Ports[0].Port ||
*gwServer.Spec.Endpoint.NodePort != service.Spec.Ports[0].NodePort ||
*gwServer.Spec.Endpoint.LoadBalancerIP != service.Spec.LoadBalancerIP {
// Delete service if it exists but it is not the same as the one we want to create
if err := c.local.CRClient.Delete(ctx, gwServer); err != nil {
s.Fail(fmt.Sprintf("An error occurred while deleting gateway server service: %v", output.PrettyErr(err)))
return nil, err
}
s.Success("Deleted existing gateway server")
}
}

_, err = controllerutil.CreateOrUpdate(ctx, c.local.CRClient, gwServer, func() error {
return gatewayserver.MutateGatewayServer(gwServer, opts)
})
Expand Down

0 comments on commit c3fd686

Please sign in to comment.