Skip to content

pkg/stringid: deprecate, move to daemon, and provide copy in client#50504

Merged
thaJeztah merged 1 commit intomoby:masterfrom
thaJeztah:pkg_stringid
Jul 25, 2025
Merged

pkg/stringid: deprecate, move to daemon, and provide copy in client#50504
thaJeztah merged 1 commit intomoby:masterfrom
thaJeztah:pkg_stringid

Conversation

@thaJeztah
Copy link
Member

@thaJeztah thaJeztah commented Jul 24, 2025

pkg/stringid: move to daemon, and provide copy in client

The stringid package is used in many places; while it's trivial
to implement a similar utility, let's just provide it as a utility
package in the client, removing the daemon-specific logic.

For integration tests, I opted to use the implementation in the
client, as those should not ideally not make assumptions about
the daemon implementation.

- Human readable description for the release notes

Go SDK: deprecate pkg/stringid in favour of github.com/moby/moby/client/pkg/stringid

- A picture of a cute animal (not mandatory but encouraged)

@thaJeztah

This comment was marked as resolved.

@thaJeztah thaJeztah force-pushed the pkg_stringid branch 3 times, most recently from 852ef2f to 8b997ad Compare July 24, 2025 12:23
@thaJeztah thaJeztah marked this pull request as ready for review July 24, 2025 12:24
@thaJeztah thaJeztah requested a review from dmcgowan July 24, 2025 21:16
@thaJeztah

This comment was marked as outdated.

@thaJeztah
Copy link
Member Author

Rebased and now moved the copy in the daemon to daemon/internal as nothing outside of the daemon should be using that one.

The stringid package is used in many places; while it's trivial
to implement a similar utility, let's just provide it as a utility
package in the client, removing the daemon-specific logic.

For integration tests, I opted to use the implementation in the
client, as those should not ideally not make assumptions about
the daemon implementation.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

// GenerateRandomID returns a unique, 64-character ID consisting of a-z, 0-9.
func GenerateRandomID() string {
b := make([]byte, 32)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should 32 be fullLen/2 ... or, move the const to the unit test?

(fullLen was also unused in the original, apart from in the unit test.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Ha! Perhaps, yes. I didn't pay too close attention to the existing implementation. I assume we won't change the 64-char length, so I'll leave that one for a future exercise (there's a test validating the length).

Copy link
Contributor

@austinvazquez austinvazquez left a comment

Choose a reason for hiding this comment

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

Sometimes when making copies it's useful to have a mechanism for detecting drift, but in this case the packages are simple and mature enough that probably that would be over engineering. Continue to monitor and see how it shakes out.

@thaJeztah
Copy link
Member Author

mechanism

Yeah, in the end, they serve different purposes, or at least, should not have to follow the same contract. For the daemon, there's special handling for all-numeric IDs, because the short-ID can be used a default hostname inside the container (which doesn't like numeric hostnames). For the client, and elsewhere, it was really a convenience utility for presentation (and the randomID proved to be popular for those "I need something random"). That last part... really shouldn't be "us" providing it, but it's 5 lines of code to maintain, so I'm not too upset to include it.

@thaJeztah
Copy link
Member Author

I'll bring this one in 👍

@thaJeztah thaJeztah merged commit 7dc46c6 into moby:master Jul 25, 2025
208 of 209 checks passed
@thaJeztah thaJeztah deleted the pkg_stringid branch July 25, 2025 14:00
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