Skip to content

Conversation

@giuliafalaschi
Copy link

@giuliafalaschi giuliafalaschi commented Sep 11, 2025

Description

I created the ‘force unpeer --cluster-id ’ command, which allows you to force the unpeer command if one of the two clusters is no longer reachable. What this command actually does is set an annotation to the foreigncluster and delete the namespace-tenant of the one invoking the force. These additions will be taken over by the backend, which will perform the actual force unpeer.

Fixes #3051

@adamjensenbot
Copy link
Collaborator

Hi @giuliafalaschi. Thanks for your PR!

I am @adamjensenbot.
You can interact with me issuing a slash command in the first line of a comment.
Currently, I understand the following commands:

  • /rebase: Rebase this PR onto the master branch (You can add the option test=true to launch the tests
    when the rebase operation is completed)
  • /merge: Merge this PR into the master branch
  • /build Build Liqo components
  • /test Launch the E2E and Unit tests
  • /hold, /unhold Add/remove the hold label to prevent merging with /merge

Make sure this PR appears in the liqo changelog, adding one of the following labels:

  • feat: 🚀 New Feature
  • fix: 🐛 Bug Fix
  • refactor: 🧹 Code Refactoring
  • docs: 📝 Documentation
  • style: 💄 Code Style
  • perf: 🐎 Performance Improvement
  • test: ✅ Tests
  • chore: 🚚 Dependencies Management
  • build: 📦 Builds Management
  • ci: 👷 CI/CD
  • revert: ⏪ Reverts Previous Changes

@github-actions github-actions bot added the feat Adds a new feature to the codebase label Sep 11, 2025
Copy link
Contributor

@claudiolor claudiolor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @giuliafalaschi, thanks for this PR 💯
I added some issues that need to be addressed before merging :)

"github.com/liqotech/liqo/pkg/liqoctl/utils"
)

//TODO: sistemare le descrizioni che dovranno essere inserite nell'help della force
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//TODO: sistemare le descrizioni che dovranno essere inserite nell'help della force

},
}

cmd.PersistentFlags().StringVar(&options.ClusterId, "cluster-id", "", "Force unpeering only on the local cluster")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd make use the format:

liqoctl force unpeer <CLUSTER_ID>

as we for example fo with the liqoctl unoffload command.

Suggested change
cmd.PersistentFlags().StringVar(&options.ClusterId, "cluster-id", "", "Force unpeering only on the local cluster")

Use: "unpeer",
Short: "Force unpeer a cluster",
Long: liqoctUnpeerForceLongHelp,
ValidArgsFunction: completion.ClusterIDs(ctx, f, completion.NoLimit),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allow a single argument and provide suggest for just one argument:

Suggested change
ValidArgsFunction: completion.ClusterIDs(ctx, f, completion.NoLimit),
Args: cobra.ExactArgs(1),
ValidArgsFunction: completion.ClusterIDs(ctx, f, 1),

Long: liqoctUnpeerForceLongHelp,
ValidArgsFunction: completion.ClusterIDs(ctx, f, completion.NoLimit),

Run: func(_ *cobra.Command, _ []string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once we do not use the --cluster-id argument, then we need to pass it via args:

Suggested change
Run: func(_ *cobra.Command, _ []string) {
Run: func(_ *cobra.Command, args []string) {
options.ClusterId = args[0]

Comment on lines 8 to 9

export LIQOCTL="/home/gfalaschi/liqo-giufal/liqo/liqoctl"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export LIQOCTL="/home/gfalaschi/liqo-giufal/liqo/liqoctl"

// Options encapsulates the arguments of the info command.
type Options struct {
*factory.Factory
LocalFactory *factory.Factory
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to have LocalFactory, we can just use Factory

Suggested change
LocalFactory *factory.Factory

Additionally, as Factory is a promoted field, we can access its fields directly from options, e.g. (o.Printer instead of o.Factory.Printer)


func NewOptions(localFactory *factory.Factory) *Options {
return &Options{
LocalFactory: localFactory,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of above this becomes:

Suggested change
LocalFactory: localFactory,
Factory: localFactory,

"liqo.io/foreign-cluster-permanently-unreachable": "true",
})

err = o.LocalFactory.CRClient.Patch(ctx, fc, patch)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
err = o.LocalFactory.CRClient.Patch(ctx, fc, patch)
err = o.CRClient.Patch(ctx, fc, patch)

}

func newForceCommand(ctx context.Context, f *factory.Factory) *cobra.Command {
options := unpeer.NewOptions(f)
Copy link
Contributor

@claudiolor claudiolor Sep 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we should initialize options inside newUnpeerForceCommand and not here, so you don't need to pass it as parameter.

@claudiolor claudiolor changed the title Force unpeer command [Liqoctl] Force unpeer command Sep 12, 2025
@github-actions github-actions bot added the fix Fixes a bug in the codebase. label Sep 12, 2025
@github-actions github-actions bot removed the fix Fixes a bug in the codebase. label Sep 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat Adds a new feature to the codebase size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Force unpeering

3 participants