Skip to content

Commit 8f14a3e

Browse files
Add dockerRunOptions setting (#64)
* Add dockerRunOptions setting Signed-off-by: Jacob Tomlinson <[email protected]> * Add missing args Signed-off-by: Jacob Tomlinson <[email protected]> --------- Signed-off-by: Jacob Tomlinson <[email protected]>
1 parent c473896 commit 8f14a3e

File tree

7 files changed

+33
-6
lines changed

7 files changed

+33
-6
lines changed

examples/gpu.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apiVersion: container-canary.nvidia.com/v1
2+
kind: Validator
3+
name: gpu
4+
description: A GPU example to show you can pass extra flags to Docker
5+
command:
6+
- "sleep"
7+
- "30"
8+
dockerRunOptions:
9+
- "--gpus"
10+
- "all"
11+
checks:
12+
- name: nvidia-smi
13+
description: 📦 Can run nvidia-smi
14+
probe:
15+
exec:
16+
command:
17+
- /usr/bin/nvidia-smi
18+
initialDelaySeconds: 1

internal/apis/v1/types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ type Validator struct {
4848
// A command to run in the container
4949
// +optional
5050
Command []string
51+
52+
// Additional flags to pass to the docker CLI.
53+
// +optional
54+
DockerRunOptions []string `yaml:"dockerRunOptions"`
5155
}
5256

5357
type Check struct {

internal/config/load.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
"path/filepath"
2727

2828
canaryv1 "github.com/nvidia/container-canary/internal/apis/v1"
29-
"gopkg.in/yaml.v2"
29+
yaml "gopkg.in/yaml.v2"
3030
)
3131

3232
func LoadValidatorFromURL(url string) (*canaryv1.Validator, error) {

internal/container/container.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ type ContainerInterface interface {
4444
Logs() (string, error)
4545
}
4646

47-
func New(image string, env []v1.EnvVar, ports []v1.ServicePort, volumes []canaryv1.Volume, command []string) ContainerInterface {
47+
func New(image string, env []v1.EnvVar, ports []v1.ServicePort, volumes []canaryv1.Volume, command []string, dockerRunOptions []string) ContainerInterface {
4848
name := fmt.Sprintf("%s%s", "canary-runner-", uuid.New().String()[:8])
49-
return &DockerContainer{Name: name, Image: image, Command: command, Env: env, Ports: ports, Volumes: volumes}
49+
return &DockerContainer{Name: name, Image: image, Command: command, Env: env, Ports: ports, Volumes: volumes, RunOptions: dockerRunOptions}
5050
}

internal/container/docker.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type DockerContainer struct {
2020
Env []v1.EnvVar
2121
Ports []v1.ServicePort
2222
Volumes []canaryv1.Volume
23+
RunOptions []string
2324
runCommand string
2425
}
2526

@@ -46,6 +47,10 @@ func (c *DockerContainer) Start() error {
4647
}
4748
}
4849

50+
if len(c.RunOptions) > 0 {
51+
commandArgs = append(commandArgs, c.RunOptions...)
52+
}
53+
4954
commandArgs = append(commandArgs, c.Image)
5055

5156
if len(c.Command) > 0 {

internal/container/docker_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func TestDockerContainer(t *testing.T) {
3737
volumes := []canaryv1.Volume{
3838
{MountPath: "/foo"},
3939
}
40-
c := New("nginx", env, ports, volumes, nil)
40+
c := New("nginx", env, ports, volumes, nil, nil)
4141

4242
err := c.Start()
4343

@@ -69,7 +69,7 @@ func TestDockerContainer(t *testing.T) {
6969
}
7070
}
7171
func TestDockerContainerRemoves(t *testing.T) {
72-
c := New("nginx", nil, nil, nil, nil)
72+
c := New("nginx", nil, nil, nil, nil, nil)
7373

7474
err := c.Start()
7575
if err != nil {

internal/validator/validator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func loadConfig(filePath string) tea.Cmd {
125125

126126
func startContainer(image string, validator *canaryv1.Validator) tea.Cmd {
127127
return func() tea.Msg {
128-
container := container.New(image, validator.Env, validator.Ports, validator.Volumes, validator.Command)
128+
container := container.New(image, validator.Env, validator.Ports, validator.Volumes, validator.Command, validator.DockerRunOptions)
129129
err := container.Start()
130130
if err != nil {
131131
return containerFailed{Error: err}

0 commit comments

Comments
 (0)