@@ -339,8 +339,7 @@ func Create(ctx context.Context, client *containerd.Client, args []string, netMa
339
339
cOpts = append (cOpts , lCOpts ... )
340
340
341
341
var containerNameStore namestore.NameStore
342
- if options .Name == "" && ! options .NameChanged {
343
- // Automatically set the container name, unless `--name=""` was explicitly specified.
342
+ if options .Name == "" {
344
343
var imageRef string
345
344
if ensuredImage != nil {
346
345
imageRef = ensuredImage .Ref
@@ -352,15 +351,15 @@ func Create(ctx context.Context, client *containerd.Client, args []string, netMa
352
351
}
353
352
options .Name = parsedReference .SuggestContainerName (id )
354
353
}
355
- if options .Name != "" {
356
- containerNameStore , err = namestore .New (dataStore , options .GOptions .Namespace )
357
- if err != nil {
358
- return nil , generateRemoveOrphanedDirsFunc (ctx , id , dataStore , internalLabels ), err
359
- }
360
- if err := containerNameStore .Acquire (options .Name , id ); err != nil {
361
- return nil , generateRemoveOrphanedDirsFunc (ctx , id , dataStore , internalLabels ), err
362
- }
354
+
355
+ containerNameStore , err = namestore .New (dataStore , options .GOptions .Namespace )
356
+ if err != nil {
357
+ return nil , generateRemoveOrphanedDirsFunc (ctx , id , dataStore , internalLabels ), err
363
358
}
359
+ if err := containerNameStore .Acquire (options .Name , id ); err != nil {
360
+ return nil , generateRemoveOrphanedDirsFunc (ctx , id , dataStore , internalLabels ), err
361
+ }
362
+
364
363
internalLabels .name = options .Name
365
364
internalLabels .pidFile = options .PidFile
366
365
@@ -714,9 +713,7 @@ func withInternalLabels(internalLabels internalLabels) (containerd.NewContainerO
714
713
var hostConfigLabel dockercompat.HostConfigLabel
715
714
var dnsSettings dockercompat.DNSSettings
716
715
m [labels .Namespace ] = internalLabels .namespace
717
- if internalLabels .name != "" {
718
- m [labels .Name ] = internalLabels .name
719
- }
716
+ m [labels .Name ] = internalLabels .name
720
717
m [labels .Hostname ] = internalLabels .hostname
721
718
m [labels .Domainname ] = internalLabels .domainname
722
719
extraHostsJSON , err := json .Marshal (internalLabels .extraHosts )
@@ -1024,15 +1021,13 @@ func generateGcFunc(ctx context.Context, container containerd.Container, ns, id,
1024
1021
log .G (ctx ).WithError (rmErr ).Warnf ("failed to remove container %q state dir %q" , id , internalLabels .stateDir )
1025
1022
}
1026
1023
1027
- if name != "" {
1028
- var errE error
1029
- if containerNameStore , errE = namestore .New (dataStore , ns ); errE != nil {
1030
- log .G (ctx ).WithError (errE ).Warnf ("failed to instantiate container name store during cleanup for container %q" , id )
1031
- }
1032
- // Double-releasing may happen with containers started with --rm, so, ignore NotFound errors
1033
- if errE := containerNameStore .Release (name , id ); errE != nil && ! errors .Is (errE , store .ErrNotFound ) {
1034
- log .G (ctx ).WithError (errE ).Warnf ("failed to release container name store for container %q (%s)" , name , id )
1035
- }
1024
+ var errE error
1025
+ if containerNameStore , errE = namestore .New (dataStore , ns ); errE != nil {
1026
+ log .G (ctx ).WithError (errE ).Warnf ("failed to instantiate container name store during cleanup for container %q" , id )
1027
+ }
1028
+ // Double-releasing may happen with containers started with --rm, so, ignore NotFound errors
1029
+ if errE := containerNameStore .Release (name , id ); errE != nil && ! errors .Is (errE , store .ErrNotFound ) {
1030
+ log .G (ctx ).WithError (errE ).Warnf ("failed to release container name store for container %q (%s)" , name , id )
1036
1031
}
1037
1032
}
1038
1033
}
0 commit comments