Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ require (
github.com/distribution/reference v0.6.0
github.com/docker/cli v29.8.2+incompatible
github.com/docker/cli-docs-tool v0.11.0
github.com/docker/docker v28.5.2+incompatible
github.com/docker/go-units v0.5.0
github.com/dustinkirkland/golang-petname v0.0.0-20261016130451-be8536a0e189
github.com/gofrs/flock v0.13.1
github.com/golang/snappy v1.0.0
github.com/google/go-dap v0.12.1-0.20250904181021-d7a2259b058b
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,6 @@ github.com/docker/cli-docs-tool v0.11.0 h1:7d8QARFb7QEobizqxmEM7fOteZEHwH/zWgHQt
github.com/docker/cli-docs-tool v0.11.0/go.mod h1:ma8BKiisUo8D6W05XEYIh3oa1UbgrZhi1nowyKFJa8Q=
github.com/docker/distribution v2.8.3+incompatible h1:AtKxIZ36LoNK51+Z6RpzLpddBirtxJnzDrHLEKxTAYk=
github.com/docker/distribution v2.8.3+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
github.com/docker/docker v28.5.2+incompatible h1:DBX0Y0zAjZbSrm1uzOkdr1onVghKaftjlSWt4AFexzM=
github.com/docker/docker v28.5.2+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/docker-credential-helpers v0.9.9 h1:BkydjIgZ46JnDbqyM2p2fc63KMw6y+KHL3Em/2AGJ7w=
github.com/docker/docker-credential-helpers v0.9.9/go.mod h1:v1S+hepowrQXITkEfw6o4+BMbGot02wiKpzWhGUZK6c=
github.com/docker/go-connections v0.8.1 h1:JibmG5hULs5qXSr/cp/w3Pw5fZuStt4MOHMUExb29/M=
Expand All @@ -199,6 +197,8 @@ github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/dustinkirkland/golang-petname v0.0.0-20261016130451-be8536a0e189 h1:OC0e6wzF5KAM9n92zzB4LWNQMHFrJd4duS1VXQJo6Y0=
github.com/dustinkirkland/golang-petname v0.0.0-20261016130451-be8536a0e189/go.mod h1:8AuBTZBRSFqEYBPYULd+NN474/zZBLP+6WeT5S9xlAc=
github.com/emicklei/go-restful/v3 v3.13.0 h1:C4Bl2xDndpU6nJ4bc1jXd+uTmYPVUwkD6bFY/oTyCes=
github.com/emicklei/go-restful/v3 v3.13.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
github.com/felixge/httpsnoop v1.1.0 h1:3YtUj32ZZkqZtt3sZZsClsymw/QDuVfpNhoA31zeORc=
Expand Down
25 changes: 25 additions & 0 deletions store/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,28 @@ func TestNodeInvalidName(t *testing.T) {
require.Error(t, err)
require.True(t, IsErrInvalidName(err))
}

func TestGenerateName(t *testing.T) {
t.Parallel()

s, err := New(confutil.NewConfig(nil, confutil.WithDir(t.TempDir())))
require.NoError(t, err)

txn, release, err := s.Txn()
require.NoError(t, err)
defer release()

for range 100 {
name, err := GenerateName(txn)
require.NoError(t, err)
require.Regexp(t, `^[a-z]+_[a-z]+$`, name)

validated, err := ValidateName(name)
require.NoError(t, err)
require.Equal(t, name, validated)

_, err = txn.NodeGroupByName(name)
require.True(t, os.IsNotExist(errors.Cause(err)))
require.NoError(t, txn.Save(&NodeGroup{Name: name}))
}
}
7 changes: 3 additions & 4 deletions store/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"regexp"
"strings"

"github.com/docker/docker/pkg/namesgenerator"
petname "github.com/dustinkirkland/golang-petname"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -38,9 +38,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 := petname.Generate(2, "_")
if _, err := txn.NodeGroupByName(name); err != nil {
if !os.IsNotExist(errors.Cause(err)) {
return "", err
Expand Down
Loading
Loading