Skip to content

Commit a003f56

Browse files
authored
Merge pull request #28223 from jankaluza/namesgenerator
libpod: include names-generator.go
2 parents 6b10bea + 8c4edb6 commit a003f56

File tree

5 files changed

+49
-5
lines changed

5 files changed

+49
-5
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ require (
2222
github.com/cyphar/filepath-securejoin v0.6.1
2323
github.com/digitalocean/go-qemu v0.0.0-20250212194115-ee9b0668d242
2424
github.com/docker/distribution v2.8.3+incompatible
25-
github.com/docker/docker v28.5.2+incompatible
2625
github.com/docker/go-connections v0.6.0
2726
github.com/docker/go-plugins-helpers v0.0.0-20240701071450-45e2431495c8
2827
github.com/docker/go-units v0.5.0
@@ -110,6 +109,7 @@ require (
110109
github.com/digitalocean/go-libvirt v0.0.0-20220804181439-8648fbde413e // indirect
111110
github.com/disiqueira/gotree/v3 v3.0.2 // indirect
112111
github.com/distribution/reference v0.6.0 // indirect
112+
github.com/docker/docker v28.5.2+incompatible // indirect
113113
github.com/docker/docker-credential-helpers v0.9.5 // indirect
114114
github.com/ebitengine/purego v0.9.1 // indirect
115115
github.com/felixge/httpsnoop v1.0.4 // indirect

vendor/github.com/docker/docker/pkg/namesgenerator/names-generator.go renamed to libpod/namesgenerator/names-generator.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
// This file has been copied from
2+
// https://github.com/moby/moby/tree/a52171f5eeb6e553e7c4744abf6b722962b2aca4/internal/namesgenerator.
3+
// It is licensed under the Apache License 2.0.
4+
// See https://github.com/moby/moby/blob/a52171f5eeb6e553e7c4744abf6b722962b2aca4/LICENSE.
5+
//
16
// Package namesgenerator generates random names.
27
//
38
// This package is officially "frozen" - no new additions will be accepted.
@@ -263,7 +268,7 @@ var (
263268
// David Lee Chaum - American computer scientist and cryptographer. Known for his seminal contributions in the field of anonymous communication. https://en.wikipedia.org/wiki/David_Chaum
264269
"chaum",
265270

266-
// Pafnuty Chebyshev - Russian mathematician. He is known fo his works on probability, statistics, mechanics, analytical geometry and number theory https://en.wikipedia.org/wiki/Pafnuty_Chebyshev
271+
// Pafnuty Chebyshev - Russian mathematician. He is known for his works on probability, statistics, mechanics, analytical geometry and number theory https://en.wikipedia.org/wiki/Pafnuty_Chebyshev
267272
"chebyshev",
268273

269274
// Joan Clarke - Bletchley Park code breaker during the Second World War who pioneered techniques that remained top secret for decades. Also an accomplished numismatist https://en.wikipedia.org/wiki/Joan_Clarke
@@ -793,7 +798,7 @@ var (
793798
// Dorothy Vaughan was a NASA mathematician and computer programmer on the SCOUT launch vehicle program that put America's first satellites into space - https://en.wikipedia.org/wiki/Dorothy_Vaughan
794799
"vaughan",
795800

796-
// Cédric Villani - French mathematician, won Fields Medal, Fermat Prize and Poincaré Price for his work in differential geometry and statistical mechanics. https://en.wikipedia.org/wiki/C%C3%A9dric_Villani
801+
// Cédric Villani - French mathematician, won Fields Medal, Fermat Prize and Poincaré Prize for his work in differential geometry and statistical mechanics. https://en.wikipedia.org/wiki/C%C3%A9dric_Villani
797802
"villani",
798803

799804
// Sir Mokshagundam Visvesvaraya - is a notable Indian engineer. He is a recipient of the Indian Republic's highest honour, the Bharat Ratna, in 1955. On his birthday, 15 September is celebrated as Engineer's Day in India in his memory - https://en.wikipedia.org/wiki/Visvesvaraya
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// This file has been copied from
2+
// https://github.com/moby/moby/tree/a52171f5eeb6e553e7c4744abf6b722962b2aca4/internal/namesgenerator.
3+
// It is licensed under the Apache License 2.0.
4+
// See https://github.com/moby/moby/blob/a52171f5eeb6e553e7c4744abf6b722962b2aca4/LICENSE.
5+
6+
package namesgenerator
7+
8+
import (
9+
"strings"
10+
"testing"
11+
)
12+
13+
func TestNameFormat(t *testing.T) {
14+
name := GetRandomName(0)
15+
if !strings.Contains(name, "_") {
16+
t.Fatalf("Generated name does not contain an underscore")
17+
}
18+
if strings.ContainsAny(name, "0123456789") {
19+
t.Fatalf("Generated name contains numbers!")
20+
}
21+
}
22+
23+
func TestNameRetries(t *testing.T) {
24+
name := GetRandomName(1)
25+
if !strings.Contains(name, "_") {
26+
t.Fatalf("Generated name does not contain an underscore")
27+
}
28+
if !strings.ContainsAny(name, "0123456789") {
29+
t.Fatalf("Generated name doesn't contain a number")
30+
}
31+
}
32+
33+
func BenchmarkGetRandomName(b *testing.B) {
34+
b.ReportAllocs()
35+
var out string
36+
for b.Loop() {
37+
out = GetRandomName(5)
38+
}
39+
b.Log("Last result:", out)
40+
}

libpod/runtime.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ import (
1919
"github.com/containers/podman/v6/libpod/define"
2020
"github.com/containers/podman/v6/libpod/events"
2121
"github.com/containers/podman/v6/libpod/lock"
22+
"github.com/containers/podman/v6/libpod/namesgenerator"
2223
"github.com/containers/podman/v6/libpod/plugin"
2324
"github.com/containers/podman/v6/libpod/shutdown"
2425
"github.com/containers/podman/v6/pkg/domain/entities"
2526
"github.com/containers/podman/v6/pkg/domain/entities/reports"
2627
"github.com/containers/podman/v6/pkg/rootless"
2728
"github.com/containers/podman/v6/pkg/systemd"
2829
"github.com/containers/podman/v6/pkg/util"
29-
"github.com/docker/docker/pkg/namesgenerator"
3030
"github.com/hashicorp/go-multierror"
3131
jsoniter "github.com/json-iterator/go"
3232
spec "github.com/opencontainers/runtime-spec/specs-go"

vendor/modules.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,6 @@ github.com/docker/docker/api/types/swarm/runtime
251251
github.com/docker/docker/api/types/versions
252252
github.com/docker/docker/pkg/homedir
253253
github.com/docker/docker/pkg/jsonmessage
254-
github.com/docker/docker/pkg/namesgenerator
255254
github.com/docker/docker/pkg/stdcopy
256255
# github.com/docker/docker-credential-helpers v0.9.5
257256
## explicit; go 1.21

0 commit comments

Comments
 (0)