Skip to content

refactor(utils): move ResolveClusterCRByUUID's lookup into a generic atlas/kube helper - #450

Draft
boddumanohar wants to merge 1 commit into
mainfrom
address-pr441-review-comment
Draft

refactor(utils): move ResolveClusterCRByUUID's lookup into a generic atlas/kube helper#450
boddumanohar wants to merge 1 commit into
mainfrom
address-pr441-review-comment

Conversation

@boddumanohar

Copy link
Copy Markdown
Member

Summary

Follow-up to review feedback from #441 (comment) on ResolveClusterCRByUUID (operator/internal/utils/objects.go), deferred at the time ("let's do this separately").

The reviewer asked to move the by-UUID lookup into atlas/kube as part of the Resolver interface. That interface (atlas-lib/kube/resolver.go) is deliberately generic — it only knows core Kubernetes types (PersistentVolume, VolumeAttachment, StorageClass) and has zero dependency on the operator's own CRD types. ResolveClusterCRByUUID resolves the operator's StorageCluster CRD specifically; moving that concrete lookup into atlas/kube as-is would require atlas/kube to import simplyblock-operator/api/v1alpha1 — a circular module dependency, since the operator already depends on atlas via a local replace.

Instead, this pulls out the reusable mechanism — a generic find-by-key linear scan — into atlas/kube, with no knowledge of StorageCluster:

  • atlas-lib/kube/find.go: FindByKey[T any](items []T, keyFn func(T) string, key string) (T, error), returning errs.ErrNotFound (the package's existing convention) when nothing matches.
  • operator/internal/utils/objects.go: ResolveClusterCRByUUID now lists StorageClusters itself (as before) and calls kube.FindByKey with Status.UUID as the key, wrapping a miss in the existing ErrClusterNotFound for callers that check it (e.g. simplyblockstoragepool_controller.go).

No behavior change — same lookup, same error semantics, shared scan logic.

Test plan

  • go test ./... in both atlas-lib and operator modules — full suite passes
  • make lint in both modules — 0 issues
  • Added TestFindByKey covering found / not-found / empty-list cases

🤖 Generated with Claude Code

…atlas/kube helper

Addresses review feedback on #441 (ResolveClusterCRByUUID): the linear
by-key scan is generic enough to share, but atlas/kube can't depend on
the operator's StorageCluster CRD type without creating a circular
module dependency. Adds kube.FindByKey[T], a type-parameterized
find-by-key helper with no knowledge of any concrete CRD, and has
ResolveClusterCRByUUID list StorageClusters itself and call it with
Status.UUID as the key.
@boddumanohar
boddumanohar marked this pull request as draft August 21, 2026 14:02
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.

1 participant