Skip to content

OCPBUGS-85713: set WorkingDir from --delete-yaml-file path - #1500

Open
shishind wants to merge 1 commit into
openshift:mainfrom
shishind:OCPBUGS-85713-delete-workingdir
Open

OCPBUGS-85713: set WorkingDir from --delete-yaml-file path#1500
shishind wants to merge 1 commit into
openshift:mainfrom
shishind:OCPBUGS-85713-delete-workingdir

Conversation

@shishind

@shishind shishind commented Aug 13, 2026

Copy link
Copy Markdown

Summary

  • When running oc-mirror delete --delete-yaml-file (without --generate), derive WorkingDir from the YAML path (…/working-dir/delete/delete-images*.yaml).
  • Prevents mkdir logs: permission denied when the process CWD is not writable (e.g. container with read-only root).
  • Adds unit coverage for path derivation and CompleteDelete.

Fixes https://issues.redhat.com/browse/OCPBUGS-85713

Test plan

  • CGO_ENABLED=0 go test -tags "json1 exclude_graphdriver_devicemapper exclude_graphdriver_btrfs containers_image_openpgp" ./internal/pkg/cli/ -run 'TestWorkingDirFromDeleteYaml|TestExecutorCompleteDelete|TestExecutorValidateDelete' -v
  • Manually run delete phase 2 with --delete-yaml-file …/working-dir/delete/delete-images.yaml from a non-writable CWD and confirm logs land under working-dir/logs

Summary by CodeRabbit

  • New Features

    • Delete operations can now determine the workspace automatically from the specified delete YAML file when no workspace is provided.
    • Supports delete YAML files in standard locations and delete subdirectories.
  • Bug Fixes

    • Improved delete execution by automatically deriving required workspace and log directories.
    • Added validation for delete YAML paths and automatic directory creation where needed.

Derive WorkingDir from the delete YAML location so logs use an
absolute writable path when --generate is not used.

Co-authored-by: Cursor <cursoragent@cursor.com>
@openshift-merge-bot

Copy link
Copy Markdown
Contributor

Pipeline controller notification
This repo is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.

For optional jobs, comment /test ? to see a list of all defined jobs. To trigger manually all jobs from second stage use /pipeline required command.

This repository is configured in: LGTM mode

@openshift-ci-robot openshift-ci-robot added jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. jira/invalid-bug Indicates that a referenced Jira bug is invalid for the branch this PR is targeting. labels Aug 13, 2026
@openshift-ci-robot

Copy link
Copy Markdown

@shishind: This pull request references Jira Issue OCPBUGS-85713, which is invalid:

  • expected the bug to target the "5.0.0" version, but no target version was set

Comment /jira refresh to re-evaluate validity if changes to the Jira bug are made, or edit the title of this pull request to link to a different bug.

The bug has been updated to refer to the pull request using the external bug tracker.

Details

In response to this:

Summary

  • When running oc-mirror delete --delete-yaml-file (without --generate), derive WorkingDir from the YAML path (…/working-dir/delete/delete-images*.yaml).
  • Prevents mkdir logs: permission denied when the process CWD is not writable (e.g. container with read-only root).
  • Adds unit coverage for path derivation and CompleteDelete.

Fixes https://issues.redhat.com/browse/OCPBUGS-85713

Test plan

  • CGO_ENABLED=0 go test -tags "json1 exclude_graphdriver_devicemapper exclude_graphdriver_btrfs containers_image_openpgp" ./internal/pkg/cli/ -run 'TestWorkingDirFromDeleteYaml|TestExecutorCompleteDelete|TestExecutorValidateDelete' -v
  • Manually run delete phase 2 with --delete-yaml-file …/working-dir/delete/delete-images.yaml from a non-writable CWD and confirm logs land under working-dir/logs

Made with Cursor

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@shishind

Copy link
Copy Markdown
Author

/jira refresh

@openshift-ci-robot openshift-ci-robot added the jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. label Aug 13, 2026
@coderabbitai

coderabbitai Bot commented Aug 13, 2026

Copy link
Copy Markdown

Walkthrough

The delete CLI now derives WorkingDir from --delete-yaml-file when no workspace is provided. It validates YAML paths, handles standard and delete-ID paths, creates the log directory, and completes delete execution.

Changes

Delete working directory resolution

Layer / File(s) Summary
Working directory resolution
internal/pkg/cli/delete.go
The CLI validates delete YAML paths, derives workspaces from paths under delete, uses parent directories for custom paths, and applies the result to non-generate delete operations.
Resolution and execution tests
internal/pkg/cli/delete_test.go
Tests cover standard paths, delete-ID filenames, empty-path errors, workspace and log-directory derivation, log-directory creation, and successful completion.

Estimated code review effort: 2 (Simple) | ~10 minutes

Mergeability Score: 🟡 Moderate · up to 2d9a0

The change can place logs in the wrong directory when a custom delete YAML resides under a directory named delete, so the PR should not merge until generated and custom paths are distinguished.

🚥 Pre-merge checks | ✅ 14 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Test Structure And Quality ⚠️ Warning The added tests use assert.NoError/assert.Equal without meaningful failure messages at delete_test.go:185-231, violating the explicit assertion-message requirement. Add diagnostic messages to each new filesystem, CompleteDelete, log-directory, and path-derivation assertion.
✅ Passed checks (14 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Stable And Deterministic Test Names ✅ Passed The changed tests use Go t.Run, not Ginkgo, and all added titles are static literals; dynamic t.TempDir values appear only in test bodies.
Microshift Test Compatibility ✅ Passed The PR adds Go unit tests with testing.T, not Ginkgo e2e tests; they reference only local filesystem and CLI logic, with no MicroShift-unavailable APIs or features.
Single Node Openshift (Sno) Test Compatibility ✅ Passed The PR adds only standard Go unit tests in internal/pkg/cli/delete_test.go; no new Ginkgo e2e tests or multi-node/HA assumptions are present.
Topology-Aware Scheduling Compatibility ✅ Passed The commit changes only internal/pkg/cli/delete.go and its tests; it adds filesystem path handling and logging setup, with no manifests, controllers, replicas, affinity, selectors, tolerations, or...
Ote Binary Stdout Contract ✅ Passed The PR changes only internal/pkg/cli/delete.go and tests; added code has no stdout writes, and no main or OTE suite entrypoint changed.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed The commit changes only delete.go and Go testing.T/t.Run unit tests; no new Ginkgo e2e tests, IPv4 literals, or external network access were added.
No-Weak-Crypto ✅ Passed The PR adds path resolution and tests only; the added diff introduces no MD5, SHA1, DES, RC4, 3DES, Blowfish, ECB, custom crypto, or secret comparisons.
Container-Privileges ✅ Passed The PR changes only two Go files. The diff adds no container/Kubernetes manifests or privilege settings such as privileged, hostPID, hostNetwork, hostIPC, SYS_ADMIN, or allowPrivilegeEscalation.
No-Sensitive-Data-In-Logs ✅ Passed The diff adds path resolution and tests only; it adds no logging calls or sensitive-data formatting. Existing config and image logging is unchanged.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes deriving WorkingDir from the --delete-yaml-file path.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands.

@openshift-ci-robot openshift-ci-robot removed the jira/invalid-bug Indicates that a referenced Jira bug is invalid for the branch this PR is targeting. label Aug 13, 2026
@openshift-ci-robot

Copy link
Copy Markdown

@shishind: This pull request references Jira Issue OCPBUGS-85713, which is valid. The bug has been moved to the POST state.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target version (5.0.0) matches configured target version for branch (5.0.0)
  • bug is in the state New, which is one of the valid states (NEW, ASSIGNED, POST)
Details

In response to this:

/jira refresh

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci
openshift-ci Bot requested review from adolfo-ab and aguidirh August 13, 2026 00:14
@openshift-ci openshift-ci Bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Aug 13, 2026
@openshift-ci

openshift-ci Bot commented Aug 13, 2026

Copy link
Copy Markdown

Hi @shishind. Thanks for your PR.

I'm waiting for a openshift member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@openshift-ci

openshift-ci Bot commented Aug 13, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: shishind
Once this PR has been reviewed and has the lgtm label, please assign adolfo-ab for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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

@openshift-ci-robot

Copy link
Copy Markdown

@shishind: This pull request references Jira Issue OCPBUGS-85713, which is valid.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target version (5.0.0) matches configured target version for branch (5.0.0)
  • bug is in the state POST, which is one of the valid states (NEW, ASSIGNED, POST)
Details

In response to this:

Summary

  • When running oc-mirror delete --delete-yaml-file (without --generate), derive WorkingDir from the YAML path (…/working-dir/delete/delete-images*.yaml).
  • Prevents mkdir logs: permission denied when the process CWD is not writable (e.g. container with read-only root).
  • Adds unit coverage for path derivation and CompleteDelete.

Fixes https://issues.redhat.com/browse/OCPBUGS-85713

Test plan

  • CGO_ENABLED=0 go test -tags "json1 exclude_graphdriver_devicemapper exclude_graphdriver_btrfs containers_image_openpgp" ./internal/pkg/cli/ -run 'TestWorkingDirFromDeleteYaml|TestExecutorCompleteDelete|TestExecutorValidateDelete' -v
  • Manually run delete phase 2 with --delete-yaml-file …/working-dir/delete/delete-images.yaml from a non-writable CWD and confirm logs land under working-dir/logs

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/pkg/cli/delete.go`:
- Around line 58-62: Update the helper containing the filepath.Base(dir) ==
deleteSubDir check to strip the delete directory only when its parent is the
generated workingDir; preserve the full directory for custom paths such as
/custom/delete/remove.yaml. Add a regression test covering a custom YAML path
inside a delete-named directory and verify setupLogsLevelAndDir uses that
directory for logs.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: d6a5e711-94b2-417a-8a3d-ea107c0e1e31

📥 Commits

Reviewing files that changed from the base of the PR and between 315323f and 2d9a042.

📒 Files selected for processing (2)
  • internal/pkg/cli/delete.go
  • internal/pkg/cli/delete_test.go

Comment on lines +58 to +62
if filepath.Base(dir) == deleteSubDir {
return filepath.Dir(dir), nil
}
// Custom paths still need an absolute parent for logs.
return dir, 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.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Distinguish generated paths from custom paths.

Line 58 treats every YAML file in a directory named delete as a generated delete file. For /custom/delete/remove.yaml, the helper returns /custom, but custom-path behavior requires /custom/delete. setupLogsLevelAndDir then creates logs in the wrong directory.

Only strip delete when its parent is the generated workingDir directory. Add a regression test for a custom YAML path in a directory named delete.

Proposed fix
 	dir := filepath.Dir(absPath)
-	if filepath.Base(dir) == deleteSubDir {
-		return filepath.Dir(dir), nil
+	parentDir := filepath.Dir(dir)
+	if filepath.Base(dir) == deleteSubDir && filepath.Base(parentDir) == workingDir {
+		return parentDir, nil
 	}
📝 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
if filepath.Base(dir) == deleteSubDir {
return filepath.Dir(dir), nil
}
// Custom paths still need an absolute parent for logs.
return dir, nil
parentDir := filepath.Dir(dir)
if filepath.Base(dir) == deleteSubDir && filepath.Base(parentDir) == workingDir {
return parentDir, nil
}
// Custom paths still need an absolute parent for logs.
return dir, nil
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/pkg/cli/delete.go` around lines 58 - 62, Update the helper
containing the filepath.Base(dir) == deleteSubDir check to strip the delete
directory only when its parent is the generated workingDir; preserve the full
directory for custom paths such as /custom/delete/remove.yaml. Add a regression
test covering a custom YAML path inside a delete-named directory and verify
setupLogsLevelAndDir uses that directory for logs.

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

Labels

jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants