Skip to content

Add opt-in cleanup for persistent volumes - #248

Open
David Negstad (danegsta) wants to merge 1 commit into
mainfrom
danegsta-volume-cleanup-support
Open

Add opt-in cleanup for persistent volumes#248
David Negstad (danegsta) wants to merge 1 commit into
mainfrom
danegsta-volume-cleanup-support

Conversation

@danegsta

Copy link
Copy Markdown
Member

Persistent volumes currently outlive workload cleanup with no supported way to remove the volumes DCP created. This adds an explicit dcp cleanup --volumes <workload-id> option while preserving volumes by default.

The change records newly created persistent volumes in the state store with their workload and runtime, then includes those records in dependency-ordered cleanup after containers have been removed. Existing volumes that DCP adopts are deliberately not recorded or removed. Volume reconciliation and cleanup coordinate through resource leases, and removal avoids force mode so Podman cannot delete unrelated containers using a volume.

The state-store addition is an additive major-version-1 minor migration with interrupted-migration recovery coverage. Cleanup reporting now includes volume counts and failures.

Validation:

  • make lint
  • make test

Track DCP-created persistent volumes by workload and remove them only when cleanup is invoked with --volumes. Preserve adopted volumes and coordinate creation and cleanup through resource leases.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 94a89aca-02b4-4c6e-8220-0de0ec26ccae

CopilotAI 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.

Pull request overview

Adds opt-in cleanup for DCP-created persistent volumes while preserving adopted volumes by default.

Changes:

  • Records newly created persistent volumes in the state store.
  • Adds dcp cleanup --volumes with dependency-ordered removal and reporting.
  • Adds migration, controller, cleanup, and integration coverage.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.

Show a summary per file
FileDescription
README.mdDocuments workload tracking and volume cleanup.
api/v1/container_types_test.goTests volume lease keys.
api/v1/container_volume_types.goAdds volume lease-key generation.
controllers/volume_controller.goAdds leasing and persistent-volume recording.
internal/commands/workload.goUpdates workload-ID help text.
internal/containers/volume_orchestrator.goExposes runtime names for volume records.
internal/dcp/commands/cleanup.goImplements opt-in volume cleanup.
internal/dcp/commands/cleanup_test.goTests cleanup flags, ordering, and removal.
internal/dcpctrl/commands/run_controllers.goConfigures volume persistence tracking.
internal/statestore/migrations/000001_initial/000002_persistent_volumes.up.sqlAdds the persistent-volume table.
internal/statestore/persistent_volumes.goImplements volume record persistence.
internal/statestore/schema.goRegisters schema version 1.2.
internal/statestore/store_test.goTests migration recovery and volume records.
test/integration/advanced_test_env.goConfigures volume reconciler dependencies.
test/integration/standard_test_env.goPasses workload configuration to volume reconciliation.
test/integration/volume_controller_test.goTests recording and adopted-volume preservation.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +266 to +270
if persistErr := r.upsertPersistentVolumeRecord(ctx, vol, inspectedVolume, log); persistErr != nil {
removeErr := removeVolume(context.WithoutCancel(ctx), r.orchestrator, vol.Spec.Name)
persistErr = errors.Join(persistErr, removeErr)
log.Error(persistErr, "Could not persist ContainerVolume workload record", "ResourceKey", vol.GetLeaseKey())
return setContainerVolumeState(vol, apiv1.ContainerVolumeStatePending) | additionalReconciliationNeeded
Comment on lines +760 to +770
_, initialInspectErr := orchestrator.InspectVolumes(ctx, containers.InspectVolumesOptions{Volumes: []string{volumeName}})
if errors.Is(initialInspectErr, containers.ErrNotFound) {
return nil
}
if initialInspectErr != nil {
return initialInspectErr
}

_, removeErr := orchestrator.RemoveVolumes(ctx, containers.RemoveVolumesOptions{
Volumes: []string{volumeName},
})
Sign up for freeto 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.

2 participants

@danegsta