Skip to content

Commit

Permalink
Merge pull request #380 from navidys/container_create_mount_option
Browse files Browse the repository at this point in the history
adding container create mount inputfield option
  • Loading branch information
navidys authored Nov 25, 2023
2 parents 8c2b52e + 05f7e7a commit 54dc570
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 9 deletions.
9 changes: 9 additions & 0 deletions pdcs/containers/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type CreateOptions struct {
DNSSearchDomain []string
Volume string
ImageVolume string
Mount string
SelinuxOpts []string
ApparmorProfile string
Seccomp string
Expand Down Expand Up @@ -101,6 +102,14 @@ func Create(opts CreateOptions) ([]string, error) { //nolint:cyclop
createOptions.Volume = strings.Split(opts.Volume, ",")
}

if opts.Mount != "" {
for _, mopts := range strings.Split(opts.Mount, " ") {
if mopts != "" {
createOptions.Mount = append(createOptions.Mount, mopts)
}
}
}

createOptions.ImageVolume = opts.ImageVolume

// security options
Expand Down
22 changes: 14 additions & 8 deletions test/005-container.bats
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ load helpers_tui
podman network rm $TEST_CONTAINER_NETWORK_NAME || echo done
podman volume rm $TEST_CONTAINER_VOLUME_NAME || echo done

[ ! -d "${TEST_CONTAINER_MOUNT_SOURCE}" ] && mkdir $TEST_CONTAINER_MOUNT_SOURCE

httpd_image=$(podman image ls --sort repository --format "{{ .Repository }}" --filter "reference=docker.io/library/httpd")
if [ "${httpd_image}" == "" ] ; then
podman image pull docker.io/library/httpd
Expand Down Expand Up @@ -74,22 +76,24 @@ load helpers_tui
# select volume from dropdown widget
podman_tui_send_inputs "Down" "Tab"
podman_tui_send_inputs "${TEST_CONTAINER_VOLUME_NAME}:${TEST_CONTAINER_VOLUME_MOUNT_POINT}:rw"
podman_tui_send_inputs "Tab" "Tab"
podman_tui_send_inputs "type=bind,src=${TEST_CONTAINER_MOUNT_SOURCE},dst=${TEST_CONTAINER_MOUNT_DEST}"
sleep 1

# go to "Create" button and press Enter
podman_tui_send_inputs "Tab" "Tab" "Tab" "Enter"
podman_tui_send_inputs "Tab" "Tab" "Enter"
sleep 2

# get created container information
container_information=$(podman container ls --all --pod --filter "name=${TEST_CONTAINER_NAME}$" --format \
"{{ json .PodName }},{{ json .Networks }},{{ json .Mounts }},{{ json .Image }},{{ json .Ports }},{{ json .Labels }}")
"{{ json .PodName }}|{{ json .Networks }}|{{ json .Mounts }}|{{ json .Image }}|{{ json .Ports }}|{{ json .Labels }}")

cnt_pod_name=$(echo $container_information | awk -F, '{print $1}')
cnt_networks=$(echo $container_information | awk -F, '{print $2}')
cnt_mounts=$(echo $container_information | awk -F, '{print $3}')
cnt_image_name=$(echo $container_information | awk -F, '{print $4}')
cnt_ports=$(echo $container_information | awk -F, '{print $5}')
cnt_labels=$(echo $container_information | awk -F, '{print $6}')
cnt_pod_name=$(echo $container_information | awk -F '|' '{print $1}')
cnt_networks=$(echo $container_information | awk -F '|' '{print $2}')
cnt_mounts=$(echo $container_information | awk -F '|' '{print $3}')
cnt_image_name=$(echo $container_information | awk -F '|' '{print $4}')
cnt_ports=$(echo $container_information | awk -F '|' '{print $5}')
cnt_labels=$(echo $container_information | awk -F '|' '{print $6}')

host_port=$(echo $TEST_CONTAINER_PORT | awk -F: '{print $1}')
cnt_port=$(echo $TEST_CONTAINER_PORT | awk -F: '{print $2}')
Expand All @@ -106,6 +110,8 @@ load helpers_tui
assert "$cnt_pod_name" =~ "$TEST_CONTAINER_POD_NAME" "expected container pod: $TEST_CONTAINER_POD_NAME"

assert "$cnt_mounts" =~ "$TEST_CONTAINER_VOLUME_MOUNT_POINT" "expected container volume mount point: $TEST_CONTAINER_VOLUME_MOUNT_POINT"
assert "$cnt_mounts" =~ "$TEST_CONTAINER_MOUNT_DEST" "expected container mount point: $TEST_CONTAINER_MOUNT_DEST"

assert "$cnt_image_name" =~ "$httpd_image" "expected container image name: $httpd_image"
assert "$cnt_ports" =~ "$cnt_port_str" "expected container port: $cnt_port_str"
assert "$cnt_security_opt" =~ "no-new-privileges" "expected no-new-privileges in container security options"
Expand Down
4 changes: 3 additions & 1 deletion test/helpers_tui.bash
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ TEST_CONTAINER_HEALTH_ONFAILURE="restart"
TEST_CONTAINER_POD_NAME="${TEST_NAME}_cnt01_pod"
TEST_CONTAINER_NETWORK_NAME="${TEST_NAME}_cnt01_net"
TEST_CONTAINER_VOLUME_NAME="${TEST_NAME}_cnt01_vol"
TEST_CONTAINER_VOLUME_MOUNT_POINT="/data"
TEST_CONTAINER_VOLUME_MOUNT_POINT="/data_mount01"
TEST_CONTAINER_MOUNT_SOURCE="/tmp/data02"
TEST_CONTAINER_MOUNT_DEST="/data_mount02"
TEST_CONTAINER_COMMIT_IMAGE_NAME="${TEST_NAME}_commited_image"

TEST_CONTAINER_PORT="8888:80"
Expand Down
18 changes: 18 additions & 0 deletions ui/containers/cntdialogs/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const (
createContainerDNSSearchFieldFocus
createContainerImageVolumeFieldFocus
createContainerVolumeFieldFocus
createContainerMountFieldFocus
containerHealthCmdFieldFocus
containerHealthStartupCmdFieldFocus
containerHealthOnFailureFieldFocus
Expand Down Expand Up @@ -127,6 +128,7 @@ type ContainerCreateDialog struct {
containerHealthStartupTimeoutField *tview.InputField
containerVolumeField *tview.InputField
containerImageVolumeField *tview.DropDown
containerMountField *tview.InputField
cancelHandler func()
createHandler func()
}
Expand Down Expand Up @@ -179,6 +181,7 @@ func NewContainerCreateDialog() *ContainerCreateDialog {
containerDNSSearchField: tview.NewInputField(),
containerVolumeField: tview.NewInputField(),
containerImageVolumeField: tview.NewDropDown(),
containerMountField: tview.NewInputField(),
containerHealthCmdField: tview.NewInputField(),
containerHealthIntervalField: tview.NewInputField(),
containerHealthOnFailureField: tview.NewDropDown(),
Expand Down Expand Up @@ -657,11 +660,20 @@ func (d *ContainerCreateDialog) setupVolumePageUI() {
d.containerImageVolumeField.SetListStyles(ddUnselectedStyle, ddselectedStyle)
d.containerImageVolumeField.SetFieldBackgroundColor(inputFieldBgColor)

// mounts
d.containerMountField.SetLabel("mount:")
d.containerMountField.SetLabelWidth(volumePageLabelWidth)
d.containerMountField.SetBackgroundColor(bgColor)
d.containerMountField.SetLabelColor(style.DialogFgColor)
d.containerMountField.SetFieldBackgroundColor(inputFieldBgColor)

// volume settings page
d.volumePage.SetDirection(tview.FlexRow)
d.volumePage.AddItem(d.containerVolumeField, 1, 0, true)
d.volumePage.AddItem(utils.EmptyBoxSpace(bgColor), 1, 0, true)
d.volumePage.AddItem(d.containerImageVolumeField, 1, 0, true)
d.volumePage.AddItem(utils.EmptyBoxSpace(bgColor), 1, 0, true)
d.volumePage.AddItem(d.containerMountField, 1, 0, true)
d.volumePage.SetBackgroundColor(bgColor)
}

Expand Down Expand Up @@ -797,6 +809,8 @@ func (d *ContainerCreateDialog) Focus(delegate func(p tview.Primitive)) {
delegate(d.containerVolumeField)
case createContainerImageVolumeFieldFocus:
delegate(d.containerImageVolumeField)
case createContainerMountFieldFocus:
delegate(d.containerMountField)
// health page
case containerHealthCmdFieldFocus:
delegate(d.containerHealthCmdField)
Expand Down Expand Up @@ -1095,6 +1109,7 @@ func (d *ContainerCreateDialog) initData() {
d.containerDNSSearchField.SetText("")
d.containerDNSOptionsField.SetText("")
d.containerVolumeField.SetText("")
d.containerMountField.SetText("")
d.containerImageVolumeField.SetOptions(imageVolumeOptions, nil)
d.containerImageVolumeField.SetCurrentOption(0)

Expand Down Expand Up @@ -1203,6 +1218,8 @@ func (d *ContainerCreateDialog) setHealthSettingsPageNextFocus() {
func (d *ContainerCreateDialog) setVolumeSettingsPageNextFocus() {
if d.containerVolumeField.HasFocus() {
d.focusElement = createContainerImageVolumeFieldFocus
} else if d.containerImageVolumeField.HasFocus() {
d.focusElement = createContainerMountFieldFocus
} else {
d.focusElement = createContainerFormFocus
}
Expand Down Expand Up @@ -1296,6 +1313,7 @@ func (d *ContainerCreateDialog) ContainerCreateOptions() containers.CreateOption
DNSSearchDomain: dnsSearchDomains,
Volume: d.containerVolumeField.GetText(),
ImageVolume: imageVolume,
Mount: d.containerMountField.GetText(),
SelinuxOpts: selinuxOpts,
ApparmorProfile: d.containerApparmorField.GetText(),
Seccomp: d.containerSeccompField.GetText(),
Expand Down

0 comments on commit 54dc570

Please sign in to comment.