Skip to content

Commit 0f6c4be

Browse files
committed
update nerdctl to add all global options - dirty
Signed-off-by: Arjun Raja Yogidas <[email protected]>
1 parent df9ff8c commit 0f6c4be

File tree

12 files changed

+32
-55
lines changed

12 files changed

+32
-55
lines changed

cmd/nerdctl/compose/compose_start.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func startContainers(ctx context.Context, client *containerd.Client, containers
114114
}
115115

116116
// in compose, always disable attach
117-
if err := containerutil.Start(ctx, c, false, false, client, "", "", (*config.Config)(globalOptions)); err != nil {
117+
if err := containerutil.Start(ctx, c, false, false, client, "", "", (*config.Config)(globalOptions), options.NerdctlCmd, options.NerdctlArgs); err != nil {
118118
return err
119119
}
120120
info, err := c.Info(ctx, containerd.WithoutRefreshedMetadata)

cmd/nerdctl/container/container_restart.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ func restartOptions(cmd *cobra.Command) (types.ContainerRestartOptions, error) {
4848
return types.ContainerRestartOptions{}, err
4949
}
5050

51+
// Call GlobalFlags function here
52+
nerdctlCmd, nerdctlArgs := helpers.GlobalFlags(cmd)
53+
5154
var timeout *time.Duration
5255
if cmd.Flags().Changed("time") {
5356
// Seconds to wait for stop before killing it
@@ -74,6 +77,8 @@ func restartOptions(cmd *cobra.Command) (types.ContainerRestartOptions, error) {
7477
GOption: globalOptions,
7578
Timeout: timeout,
7679
Signal: signal,
80+
NerdctlCmd: nerdctlCmd,
81+
NerdctlArgs: nerdctlArgs,
7782
}, err
7883
}
7984

cmd/nerdctl/container/container_run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ func runAction(cmd *cobra.Command, args []string) error {
457457
}
458458

459459
// Setup container healthchecks.
460-
if err := healthcheck.CreateTimer(ctx, c, (*config.Config)(&createOpt.GOptions)); err != nil {
460+
if err := healthcheck.CreateTimer(ctx, c, (*config.Config)(&createOpt.GOptions), createOpt.NerdctlCmd, createOpt.nerdctlArgs); err != nil {
461461
return fmt.Errorf("failed to create healthcheck timer: %w", err)
462462
}
463463
if err := healthcheck.StartTimer(ctx, c, (*config.Config)(&createOpt.GOptions)); err != nil {

cmd/nerdctl/container/container_start.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ func startAction(cmd *cobra.Command, args []string) error {
9191
return err
9292
}
9393

94+
// call GlobalFlags( somewhere here
95+
options.NerdctlCmd, options.NerdctlArgs := helpers.GlobalFlags(cmd)
96+
9497
client, ctx, cancel, err := clientutil.NewClient(cmd.Context(), options.GOptions.Namespace, options.GOptions.Address)
9598
if err != nil {
9699
return err

pkg/api/types/container_types.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ type ContainerStartOptions struct {
3636
Checkpoint string
3737
// CheckpointDir is the directory to store checkpoints
3838
CheckpointDir string
39+
// NerdctlCmd is the command name of nerdctl
40+
NerdctlCmd string
41+
// NerdctlArgs is the arguments of nerdctl
42+
NerdctlArgs []string
3943
}
4044

4145
// ContainerKillOptions specifies options for `nerdctl (container) kill`.
@@ -329,6 +333,10 @@ type ContainerRestartOptions struct {
329333
Timeout *time.Duration
330334
// Signal to send to stop the container, before sending SIGKILL
331335
Signal string
336+
// NerdctlCmd is the command name of nerdctl
337+
NerdctlCmd string
338+
// NerdctlArgs is the arguments of nerdctl
339+
NerdctlArgs []string
332340
}
333341

334342
// ContainerPauseOptions specifies options for `nerdctl (container) pause`.

pkg/cmd/container/restart.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ func Restart(ctx context.Context, client *containerd.Client, containers []string
4848
if err := containerutil.Stop(ctx, found.Container, options.Timeout, options.Signal); err != nil {
4949
return err
5050
}
51-
if err := containerutil.Start(ctx, found.Container, false, false, client, "", "", (*config.Config)(&options.GOption)); err != nil {
51+
// ~ maybe just send the NerdctlCmd and NerdctlFlags array instead of the whole object, or maybe just send the whole object instead ~
52+
// This has to be individual options as the Start function gets called by mutiple commands like compse, start and restart, each will have varying structs
53+
if err := containerutil.Start(ctx, found.Container, false, false, client, "", "", (*config.Config)(&options.GOptions), options.NerdctlCmd, options.NerdctlArgs); err != nil {
5254
return err
5355
}
5456
_, err = fmt.Fprintln(options.Stdout, found.Req)

pkg/cmd/container/start.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ func Start(ctx context.Context, client *containerd.Client, reqs []string, option
5656
return err
5757
}
5858
}
59-
if err := containerutil.Start(ctx, found.Container, options.Attach, options.Interactive, client, options.DetachKeys, checkpointDir, (*config.Config)(&options.GOptions)); err != nil {
59+
// ~ maybe just send the NerdctlCmd and NerdctlFlags array instead of the whole object, or maybe just send the whole object instead ~
60+
// This has to be individual options as the Start function gets called by mutiple commands like compse, start and restart, each will have varying structs
61+
if err := containerutil.Start(ctx, found.Container, options.Attach, options.Interactive, client, options.DetachKeys, checkpointDir, (*config.Config)(&options.GOptions), options.NerdctlCmd, options.NerdctlArgs); err != nil {
6062
return err
6163
}
6264
if !options.Attach {

pkg/containerutil/containerutil.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ func GenerateSharingPIDOpts(ctx context.Context, targetCon containerd.Container)
206206
}
207207

208208
// Start starts `container` with `attach` flag. If `attach` is true, it will attach to the container's stdio.
209-
func Start(ctx context.Context, container containerd.Container, isAttach bool, isInteractive bool, client *containerd.Client, detachKeys string, checkpointDir string, cfg *config.Config) (err error) {
209+
func Start(ctx context.Context, container containerd.Container, isAttach bool, isInteractive bool, client *containerd.Client, detachKeys string, checkpointDir string, cfg *config.Config, NerdctlCmd string, NerdctlArgs []string) (err error) {
210210
// defer the storage of start error in the dedicated label
211211
defer func() {
212212
if err != nil {

pkg/healthcheck/healthcheck_manager_darwin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
)
2626

2727
// CreateTimer sets up the transient systemd timer and service for healthchecks.
28-
func CreateTimer(ctx context.Context, container containerd.Container, cfg *config.Config) error {
28+
func CreateTimer(ctx context.Context, container containerd.Container, cfg *config.Config, NerdctlCmd string, NerdctlArgs []string) error {
2929
return nil
3030
}
3131

pkg/healthcheck/healthcheck_manager_freebsd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
)
2626

2727
// CreateTimer sets up the transient systemd timer and service for healthchecks.
28-
func CreateTimer(ctx context.Context, container containerd.Container, cfg *config.Config) error {
28+
func CreateTimer(ctx context.Context, container containerd.Container, cfg *config.Config, NerdctlCmd string, NerdctlArgs []string) error {
2929
return nil
3030
}
3131

0 commit comments

Comments
 (0)