Skip to content

Conversation

@chrisseto
Copy link
Contributor

@chrisseto chrisseto commented Aug 18, 2025

Extract the simple syncing logic from lifecycle.ResourceClient into a
generic and dedicated kube.Syncer struct.

Future work (Console CR) will utilize this new struct to implement the bulk of
its logic.

Additionally fix a subtle bug in the existing sync algorithm. As
client.InNamespace was never provided to the ResourceClient's List calls,
it would default to "default". As the tests used the default namespace, this
issue wasn't visible. The primary trouble is that Sync would not correct
delete resources due to List not returning them. It's likely NodePools were
affected in some way but how is unclear.

@chrisseto chrisseto force-pushed the chris/p/extract-syncer branch 3 times, most recently from 260f3d6 to 3b4ea8a Compare August 19, 2025 14:52
Extract the simple syncing logic from `lifecycle.ResourceClient` into a
generic and dedicated `kube.Syncer` struct.

Future work (Console CR) will utilize this new struct to implement the bulk of
its logic.

Additionally fix a subtle bug in the existing sync algorithm. As
`client.InNamespace` was never provided to the `ResourceClient`'s `List` calls,
it would default to `"default"`. As the tests used the default namespace, this
issue wasn't visible. The primary trouble is that `Sync` would not correct
delete resources due to `List` not returning them. It's likely NodePools were
affected in some way but how is unclear.
@chrisseto chrisseto force-pushed the chris/p/extract-syncer branch from 3b4ea8a to a8369ef Compare August 20, 2025 16:07
"github.com/redpanda-data/redpanda-operator/pkg/otelutil/log"
)

const fieldOwner client.FieldOwner = "redpanda-operator"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also discovered, via an upgrade test, that this value is different from that in the lifecycle client.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good to me to make them the same. Shouldn't cause any issues if they're different since this controller is only relevant for CRDs that are reffing the cluster, but the consistency is a 🎉 to me.

Copy link
Contributor

@andrewstucki andrewstucki left a comment

Choose a reason for hiding this comment

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

Ovrall these changes LGTM. There's one issue that may or may not be a thing. Don't recall how more recent versions of Go deal with variable scoping on ranges. I overall like this extraction as it makes it a bit easier to reason about components rather than having as fat of a lifecycle client.


existing = append(existing, &poolWithOrdinals{
set: statefulSet,
set: &statefulSet,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
set: &statefulSet,
set: ptr.To(statefulSet),

it's a bit hard to read in the diff, but pretty sure this is a loop-initialized variable you're taking the address of. Though I vaguely recall newer versions of Go may have fixed some of the lifetime scoping of range variables, so this might not be problematic... just raises my spidey senses a bit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm 90% certain that this is fine as of go... 1.22/1.23. If it wasn't fine ptr.To would produce the same error :P

I'll double check before merging. As I wrote this all I was thinking was "rustc would scream blood murder about this. I love garbage collection".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Screenshot 2025-08-20 at 13 19 58

Copy link
Contributor

Choose a reason for hiding this comment

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

👍 - yeah, looks like 1.22 introduced a change in range-based scope lifecycles. Though, if it hadn't, ptr.To would actually fix it due to the assignment to an intermediate variable (i.e. the function parameter).

"github.com/redpanda-data/redpanda-operator/pkg/otelutil/log"
)

const fieldOwner client.FieldOwner = "redpanda-operator"
Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good to me to make them the same. Shouldn't cause any issues if they're different since this controller is only relevant for CRDs that are reffing the cluster, but the consistency is a 🎉 to me.

@chrisseto chrisseto merged commit 4cf6660 into main Aug 20, 2025
10 checks passed
@chrisseto chrisseto deleted the chris/p/extract-syncer branch August 20, 2025 17:46
@github-actions
Copy link

💚 All backports created successfully

Status Branch Result
release/v25.1.x

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation and see the Github Action logs for details

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants