Skip to content

Commit

Permalink
Merge pull request #256 from jumppad-labs/f-always-restart-container
Browse files Browse the repository at this point in the history
Allow specifying restart count as -1 for always
  • Loading branch information
nicholasjackson authored Nov 17, 2023
2 parents 1492c14 + 90ba80a commit 4b37299
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions pkg/clients/container/docker_tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ func (d *DockerTasks) CreateContainer(c *dtypes.Container) (string, error) {

if c.MaxRestartCount > 0 {
hc.RestartPolicy = container.RestartPolicy{Name: "on-failure", MaximumRetryCount: c.MaxRestartCount}
} else if c.MaxRestartCount == -1 {
hc.RestartPolicy = container.RestartPolicy{Name: "always"}
}

if c.Capabilities != nil {
Expand Down
15 changes: 15 additions & 0 deletions pkg/clients/container/docker_tasks_container_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,21 @@ func TestContainerConfiguresRetryWhenCountGreater0(t *testing.T) {
assert.Equal(t, hc.RestartPolicy.Name, "on-failure")
}

func TestContainerConfiguresRetryWhenCountMinusOne(t *testing.T) {
cc, md, mic := createContainerConfig()
cc.MaxRestartCount = -1

err := setupContainer(t, cc, md, mic)
assert.NoError(t, err)

params := testutils.GetCalls(&md.Mock, "ContainerCreate")[0].Arguments
hc := params[2].(*container.HostConfig)
assert.NotEmpty(t, hc.Resources)

assert.Equal(t, hc.RestartPolicy.MaximumRetryCount, 0)
assert.Equal(t, hc.RestartPolicy.Name, "always")
}

func TestContainerNotConfiguresRetryWhen0(t *testing.T) {
cc, md, mic := createContainerConfig()

Expand Down
2 changes: 1 addition & 1 deletion pkg/config/resources/container/resource_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ type Volume struct {
ReadOnly bool `hcl:"read_only,optional" json:"read_only,omitempty"` // specify that the volume is mounted read only
BindPropagation string `hcl:"bind_propagation,optional" json:"bind_propagation,omitempty"` // propagation mode for bind mounts [shared, private, slave, rslave, rprivate]
BindPropagationNonRecursive bool `hcl:"bind_propagation_non_recursive,optional" json:"bind_propagation_non_recursive,omitempty"` // recursive bind mount, default true
SelinuxRelabel string `hcl:"selinux_relabel,optional" json:"selinux_relabel,optional"` // selinux_relabeling ["", shared, private]
SelinuxRelabel string `hcl:"selinux_relabel,optional" json:"selinux_relabel,omitempty"` // selinux_relabeling ["", shared, private]
}

type Volumes []Volume
Expand Down

0 comments on commit 4b37299

Please sign in to comment.