Skip to content

support to delete pipelinerun#1069

Open
renyunkang wants to merge 1 commit intokubesphere:masterfrom
renyunkang:master
Open

support to delete pipelinerun#1069
renyunkang wants to merge 1 commit intokubesphere:masterfrom
renyunkang:master

Conversation

@renyunkang
Copy link
Member

What type of PR is this?

/kind feature

What this PR does / why we need it:

Which issue(s) this PR fixes:

Fixes # https://github.com/kubesphere/project/issues/7185

Special notes for reviewers:

Please check the following list before waiting reviewers:

  • Already committed the CRD files to the Helm Chart if you created some new CRDs
  • Already added the permission for the new API
  • Already added the RBAC markers for the new controllers

Does this PR introduce a user-facing change??

none

@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces the capability to delete PipelineRun resources, providing a new API endpoint for this operation. It includes robust logic to prevent accidental deletion of active pipeline runs and offers flexibility to retain associated Jenkins build records if desired. The changes ensure proper resource lifecycle management and cleanup within the system.

Highlights

  • PipelineRun Deletion API: Introduced a new API endpoint to allow for the deletion of PipelineRun resources.
  • Safe Deletion Logic: Implemented checks to prevent the deletion of PipelineRuns that are still in a running state, ensuring operational stability.
  • Jenkins Record Retention: Added an option, controlled by an annotation, to specify whether the corresponding Jenkins build record should be kept or deleted when a PipelineRun is removed.
  • Finalizer Management: Enhanced the PipelineRun controller to properly manage finalizers, ensuring that cleanup operations, such as deleting Jenkins job history, are performed before the PipelineRun object is fully removed from Kubernetes.
Changelog
  • controllers/jenkins/pipelinerun/pipelinerun_controller.go
    • Imported strconv and sliceutil packages.
    • Modified the Reconcile function to handle PipelineRun deletion, incorporating logic to check for a keepJenkinsRecord annotation and conditionally delete Jenkins job history.
    • Updated finalizer management to ensure the PipelineRunFinalizerName is added if missing and removed upon deletion.
  • pkg/api/devops/v1alpha3/pipelinerun_types.go
    • Added a new constant PipelineRunKeepJenkinsRecordAnnoKey to define the annotation key for retaining Jenkins records.
  • pkg/kapis/devops/v1alpha3/pipelinerun/handler.go
    • Imported the net/http package.
    • Implemented the deletePipelineRun handler function, which retrieves a PipelineRun, checks its status to ensure it's not running, applies the keepJenkinsRecord annotation if specified, and then deletes the PipelineRun resource.
  • pkg/kapis/devops/v1alpha3/pipelinerun/register.go
    • Registered a new DELETE route for /namespaces/{namespace}/pipelineruns/{pipelinerun} to expose the deletePipelineRun API endpoint.
Activity
  • The pull request is categorized as a new feature (/kind feature).
  • It addresses and fixes issue #7185.
  • The author has provided a checklist for reviewers to verify CRD files, permissions, and RBAC markers.
  • The release note for this change is explicitly marked as 'none'.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@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 adds support for deleting PipelineRun resources. The implementation includes a new API endpoint for deletion, with an option to keep the corresponding Jenkins job history. The controller logic is updated with a finalizer to handle the cleanup of Jenkins resources upon PipelineRun deletion. The changes are well-structured and the logic is sound. I have a couple of suggestions to improve the robustness of the controller's update operations.

pipelineRunCopied.ObjectMeta.Finalizers = sliceutil.RemoveString(pipelineRunCopied.ObjectMeta.Finalizers, func(item string) bool {
return item == v1alpha3.PipelineRunFinalizerName
})
err = r.Update(context.TODO(), pipelineRunCopied)

Choose a reason for hiding this comment

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

medium

This update to remove the finalizer should be wrapped in a retry.RetryOnConflict loop to handle potential conflicts gracefully. This is a standard pattern in controllers to avoid reconciliation failures due to object modifications between read and write operations. You can see an example of this pattern in the updateStatus function in this file.

Additionally, please use the ctx from the Reconcile function instead of context.TODO().

// add finalizer if it does not exist
if !sliceutil.HasString(pipelineRunCopied.ObjectMeta.Finalizers, v1alpha3.PipelineRunFinalizerName) {
pipelineRunCopied.ObjectMeta.Finalizers = append(pipelineRunCopied.ObjectMeta.Finalizers, v1alpha3.PipelineRunFinalizerName)
if err := r.Update(ctx, pipelineRunCopied); err != nil {

Choose a reason for hiding this comment

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

medium

This update to add the finalizer should be wrapped in a retry.RetryOnConflict loop to handle potential conflicts gracefully. This is a standard pattern in controllers to avoid reconciliation failures due to object modifications between read and write operations. You can see an example of this pattern in the updateStatus function in this file.

Signed-off-by: renyunkang <rykren1998@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant