Skip to content

Fixed controller logic due to clarifications - #8

Merged
valeryia-hurynovich merged 1 commit into
masterfrom
fix-cloud-profile-gc-logic
Mar 31, 2026
Merged

valeryia-hurynovich merged 1 commit into
masterfrom
fix-cloud-profile-gc-logic

Conversation

@valeryia-hurynovich

@valeryia-hurynovich valeryia-hurynovich commented Mar 31, 2026

Copy link
Copy Markdown
Collaborator

It was clarified, that we don't need to have GC under each MachineImageUpdate, so made changes to fix controller and tests according to the updates

Summary by CodeRabbit

  • Refactor
    • Garbage collection configuration is now centralized at the profile level instead of being defined per machine image, streamlining configuration management.

@coderabbitai

coderabbitai Bot commented Mar 31, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This PR refactors garbage collection configuration in ManagedCloudProfile from per-machine-image settings to a centralized, global configuration at the spec level, simplifying the API and controller validation logic.

Changes

Cohort / File(s) Summary
API Structure
api/v1alpha1/managedcloudprofile.go
Moved GarbageCollection field from MachineImageUpdate to ManagedCloudProfileSpec, centralizing configuration from per-image to global spec level.
Generated DeepCopy Logic
api/v1alpha1/zz_generated.deepcopy.go
Updated auto-generated deepcopy methods: removed GarbageCollection deep-copy from MachineImageUpdate.DeepCopyInto, added it to ManagedCloudProfileSpec.DeepCopyInto.
Controller Reconciliation
controllers/managedcloudprofile_controller.go
Refactored reconcileGarbageCollection to validate global config once upfront, exit early if disabled, and remove per-image GC checks; loop now directly creates OCI source and uses global cutoff.
Test Configuration
controllers/managedcloudprofile_controller_test.go
Updated test cases to set GarbageCollection at mcp.Spec.GarbageCollection instead of per-MachineImageUpdate, applying consistent changes across GC deletion, preservation, and error-handling scenarios.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • fwiesel
  • defo89
  • Nuckal777

Poem

🐰 Garbage tales once scattered wide,
Per-image configs, far and far denied,
Now gathered at the spec's warm nest,
One global truth, the cleanest test!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'Fixed controller logic due to clarifications' is vague and does not clearly summarize the main change. Consider a more specific title that describes the actual change, such as 'Move garbage collection config from MachineImageUpdate to ManagedCloudProfileSpec' or 'Refactor GC configuration to use global spec-level setting'.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-cloud-profile-gc-logic

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 and usage tips.

@github-actions

Copy link
Copy Markdown

Merging this branch will decrease overall coverage

Impacted Packages Coverage Δ 🤖
github.com/cobaltcore-dev/cloud-profile-sync/api/v1alpha1 47.24% (ø)
github.com/cobaltcore-dev/cloud-profile-sync/controllers 69.94% (-3.20%) 👎

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/cobaltcore-dev/cloud-profile-sync/api/v1alpha1/managedcloudprofile.go 100.00% (ø) 1 1 0
github.com/cobaltcore-dev/cloud-profile-sync/api/v1alpha1/zz_generated.deepcopy.go 46.91% (ø) 162 76 86
github.com/cobaltcore-dev/cloud-profile-sync/controllers/managedcloudprofile_controller.go 69.94% (-3.20%) 173 (-2) 121 (-7) 52 (+5) 👎

Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code.

Changed unit test files

  • github.com/cobaltcore-dev/cloud-profile-sync/controllers/managedcloudprofile_controller_test.go

@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

🧹 Nitpick comments (1)
controllers/managedcloudprofile_controller_test.go (1)

549-552: These specs still fail before GC runs.

controllers/managedcloudprofile_controller.go:80-82 calls updateMachineImages before reconcileGarbageCollection, and controllers/managedcloudprofile_controller.go:283-295 consumes the same bad secret/registry during apply. So adding mcp.Spec.GarbageCollection here doesn’t make these examples cover GC-specific failures; they still pass on the ApplyFailed path. Either rename them to match that behavior or restructure the fixtures so apply succeeds and GC is the only failing stage.

Also applies to: 588-591

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@controllers/managedcloudprofile_controller_test.go` around lines 549 - 552,
The test sets mcp.Spec.GarbageCollection but the controller calls
updateMachineImages before reconcileGarbageCollection and apply already fails on
the bad secret/registry, so the test is not exercising GC failures. Either (A)
rename the test(s) to reflect they hit the ApplyFailed path (e.g., include
"ApplyFailed" in the test name) or (B) change the test fixtures so
updateMachineImages and the apply stage succeed and only
reconcileGarbageCollection fails: fix the fake secret/registry values used by
updateMachineImages and the apply path (the same secret consumed in
controllers/managedcloudprofile_controller.go updateMachineImages and the
reconcile/apply logic) so they are valid, leaving only the
garbage-collection-specific failure to be triggered by
reconcileGarbageCollection; apply this change for the instances around the
mcp.Spec.GarbageCollection setup (the blocks at the shown location and the other
occurrence noted).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@api/v1alpha1/managedcloudprofile.go`:
- Around line 23-25: The CRD is missing the new top-level spec.garbageCollection
field added to ManagedCloudProfileSpec; update the CRD generation so the schema
includes spec.garbageCollection (GarbageCollection *GarbageCollectionConfig)
alongside the existing machineImageUpdates[].garbageCollection definition,
regenerate the YAML, and commit it in this PR; also provide a migration
note/script to copy existing nested machineImageUpdates[].garbageCollection
values into the new spec.garbageCollection for existing ManagedCloudProfile
objects so the API server won't prune the new field at admission time.

---

Nitpick comments:
In `@controllers/managedcloudprofile_controller_test.go`:
- Around line 549-552: The test sets mcp.Spec.GarbageCollection but the
controller calls updateMachineImages before reconcileGarbageCollection and apply
already fails on the bad secret/registry, so the test is not exercising GC
failures. Either (A) rename the test(s) to reflect they hit the ApplyFailed path
(e.g., include "ApplyFailed" in the test name) or (B) change the test fixtures
so updateMachineImages and the apply stage succeed and only
reconcileGarbageCollection fails: fix the fake secret/registry values used by
updateMachineImages and the apply path (the same secret consumed in
controllers/managedcloudprofile_controller.go updateMachineImages and the
reconcile/apply logic) so they are valid, leaving only the
garbage-collection-specific failure to be triggered by
reconcileGarbageCollection; apply this change for the instances around the
mcp.Spec.GarbageCollection setup (the blocks at the shown location and the other
occurrence noted).
🪄 Autofix (Beta)

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: defaults

Review profile: CHILL

Plan: Pro

Run ID: d35c0d0a-935c-4432-ab1b-1da0544f98f9

📥 Commits

Reviewing files that changed from the base of the PR and between e2d28e4 and 0f3dbee.

📒 Files selected for processing (4)
  • api/v1alpha1/managedcloudprofile.go
  • api/v1alpha1/zz_generated.deepcopy.go
  • controllers/managedcloudprofile_controller.go
  • controllers/managedcloudprofile_controller_test.go

Comment on lines +23 to +25
// GarbageCollection contains configuration for automated garbage collection
// +optional
GarbageCollection *GarbageCollectionConfig `json:"garbageCollection,omitempty"`

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Regenerate the CRD for this API move.

ManagedCloudProfileSpec now exposes spec.garbageCollection, but crd/cloudprofilesync.cobaltcore.dev_managedcloudprofiles.yaml:519-611 still only defines machineImageUpdates[].garbageCollection and does not add the new top-level property. In-cluster that means the apiserver can keep validating the old shape and prune/reject the new field, so mcp.Spec.GarbageCollection never becomes effective. Please update/regenerate the CRD in the same PR, and call out a migration path if existing objects still rely on the nested field.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@api/v1alpha1/managedcloudprofile.go` around lines 23 - 25, The CRD is missing
the new top-level spec.garbageCollection field added to ManagedCloudProfileSpec;
update the CRD generation so the schema includes spec.garbageCollection
(GarbageCollection *GarbageCollectionConfig) alongside the existing
machineImageUpdates[].garbageCollection definition, regenerate the YAML, and
commit it in this PR; also provide a migration note/script to copy existing
nested machineImageUpdates[].garbageCollection values into the new
spec.garbageCollection for existing ManagedCloudProfile objects so the API
server won't prune the new field at admission time.

@valeryia-hurynovich
valeryia-hurynovich merged commit d52869c into master Mar 31, 2026
7 checks passed
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.

2 participants