@@ -21,10 +21,12 @@ import (
2121 "fmt"
2222
2323 containerd "github.com/containerd/containerd/v2/client"
24+ "github.com/containerd/log"
2425
2526 "github.com/containerd/nerdctl/v2/pkg/api/types"
2627 "github.com/containerd/nerdctl/v2/pkg/containerutil"
2728 "github.com/containerd/nerdctl/v2/pkg/idutil/containerwalker"
29+ "github.com/containerd/nerdctl/v2/pkg/labels/k8slabels"
2830)
2931
3032// Restart will restart one or more containers.
@@ -35,13 +37,20 @@ func Restart(ctx context.Context, client *containerd.Client, containers []string
3537 if found .MatchCount > 1 {
3638 return fmt .Errorf ("multiple IDs found with provided prefix: %s" , found .Req )
3739 }
40+ info , err := found .Container .Info (ctx )
41+ if err != nil {
42+ return fmt .Errorf ("can't get container %s info " , found .Container .ID ())
43+ }
44+ if _ , ok := info .Labels [k8slabels .ContainerType ]; ok {
45+ log .L .Warnf ("nerdctl does not support restarting container %s created by Kubernetes" , info .ID )
46+ }
3847 if err := containerutil .Stop (ctx , found .Container , options .Timeout , options .Signal ); err != nil {
3948 return err
4049 }
4150 if err := containerutil .Start (ctx , found .Container , false , false , client , "" ); err != nil {
4251 return err
4352 }
44- _ , err : = fmt .Fprintln (options .Stdout , found .Req )
53+ _ , err = fmt .Fprintln (options .Stdout , found .Req )
4554 return err
4655 },
4756 }
0 commit comments