Skip to content

Embed struct, not pointer in resources - #2829

Merged
denik merged 21 commits into
mainfrom
denik/embed-struct-not-ptr
May 8, 2025
Merged

Embed struct, not pointer in resources#2829
denik merged 21 commits into
mainfrom
denik/embed-struct-not-ptr

Conversation

@denik

@denikdenik commented May 7, 2025

Copy link
Copy Markdown
Contributor

Changes

  • Embed struct by value not by pointer in all the resources.
  • Remove IsNil method from the resource interface and implementations (it's never true).

Why

Tests

Existing tests.

@denik
deniktemporarily deployed to test-trigger-is May 7, 2025 14:39 — with GitHub Actions Inactive
@denik
deniktemporarily deployed to test-trigger-is May 8, 2025 08:37 — with GitHub Actions Inactive
@denik
deniktemporarily deployed to test-trigger-is May 8, 2025 08:48 — with GitHub Actions Inactive
@denik
deniktemporarily deployed to test-trigger-is May 8, 2025 08:53 — with GitHub Actions Inactive
@denik
deniktemporarily deployed to test-trigger-is May 8, 2025 09:00 — with GitHub Actions Inactive
@denik
deniktemporarily deployed to test-trigger-is May 8, 2025 09:05 — with GitHub Actions Inactive
@denik
deniktemporarily deployed to test-trigger-is May 8, 2025 09:12 — with GitHub Actions Inactive
@denik
deniktemporarily deployed to test-trigger-is May 8, 2025 09:17 — with GitHub Actions Inactive
@denik
deniktemporarily deployed to test-trigger-is May 8, 2025 09:32 — with GitHub Actions Inactive
@denikdenik changed the title WIP - embed struct, not ptrEmbed struct, not pointer in resourcesMay 8, 2025
@denik
denik marked this pull request as ready for review May 8, 2025 09:33
@denik
deniktemporarily deployed to test-trigger-is May 8, 2025 10:32 — with GitHub Actions Inactive
@denik
deniktemporarily deployed to test-trigger-is May 8, 2025 12:23 — with GitHub Actions Inactive
@denik
deniktemporarily deployed to test-trigger-is May 8, 2025 12:23 — with GitHub Actions Inactive
@denik
denik enabled auto-merge May 8, 2025 12:25
@denik
denik added this pull request to the merge queueMay 8, 2025
@denik
denik removed this pull request from the merge queue due to a manual request May 8, 2025
@denik
denik added this pull request to the merge queueMay 8, 2025
@denik
denik removed this pull request from the merge queue due to a manual request May 8, 2025
@denik
denikforce-pushed the denik/embed-struct-not-ptr branch from a1add45 to 9fa0be8CompareMay 8, 2025 13:05
@denik
deniktemporarily deployed to test-trigger-is May 8, 2025 13:05 — with GitHub Actions Inactive
@denik
denik merged commit b03da56 into mainMay 8, 2025
@denik
denik deleted the denik/embed-struct-not-ptr branch May 8, 2025 13:08

@pieternpietern 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.

Thanks, great simplification!


assert.Nil(t, b.Config.Resources.Volumes["nilVolume"])
assert.Nil(t, b.Config.Resources.Volumes["emptyVolume"].CreateVolumeRequestContent)
// assert.Nil(t, b.Config.Resources.Volumes["emptyVolume"].CreateVolumeRequestContent)

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.

Dup?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Not a dup (second line used to check inner pointer), should have been cleaned up.

ModelServingEndpoints: map[string]*resources.ModelServingEndpoint{
"my_model_serving_endpoint": {
CreateServingEndpoint: &serving.CreateServingEndpoint{},
CreateServingEndpoint: serving.CreateServingEndpoint{},

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.

FWIW, with these structs being zero-initialized, the assignment can be removed entirely.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I agree. For context, most replacement were made with search-and-replace, so they look odd (AI tools were going back and forth on whether it should be a pointer or a struct, so I stopped using those for this).

I feel like there should be a linter to clean this up, but I could not find one.

denik added a commit that referenced this pull request May 20, 2026
## Changes
- Embed struct by value not by pointer in all the resources.
- Remove IsNil method from the resource interface and implementations
(it's never true).
## Why
- Prevents a class of crashes related to nil pointer, like
#2776 and
#1937
- Simplify user code, no need to check nilness as much.
## Tests
Existing tests.
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.

4 participants

@denik@pietern@anton-107@andrewnester