-
Notifications
You must be signed in to change notification settings - Fork 632
store: replace namesgenerator with neutral builder IDs #3813
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -5,12 +5,16 @@ import ( | |||||||||||||||||||||||||||||||||||||||||
| "regexp" | ||||||||||||||||||||||||||||||||||||||||||
| "strings" | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| "github.com/docker/docker/pkg/namesgenerator" | ||||||||||||||||||||||||||||||||||||||||||
| "github.com/moby/buildkit/identity" | ||||||||||||||||||||||||||||||||||||||||||
| "github.com/pkg/errors" | ||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| var namePattern = regexp.MustCompile(`^[a-zA-Z][a-zA-Z0-9\.\-_]*$`) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| const generatedNamePrefix = "builder_" | ||||||||||||||||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As we're changing, might as well use
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I used |
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| var newID = identity.NewID | ||||||||||||||||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wondering if we need the complexity of import (
"math/rand/v2"
"encoding/hex"
)
func NewID() string {
var b [8]byte // 64 bits
rand.Read(b[:])
return hex.EncodeToString(b[:]) // 16 hex chars
}
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh; and I just recalled I did something similar for k8s some time ago; buildx/driver/kubernetes/util/generate.go Lines 56 to 75 in d5d3d3d
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| type errInvalidName struct { | ||||||||||||||||||||||||||||||||||||||||||
| error | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -39,8 +43,8 @@ func ValidateName(s string) (string, error) { | |||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| func GenerateName(txn *Txn) (string, error) { | ||||||||||||||||||||||||||||||||||||||||||
| var name string | ||||||||||||||||||||||||||||||||||||||||||
| for i := range 6 { | ||||||||||||||||||||||||||||||||||||||||||
| name = namesgenerator.GetRandomName(i) | ||||||||||||||||||||||||||||||||||||||||||
| for range 6 { | ||||||||||||||||||||||||||||||||||||||||||
| name = generatedNamePrefix + newID()[:12] | ||||||||||||||||||||||||||||||||||||||||||
| if _, err := txn.NodeGroupByName(name); err != nil { | ||||||||||||||||||||||||||||||||||||||||||
| if !os.IsNotExist(errors.Cause(err)) { | ||||||||||||||||||||||||||||||||||||||||||
| return "", err | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not for this PR probably , but looks like we have some different patterns in different packages;
buildx/bake/bake.go
Lines 40 to 41 in 09f288c
I know these regexes are rather memory-hungry; we could even rewrite these to a basic function to loop; I recall we did similar changes elsewhere, e.g.; https://github.com/moby/moby/blob/dff719e3674958407416fd1d8a35db998f128da2/daemon/internal/stringid/stringid.go#L62-L70