Skip to content

Conversation

@brandtkeller
Copy link
Member

Description

Adds support for a zarf package prune command. This allows for the explicit removal of a component chart by name OR it can look for all pending/orphaned resources and provide a list. Requires confirmation.

Related Issue

Fixes #2992

Checklist before merging

@netlify
Copy link

netlify bot commented Sep 26, 2025

Deploy Preview for zarf-docs canceled.

Name Link
🔨 Latest commit 4530168
🔍 Latest deploy log https://app.netlify.com/projects/zarf-docs/deploys/68f91dd9a604030007be48ef

@codecov
Copy link

codecov bot commented Sep 26, 2025

Codecov Report

❌ Patch coverage is 38.46154% with 112 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/cmd/package.go 21.35% 81 Missing ⚠️
src/pkg/packager/prune.go 0.00% 16 Missing ⚠️
src/pkg/packager/deploy.go 0.00% 15 Missing ⚠️
Files with missing lines Coverage Δ
src/pkg/state/state.go 42.96% <100.00%> (+12.33%) ⬆️
src/pkg/packager/deploy.go 0.00% <0.00%> (ø)
src/pkg/packager/prune.go 0.00% <0.00%> (ø)
src/cmd/package.go 39.03% <21.35%> (-1.50%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@brandtkeller brandtkeller changed the title 2992 chart prune feat(prune): add support for removing charts not tracked in state Oct 16, 2025
@brandtkeller brandtkeller marked this pull request as ready for review October 17, 2025 17:26
@brandtkeller brandtkeller requested review from a team as code owners October 17, 2025 17:26
Copy link
Member

@AustinAbro321 AustinAbro321 left a comment

Choose a reason for hiding this comment

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

Main comment is around prune when entire components are removed. Great start, I think this will be a nice value add

// GetPruneableCharts returns a map of component names to lists of charts that can be pruned,
// filtered by the provided component and chart names. If componentFilter is empty, all components
// are searched. If chartFilter is empty, all charts are searched.
func (d *DeployedPackage) GetPruneableCharts(componentFilter, chartFilter string) (map[string][]InstalledChart, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Charts are set to orphaned only work when a chart is removed from a component, but not when a component is removed entirely. I believe this could confuse some users. This could also encourage users to add all their charts to a single component so they can use prune in the future if need be.

Copy link
Member Author

Choose a reason for hiding this comment

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

Could you elaborate more? is this a concern or a required change?

Charts should only be able to be orphaned during deploys. Removes should remove all charts - active or orphaned. I do see room for confusion among the two commands but less of a distinct path forward.

Copy link
Member

Choose a reason for hiding this comment

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

Ah there's a misunderstanding. I mean when a component is removed from one package to another, rather than it being removed with zarf package remove.

For example, if we started with components like so

components:
  - name: test-component
    required: true
    charts:
      - name: chart-to-keep
        version: 1.0.0
        namespace: prune-test
        localPath: chart-to-keep
  - name: test-component-2
    charts:
      - name: chart-to-remove
        version: 1.0.0
        namespace: prune-test
        localPath: chart-to-remove

then in the next version of the package removed test-component-2. Functionally, I think as a user I'd expect prune to behave the same in both situations, but currently it will only track the chart if it was originally in a component that still exists. In my experience, more often than not a component has a single chart.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah interesting - correct me if I understood wrong - not only does Zarf orphan InstalledCharts from state - it also orphans components from state as well?

Copy link
Member

Choose a reason for hiding this comment

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

Yea, when Zarf records a package deployment it overwrites the existing secret and only the components that were in the latest deployment are added to state.

@brandtkeller brandtkeller moved this to PR Review in Zarf Oct 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: PR Review

Development

Successfully merging this pull request may close these issues.

Feature request: Support --prune feature when execute zarf package deploy to delete needless helm chart or manifest

3 participants