Skip to content

optimize the deletion order in the unpublish <extension> command.#123

Merged
ks-ci-bot merged 1 commit into
masterfrom
feat/deletionOrder
May 9, 2026
Merged

optimize the deletion order in the unpublish <extension> command.#123
ks-ci-bot merged 1 commit into
masterfrom
feat/deletionOrder

Conversation

@frezes
Copy link
Copy Markdown
Member

@frezes frezes commented May 8, 2026

What this PR does / why we need it:

In versions below KSE v4.2.1, the controller queries the corresponding ExtensionVersion before deleting the InstallPlan. If the ExtensionVersion has already been deleted, the InstallPlan deletion will be blocked and cannot be cleaned up properly. Therefore, the deletion order needs to be optimized.

Does this PR introduced a user-facing change?

optimize the deletion order in the unpublish <extension> command.

@kubesphere-prow kubesphere-prow Bot added release-note size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 8, 2026
@frezes frezes force-pushed the feat/deletionOrder branch from ecca8b0 to df557a0 Compare May 8, 2026 08:02
@frezes frezes requested a review from redscholar May 8, 2026 08:03
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the unpublish command to handle the deletion of InstallPlan objects synchronously by waiting for their removal. It also refactors the code to pass a context through deletion functions. Feedback includes using the command's context for better interrupt handling, utilizing idiomatic helper functions for object keys, and optimizing the polling loop by moving object cloning outside of it.

Comment thread cmd/unpublish.go
}

func (o *unpublishOptions) unpublish(cmd *cobra.Command, args []string) error {
ctx := context.Background()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

It is recommended to use cmd.Context() instead of context.Background(). This allows the command to respect context cancellation, such as when a user interrupts the process (e.g., via Ctrl+C), ensuring a more responsive CLI experience.

Suggested change
ctx := context.Background()
ctx := cmd.Context()

Comment thread cmd/unpublish.go Outdated
Comment thread cmd/unpublish.go
Comment on lines +117 to +129
return wait.PollUntilContextTimeout(ctx, interval, timeout, true, func(ctx context.Context) (bool, error) {
current, ok := obj.DeepCopyObject().(runtimeclient.Object)
if !ok {
return false, fmt.Errorf("object %T does not implement client.Object", obj)
}
if err := c.Get(ctx, key, current); err != nil {
if errors.IsNotFound(err) {
return true, nil
}
return false, err
}
return false, nil
})
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The object cloning and type assertion are performed inside the polling loop. Moving these operations outside the loop improves efficiency by avoiding redundant allocations and checks in every iteration.

Suggested change
return wait.PollUntilContextTimeout(ctx, interval, timeout, true, func(ctx context.Context) (bool, error) {
current, ok := obj.DeepCopyObject().(runtimeclient.Object)
if !ok {
return false, fmt.Errorf("object %T does not implement client.Object", obj)
}
if err := c.Get(ctx, key, current); err != nil {
if errors.IsNotFound(err) {
return true, nil
}
return false, err
}
return false, nil
})
current, ok := obj.DeepCopyObject().(runtimeclient.Object)
if !ok {
return fmt.Errorf("object %T does not implement client.Object", obj)
}
return wait.PollUntilContextTimeout(ctx, interval, timeout, true, func(ctx context.Context) (bool, error) {
if err := c.Get(ctx, key, current); err != nil {
if errors.IsNotFound(err) {
return true, nil
}
return false, err
}
return false, nil
})

@frezes frezes force-pushed the feat/deletionOrder branch from df557a0 to e19d024 Compare May 8, 2026 08:10
Signed-off-by: frezes <zhangjunhao@kubesphere.io>
@frezes frezes force-pushed the feat/deletionOrder branch from e19d024 to 9d3b02b Compare May 8, 2026 08:12
@redscholar
Copy link
Copy Markdown
Collaborator

/lgtm
/approve

@kubesphere-prow kubesphere-prow Bot added the lgtm Indicates that a PR is ready to be merged. label May 9, 2026
@kubesphere-prow
Copy link
Copy Markdown

LGTM label has been added.

DetailsGit tree hash: 26eef6816c7b70bbc9ed54d896ee25e79bc1a7fb

@kubesphere-prow
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: frezes, redscholar

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubesphere-prow kubesphere-prow Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 9, 2026
@ks-ci-bot ks-ci-bot merged commit efb0f9c into master May 9, 2026
3 checks passed
@frezes
Copy link
Copy Markdown
Member Author

frezes commented May 9, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. release-note size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants