@@ -21,11 +21,13 @@ 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/config"
2728 "github.com/containerd/nerdctl/v2/pkg/containerutil"
2829 "github.com/containerd/nerdctl/v2/pkg/idutil/containerwalker"
30+ "github.com/containerd/nerdctl/v2/pkg/labels/k8slabels"
2931)
3032
3133// Restart will restart one or more containers.
@@ -36,13 +38,20 @@ func Restart(ctx context.Context, client *containerd.Client, containers []string
3638 if found .MatchCount > 1 {
3739 return fmt .Errorf ("multiple IDs found with provided prefix: %s" , found .Req )
3840 }
41+ info , err := found .Container .Info (ctx )
42+ if err != nil {
43+ return fmt .Errorf ("can't get container %s info " , found .Container .ID ())
44+ }
45+ if _ , ok := info .Labels [k8slabels .ContainerType ]; ok {
46+ log .L .Warnf ("nerdctl does not support restarting container %s created by Kubernetes" , info .ID )
47+ }
3948 if err := containerutil .Stop (ctx , found .Container , options .Timeout , options .Signal ); err != nil {
4049 return err
4150 }
4251 if err := containerutil .Start (ctx , found .Container , false , false , client , "" , (* config .Config )(& options .GOption )); err != nil {
4352 return err
4453 }
45- _ , err : = fmt .Fprintln (options .Stdout , found .Req )
54+ _ , err = fmt .Fprintln (options .Stdout , found .Req )
4655 return err
4756 },
4857 }
0 commit comments