Skip to content

[platform] Another logic for deleting components - #811

Merged
Andrei Kvapil (kvaps) merged 1 commit into
mainfrom
bundle-disable
Apr 14, 2025
Merged

Andrei Kvapil (kvaps) merged 1 commit into
mainfrom
bundle-disable

Conversation

@kvaps

@kvaps Andrei Kvapil (kvaps) commented Apr 14, 2025 •

Copy link
Copy Markdown
Member

Signed-off-by: Andrei Kvapil [email protected]

Summary by CodeRabbit

  • Refactor
    • Streamlined the internal deployment process by consolidating deletion operations and simplifying task dependencies.
  • New Features
    • Enhanced release management with updated logic that automatically determines whether to deploy or remove components based on their enabled status.

@coderabbitai

coderabbitai Bot commented Apr 14, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

This pull request removes and consolidates certain deletion targets within the Makefile and refines the HelmRelease template logic. In the Makefile, the delete target is removed, the apply target now directly deletes marked HelmReleases using kubectl delete, and the reconcile target is updated to depend solely on apply. In the HelmRelease template, new condition variables ($shouldInstall and $shouldDelete) are introduced to control YAML generation, adding a deletion label when needed.

Changes

File(s) Change Summary
packages/core/platform/Makefile Modified the apply target to directly delete HelmReleases marked for deletion; removed the delete target; updated reconcile to depend only on apply.
packages/core/.../helmreleases.yaml Introduced new conditional logic with $shouldInstall and $shouldDelete; added a deletion label when appropriate; removed previous disabled component logic.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Makefile
    participant Kubernetes
    User->>Makefile: Invoke 'reconcile' target
    Makefile->>Makefile: Execute 'apply' target
    Makefile->>Kubernetes: Run 'kubectl delete' for marked HelmReleases
Loading
sequenceDiagram
    participant TemplateEngine
    participant HelmTemplates
    participant Kubernetes
    TemplateEngine->>HelmTemplates: Evaluate $shouldInstall & $shouldDelete conditions
    alt $shouldDelete is true
        HelmTemplates->>Kubernetes: Render YAML with deletion label
    else $shouldInstall is true
        HelmTemplates->>Kubernetes: Render standard HelmRelease YAML
    end
Loading

Possibly related PRs

Suggested reviewers

  • lllamnyp

Poem

🐇 I hop through code with a cheerful gait,
Removing targets to simplify our state.
Conditional logic now leads the way,
Marking deletions with a label in play.
CodeRabbit cheers as our changes create a brighter day!
🥕 Happy coding in every hop and sway!

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@kvaps Andrei Kvapil (kvaps) added the ok-to-test Indicates a non-member PR is safe to run CI on label Apr 14, 2025

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
packages/core/platform/Makefile (2)

9-13: Consolidated deletion logic in the apply target.
The new line 12 now directly deletes HelmReleases tagged with cozystack.io/marked-for-deletion=true across all namespaces. This simplifies the workflow by eliminating the separate delete target. However, please verify that this deletion command does not inadvertently remove resources that should be retained.


16-24: Pipeline failure investigation needed.
The pipeline log shows an error related to a target named gen-versions-map (make: *** [Makefile:17: gen-versions-map] Error 128). Although this target is not present in the diff, please double-check if any dependencies on it remain (or in other parts of the Makefile) so that the CI process can pass.

🧰 Tools
🪛 GitHub Actions: Pre-Commit Checks

[error] 17-17: make: *** [Makefile:17: gen-versions-map] Error 128

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ccb001e and 05d6ab9.

📒 Files selected for processing (2)
  • packages/core/platform/Makefile (1 hunks)
  • packages/core/platform/templates/helmreleases.yaml (2 hunks)
🧰 Additional context used
🪛 YAMLlint (1.35.1)
packages/core/platform/templates/helmreleases.yaml

[warning] 18-18: wrong indentation: expected 0 but found 2

(indentation)


[warning] 19-19: wrong indentation: expected 0 but found 2

(indentation)


[warning] 20-20: wrong indentation: expected 0 but found 4

(indentation)


[warning] 21-21: wrong indentation: expected 0 but found 2

(indentation)

🪛 GitHub Actions: Pre-Commit Checks
packages/core/platform/Makefile

[error] 17-17: make: *** [Makefile:17: gen-versions-map] Error 128

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build and Test
🔇 Additional comments (2)
packages/core/platform/Makefile (1)

14-15: Updated reconcile target dependency.
The reconcile target now depends solely on apply, which is consistent with your consolidation effort. Ensure that any dependencies or workflows that previously relied on the removed delete target are updated accordingly.

packages/core/platform/templates/helmreleases.yaml (1)

24-36: Conditional YAML output for deletion label.
The conditional block (lines 24–36) correctly appends the deletion label when $shouldDelete is true. Double-check that the generated YAML reflects the intended metadata structure and that the label matches what the Makefile deletion command expects.

Comment on lines +14 to +22

{{- $shouldInstall := true }}
{{- $shouldDelete := false }}
{{- if or (has $x.name $disabledComponents) (and ($x.optional) (not (has $x.name $enabledComponents))) }}
{{- $shouldInstall = false }}
{{- if lookup "helm.toolkit.fluxcd.io/v2" "HelmRelease" $x.namespace $x.name }}
{{- $shouldDelete = true }}
{{- end }}
{{- end }}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

❓ Verification inconclusive

Review template logic and YAML indentation.
The new block initializing $shouldInstall and $shouldDelete and adjusting their values based on component status (lines 15–21) correctly implements the desired logic. However, YAML lint warnings indicate that lines 18–21 have inconsistent indentation (expected 0 but found extra spaces). Since these are Go template directives within a YAML file, consider unindenting these lines or aligning them with the surrounding template syntax to ensure YAML rendering and linting pass correctly. For instance:

-{{- $shouldInstall := true }}
-{{- $shouldDelete := false }}
-{{- if or (has $x.name $disabledComponents) (and ($x.optional) (not (has $x.name $enabledComponents))) }}
-  {{- $shouldInstall = false }}
-  {{- if lookup "helm.toolkit.fluxcd.io/v2" "HelmRelease" $x.namespace $x.name }}
-    {{- $shouldDelete = true }}
-  {{- end }}
-{{- end }}
+{{- $shouldInstall := true }}
+{{- $shouldDelete := false }}
+{{- if or (has $x.name $disabledComponents) (and ($x.optional) (not (has $x.name $enabledComponents))) }}
+{{-     $shouldInstall = false }}
+{{-     if lookup "helm.toolkit.fluxcd.io/v2" "HelmRelease" $x.namespace $x.name }}
+{{-         $shouldDelete = true }}
+{{-     end }}
+{{- end }}

Please adjust the indentation as needed for consistency in your templating context.


Action Required: Fix Indentation in YAML Template

Based on our review, the templating logic in the snippet is correct, but the YAML linter is flagging extra indentation in lines 18–21. Please adjust these lines so that the Go template directives are aligned consistently with the surrounding code. For example:

-{{- $shouldInstall := true }}
-{{- $shouldDelete := false }}
-{{- if or (has $x.name $disabledComponents) (and ($x.optional) (not (has $x.name $enabledComponents))) }}
-  {{- $shouldInstall = false }}
-  {{- if lookup "helm.toolkit.fluxcd.io/v2" "HelmRelease" $x.namespace $x.name }}
-    {{- $shouldDelete = true }}
-  {{- end }}
-{{- end }}
+{{- $shouldInstall := true }}
+{{- $shouldDelete := false }}
+{{- if or (has $x.name $disabledComponents) (and ($x.optional) (not (has $x.name $enabledComponents))) }}
+{{-     $shouldInstall = false }}
+{{-     if lookup "helm.toolkit.fluxcd.io/v2" "HelmRelease" $x.namespace $x.name }}
+{{-         $shouldDelete = true }}
+{{-     end }}
+{{- end }}

Please update the file at packages/core/platform/templates/helmreleases.yaml accordingly to resolve the YAML linting warnings.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{{- $shouldInstall := true }}
{{- $shouldDelete := false }}
{{- if or (has $x.name $disabledComponents) (and ($x.optional) (not (has $x.name $enabledComponents))) }}
{{- $shouldInstall = false }}
{{- if lookup "helm.toolkit.fluxcd.io/v2" "HelmRelease" $x.namespace $x.name }}
{{- $shouldDelete = true }}
{{- end }}
{{- end }}
{{- $shouldInstall := true }}
{{- $shouldDelete := false }}
{{- if or (has $x.name $disabledComponents) (and ($x.optional) (not (has $x.name $enabledComponents))) }}
{{- $shouldInstall = false }}
{{- if lookup "helm.toolkit.fluxcd.io/v2" "HelmRelease" $x.namespace $x.name }}
{{- $shouldDelete = true }}
{{- end }}
{{- end }}
🧰 Tools
🪛 YAMLlint (1.35.1)

[warning] 18-18: wrong indentation: expected 0 but found 2

(indentation)


[warning] 19-19: wrong indentation: expected 0 but found 2

(indentation)


[warning] 20-20: wrong indentation: expected 0 but found 4

(indentation)


[warning] 21-21: wrong indentation: expected 0 but found 2

(indentation)

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

Labels

ok-to-test Indicates a non-member PR is safe to run CI on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants