@@ -63,7 +63,8 @@ const (
6363
6464 proxyName = "liqo-proxy"
6565
66- authPort = "https"
66+ authPort = "https"
67+ proxyPort = "http"
6768)
6869
6970var (
@@ -286,6 +287,25 @@ func (c *Cluster) Init(ctx context.Context) error {
286287 }
287288 s .Success ("authentication endpoint correctly retrieved" )
288289
290+ // Get proxy endpoint.
291+ s , _ = c .printer .Spinner .Start ("retrieving proxy endpoint" )
292+ selector , err = metav1 .LabelSelectorAsSelector (& liqolabels .ProxyServiceLabelSelector )
293+ if err != nil {
294+ s .Fail (fmt .Sprintf ("an error occurred while retrieving proxy endpoint: %v" , err ))
295+ return err
296+ }
297+ svc , err = liqogetters .GetServiceByLabel (ctx , c .locCtrlRunClient , c .namespace , selector )
298+ if err != nil {
299+ s .Fail (fmt .Sprintf ("an error occurred while retrieving proxy endpoint: %v" , err ))
300+ return err
301+ }
302+ ipProxy , portProxy , err := liqogetters .RetrieveEndpointFromService (svc , corev1 .ServiceTypeClusterIP , proxyPort )
303+ if err != nil {
304+ s .Fail (fmt .Sprintf ("an error occurred while retrieving proxy endpoint: %v" , err ))
305+ return err
306+ }
307+ s .Success ("proxy endpoint correctly retrieved" )
308+
289309 // Set configuration
290310 c .clusterID = clusterID
291311 c .netConfig = netcfg
@@ -304,6 +324,11 @@ func (c *Cluster) Init(ctx context.Context) error {
304324 port : portAuth ,
305325 }
306326
327+ c .proxyEP = & Endpoint {
328+ ip : ipProxy ,
329+ port : portProxy ,
330+ }
331+
307332 return nil
308333}
309334
@@ -631,22 +656,6 @@ func (c *Cluster) StopPortForwardIPAM() {
631656 s .Success (fmt .Sprintf ("IPAM service port-forward correctly stopped {%s}" , c .PortForwardOpts .Ports [0 ]))
632657}
633658
634- // SetUpProxy configures the proxy deployment.
635- func (c * Cluster ) SetUpProxy (ctx context.Context ) error {
636- s , _ := c .printer .Spinner .Start (fmt .Sprintf ("configuring proxy pod {%s} and service in namespace {%s}" , proxyName , c .namespace ))
637-
638- ep , err := createProxyDeployment (ctx , c .locK8sClient , proxyName , c .namespace )
639- if err != nil {
640- s .Fail (fmt .Sprintf ("an error occurred while setting up proxy {%s} in namespace {%s}: %v" , proxyName , c .namespace , err ))
641- return err
642- }
643- s .Success (fmt .Sprintf ("proxy {%s} correctly configured in namespace {%s}" , proxyName , c .namespace ))
644-
645- c .proxyEP = ep
646-
647- return nil
648- }
649-
650659// MapProxyIPForCluster maps the ClusterIP address of the local proxy on the local external CIDR as seen by the remote cluster.
651660func (c * Cluster ) MapProxyIPForCluster (ctx context.Context , ipamClient ipam.IpamClient , remoteCluster * discoveryv1alpha1.ClusterIdentity ) error {
652661 clusterName := remoteCluster .ClusterName
@@ -670,36 +679,10 @@ func (c *Cluster) MapProxyIPForCluster(ctx context.Context, ipamClient ipam.Ipam
670679// UnmapProxyIPForCluster unmaps the ClusterIP address of the local proxy on the local external CIDR as seen by the remote cluster.
671680func (c * Cluster ) UnmapProxyIPForCluster (ctx context.Context , ipamClient ipam.IpamClient , remoteCluster * discoveryv1alpha1.ClusterIdentity ) error {
672681 clusterName := remoteCluster .ClusterName
673-
674- // TODO: this logic will be moved on the Init function once
675- // the creation of the proxy deployment and service will be
676- // done at install time of liqo through the helm chart.
682+ ipToBeUnmapped := c .proxyEP .GetIP ()
677683
678684 s , _ := c .printer .Spinner .Start (fmt .Sprintf ("unmapping proxy ip for cluster {%s}" , clusterName ))
679685
680- selector , err := metav1 .LabelSelectorAsSelector (& liqolabels .ProxyServiceLabelSelector )
681- if err != nil {
682- s .Fail (fmt .Sprintf ("an error occurred while retrieving proxy endpoint: %v" , err ))
683- return err
684- }
685- svc , err := liqogetters .GetServiceByLabel (ctx , c .locCtrlRunClient , c .namespace , selector )
686- if client .IgnoreNotFound (err ) != nil {
687- s .Fail (fmt .Sprintf ("an error occurred while retrieving proxy endpoint: %v" , err ))
688- return err
689- }
690- if k8serrors .IsNotFound (err ) {
691- s .Warning (fmt .Sprintf ("service for proxy not found, unable to unmap proxy ip for cluster {%s}" , clusterName ))
692- return nil
693- }
694-
695- ipAuth , _ , err := liqogetters .RetrieveEndpointFromService (svc , corev1 .ServiceTypeClusterIP , "http" )
696- if err != nil {
697- s .Fail (fmt .Sprintf ("an error occurred while retrieving proxy endpoint: %v" , err ))
698- return err
699- }
700-
701- ipToBeUnmapped := ipAuth
702-
703686 if err := unmapServiceForCluster (ctx , ipamClient , ipToBeUnmapped , remoteCluster ); err != nil {
704687 s .Fail (fmt .Sprintf ("an error occurred while unmapping proxy address {%s} for cluster {%s}: %v" , ipToBeUnmapped , clusterName , err ))
705688 return err
@@ -713,19 +696,19 @@ func (c *Cluster) UnmapProxyIPForCluster(ctx context.Context, ipamClient ipam.Ip
713696// MapAuthIPForCluster maps the ClusterIP address of the local auth service on the local external CIDR as seen by the remote cluster.
714697func (c * Cluster ) MapAuthIPForCluster (ctx context.Context , ipamClient ipam.IpamClient , remoteCluster * discoveryv1alpha1.ClusterIdentity ) error {
715698 clusterName := remoteCluster .ClusterName
716- ipToBeUnmapped := c .authEP .GetIP ()
699+ ipToBeRemapped := c .authEP .GetIP ()
717700
718- s , _ := c .printer .Spinner .Start (fmt .Sprintf ("mapping auth ip {%s} for cluster {%s}" , ipToBeUnmapped , clusterName ))
701+ s , _ := c .printer .Spinner .Start (fmt .Sprintf ("mapping auth ip {%s} for cluster {%s}" , ipToBeRemapped , clusterName ))
719702
720- ip , err := mapServiceForCluster (ctx , ipamClient , ipToBeUnmapped , remoteCluster )
703+ ip , err := mapServiceForCluster (ctx , ipamClient , ipToBeRemapped , remoteCluster )
721704 if err != nil {
722- s .Fail (fmt .Sprintf ("an error occurred while mapping auth address {%s} for cluster {%s}: %v" , ipToBeUnmapped , clusterName , err ))
705+ s .Fail (fmt .Sprintf ("an error occurred while mapping auth address {%s} for cluster {%s}: %v" , ipToBeRemapped , clusterName , err ))
723706 return err
724707 }
725708
726709 c .authEP .SetRemappedIP (ip )
727710
728- s .Success (fmt .Sprintf ("auth address {%s} remapped to {%s} for remote cluster {%s}" , ipToBeUnmapped , ip , clusterName ))
711+ s .Success (fmt .Sprintf ("auth address {%s} remapped to {%s} for remote cluster {%s}" , ipToBeRemapped , ip , clusterName ))
729712
730713 return nil
731714}
0 commit comments