@@ -49,6 +49,9 @@ type Cluster struct {
4949 remote * factory.Factory
5050 waiter * wait.Waiter
5151
52+ localNetworkNamespace string
53+ remoteNetworkNamespace string
54+
5255 localNamespaceManager tenantnamespace.Manager
5356 remoteNamespaceManager tenantnamespace.Manager
5457
@@ -113,7 +116,10 @@ func (c *Cluster) SetNamespaces(ctx context.Context, createTenantNs bool) error
113116 }
114117 }
115118
116- if c .local .Namespace == "" || c .local .Namespace == corev1 .NamespaceDefault {
119+ switch c .local .Namespace {
120+ case "" , corev1 .NamespaceDefault :
121+ // If the local namespace is not set or it is the default one, create or retrieve the tenant namespace and
122+ // set it as the local network namespace.
117123 var localTenantNs * corev1.Namespace
118124
119125 if createTenantNs {
@@ -130,13 +136,16 @@ func (c *Cluster) SetNamespaces(ctx context.Context, createTenantNs bool) error
130136 }
131137 }
132138
133- // Set the local namespace to the tenant namespace.
134- c .local .Namespace = localTenantNs .Name
139+ c .localNetworkNamespace = localTenantNs .Name
140+ default :
141+ c .localNetworkNamespace = c .local .Namespace
135142 }
136143
137- if c .remote .Namespace == "" || c .remote .Namespace == corev1 .NamespaceDefault {
144+ switch c .remote .Namespace {
145+ case "" , corev1 .NamespaceDefault :
146+ // If the remote namespace is not set or it is the default one, create or retrieve the tenant namespace and
147+ // set it as the remote network namespace.
138148 var remoteTenantNs * corev1.Namespace
139-
140149 if createTenantNs {
141150 remoteTenantNs , err = c .remoteNamespaceManager .CreateNamespace (ctx , c .localClusterID )
142151 if err != nil {
@@ -151,7 +160,9 @@ func (c *Cluster) SetNamespaces(ctx context.Context, createTenantNs bool) error
151160 }
152161 }
153162
154- c .remote .Namespace = remoteTenantNs .Name
163+ c .remoteNetworkNamespace = remoteTenantNs .Name
164+ default :
165+ c .remoteNetworkNamespace = c .remote .Namespace
155166 }
156167
157168 return nil
@@ -161,7 +172,7 @@ func (c *Cluster) SetNamespaces(ctx context.Context, createTenantNs bool) error
161172func (c * Cluster ) SetLocalConfiguration (ctx context.Context ) error {
162173 // Get network configuration.
163174 s := c .local .Printer .StartSpinner ("Retrieving network configuration" )
164- conf , err := forge .ConfigurationForRemoteCluster (ctx , c .local .CRClient , c .local . Namespace , c .local .LiqoNamespace )
175+ conf , err := forge .ConfigurationForRemoteCluster (ctx , c .local .CRClient , c .localNetworkNamespace , c .local .LiqoNamespace )
165176 if err != nil {
166177 s .Fail (fmt .Sprintf ("An error occurred while retrieving network configuration: %v" , output .PrettyErr (err )))
167178 return err
@@ -175,7 +186,7 @@ func (c *Cluster) SetLocalConfiguration(ctx context.Context) error {
175186// SetupConfiguration sets up the network configuration.
176187func (c * Cluster ) SetupConfiguration (ctx context.Context , conf * networkingv1beta1.Configuration ) error {
177188 s := c .local .Printer .StartSpinner ("Setting up network configuration" )
178- conf .Namespace = c .local . Namespace
189+ conf .Namespace = c .localNetworkNamespace
179190 confCopy := conf .DeepCopy ()
180191 _ , err := resource .CreateOrUpdate (ctx , c .local .CRClient , conf , func () error {
181192 if conf .Labels == nil {
@@ -387,7 +398,7 @@ func (c *Cluster) EnsureGatewayServer(ctx context.Context, opts *forge.GwServerO
387398 }
388399
389400 // Forge GatewayServer.
390- gwServer , err = forge .GatewayServer (c .local . Namespace , name , opts )
401+ gwServer , err = forge .GatewayServer (c .localNetworkNamespace , name , opts )
391402 if err != nil {
392403 s .Fail (fmt .Sprintf ("An error occurred while forging gateway server: %v" , output .PrettyErr (err )))
393404 return nil , err
@@ -437,7 +448,7 @@ func (c *Cluster) EnsureGatewayClient(ctx context.Context, opts *forge.GwClientO
437448 name = & gwClient .Name // if the GatewayClient already exists, keep its name
438449 }
439450
440- gwClient , err = forge .GatewayClient (c .local . Namespace , name , opts )
451+ gwClient , err = forge .GatewayClient (c .localNetworkNamespace , name , opts )
441452 if err != nil {
442453 s .Fail (fmt .Sprintf ("An error occurred while forging gateway client: %v" , output .PrettyErr (err )))
443454 return nil , err
@@ -469,7 +480,7 @@ func (c *Cluster) EnsurePublicKey(ctx context.Context, remoteClusterID liqov1bet
469480 name = & pk .Name // if the PublicKey already exists, keep its name
470481 }
471482
472- pubKey , err := forge .PublicKey (c .local . Namespace , name , remoteClusterID , key )
483+ pubKey , err := forge .PublicKey (c .localNetworkNamespace , name , remoteClusterID , key )
473484 if err != nil {
474485 s .Fail (fmt .Sprintf ("An error occurred while forging public key: %v" , output .PrettyErr (err )))
475486 return err
0 commit comments