Skip to content

Commit

Permalink
Fix liqoctl disconnect on bidirectional
Browse files Browse the repository at this point in the history
  • Loading branch information
fra98 authored and adamjensenbot committed Oct 3, 2024
1 parent 3b9f887 commit 20d9d8f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 27 deletions.
2 changes: 1 addition & 1 deletion cmd/liqoctl/cmd/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func newNetworkDisconnectCommand(ctx context.Context, options *network.Options)
},

Run: func(_ *cobra.Command, _ []string) {
output.ExitOnErr(options.RunDisconnect(ctx))
output.ExitOnErr(options.RunDisconnect(ctx, nil, nil))
},
}

Expand Down
54 changes: 28 additions & 26 deletions pkg/liqoctl/network/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,23 +134,8 @@ func (o *Options) RunReset(ctx context.Context) error {
return err
}

// Delete gateway client on cluster 1
if err := cluster1.DeleteGatewayClient(ctx, forge.DefaultGatewayClientName(cluster2.localClusterID)); err != nil {
return err
}

// Delete gateway client on cluster 2
if err := cluster2.DeleteGatewayClient(ctx, forge.DefaultGatewayClientName(cluster1.localClusterID)); err != nil {
return err
}

// Delete gateway server on cluster 1
if err := cluster1.DeleteGatewayServer(ctx, forge.DefaultGatewayServerName(cluster2.localClusterID)); err != nil {
return err
}

// Delete gateway server on cluster 2
if err := cluster2.DeleteGatewayServer(ctx, forge.DefaultGatewayServerName(cluster1.localClusterID)); err != nil {
// Run disconnect command to remove gateways.
if err := o.RunDisconnect(ctx, cluster1, cluster2); err != nil {
return err
}

Expand Down Expand Up @@ -294,27 +279,44 @@ func (o *Options) RunConnect(ctx context.Context) error {
}

// RunDisconnect disconnects two clusters.
func (o *Options) RunDisconnect(ctx context.Context) error {
// It deletes the gateways (if present) on both clusters.
// Cluster1 and Cluster2 are optional, if not provided they will be created and initialized.
func (o *Options) RunDisconnect(ctx context.Context, cluster1, cluster2 *Cluster) error {
var err error
ctx, cancel := context.WithTimeout(ctx, o.Timeout)
defer cancel()

// Create and initialize cluster 1.
cluster1, err := NewCluster(ctx, o.LocalFactory, o.RemoteFactory, false)
if err != nil {
return err
if cluster1 == nil {
// Create and initialize cluster 1.
cluster1, err = NewCluster(ctx, o.LocalFactory, o.RemoteFactory, false)
if err != nil {
return err
}
}

// Create and initialize cluster 2.
cluster2, err := NewCluster(ctx, o.RemoteFactory, o.LocalFactory, false)
if err != nil {
return err
if cluster2 == nil {
// Create and initialize cluster 2.
cluster2, err = NewCluster(ctx, o.RemoteFactory, o.LocalFactory, false)
if err != nil {
return err
}
}

// Delete gateway client on cluster 1
if err := cluster1.DeleteGatewayClient(ctx, forge.DefaultGatewayClientName(cluster2.localClusterID)); err != nil {
return err
}

// Delete gateway client on cluster 2
if err := cluster2.DeleteGatewayClient(ctx, forge.DefaultGatewayClientName(cluster1.localClusterID)); err != nil {
return err
}

// Delete gateway server on cluster 1
if err := cluster1.DeleteGatewayServer(ctx, forge.DefaultGatewayServerName(cluster2.localClusterID)); err != nil {
return err
}

// Delete gateway server on cluster 2
return cluster2.DeleteGatewayServer(ctx, forge.DefaultGatewayServerName(cluster1.localClusterID))
}
Expand Down

0 comments on commit 20d9d8f

Please sign in to comment.