Skip to content
Merged
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
11 changes: 10 additions & 1 deletion pkg/cmd/container/restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ import (
"fmt"

containerd "github.com/containerd/containerd/v2/client"
"github.com/containerd/log"

"github.com/containerd/nerdctl/v2/pkg/api/types"
"github.com/containerd/nerdctl/v2/pkg/containerutil"
"github.com/containerd/nerdctl/v2/pkg/idutil/containerwalker"
"github.com/containerd/nerdctl/v2/pkg/labels/k8slabels"
)

// Restart will restart one or more containers.
Expand All @@ -35,13 +37,20 @@ func Restart(ctx context.Context, client *containerd.Client, containers []string
if found.MatchCount > 1 {
return fmt.Errorf("multiple IDs found with provided prefix: %s", found.Req)
}
info, err := found.Container.Info(ctx)
if err != nil {
return fmt.Errorf("can't get container %s info ", found.Container.ID())
}
if _, ok := info.Labels[k8slabels.ContainerType]; ok {
log.L.Warnf("nerdctl does not support restarting container %s created by Kubernetes", info.ID)
}
if err := containerutil.Stop(ctx, found.Container, options.Timeout, options.Signal); err != nil {
return err
}
if err := containerutil.Start(ctx, found.Container, false, false, client, ""); err != nil {
return err
}
_, err := fmt.Fprintln(options.Stdout, found.Req)
_, err = fmt.Fprintln(options.Stdout, found.Req)
return err
},
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/containerutil/containerutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ func Start(ctx context.Context, container containerd.Container, isAttach bool, i
return err
}

if _, ok := lab[k8slabels.ContainerType]; ok {
log.L.Warnf("nerdctl does not support starting container %s created by Kubernetes", container.ID())
}
if err := ReconfigNetContainer(ctx, container, client, lab); err != nil {
return err
}
Expand Down
Loading