Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use inputfield for container create volume option #379

Merged
merged 1 commit into from
Nov 25, 2023
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
5 changes: 1 addition & 4 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,10 @@ jobs:
container:
image: fedora:latest
steps:
- uses: actions/checkout@v4
- run: |
# Preparing and running unit tests #
dnf -y install git-core golang glibc-static git-core wget gcc make
git clone https://github.com/${GITHUB_REPOSITORY}.git
cd podman-tui
PR_HEAD=$(echo ${GITHUB_REF} | sed 's/merge/head/g')
git pull origin ${PR_HEAD}
bash ./hack/install_dep.sh
export GOBIN=$(pwd)/bin/
make .install.ginkgo
Expand Down
15 changes: 2 additions & 13 deletions pdcs/containers/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package containers
import (
"net"
"strconv"
"strings"

"github.com/containers/common/libnetwork/types"
"github.com/containers/podman-tui/pdcs/registry"
"github.com/containers/podman-tui/pdcs/utils"
"github.com/containers/podman/v4/libpod/define"
"github.com/containers/podman/v4/pkg/bindings/containers"
"github.com/containers/podman/v4/pkg/bindings/volumes"
"github.com/containers/podman/v4/pkg/domain/entities"
"github.com/containers/podman/v4/pkg/specgen"
"github.com/containers/podman/v4/pkg/specgenutil"
Expand Down Expand Up @@ -98,18 +98,7 @@ func Create(opts CreateOptions) ([]string, error) { //nolint:cyclop
}

if opts.Volume != "" {
// get volume path
volFilter := make(map[string][]string)
volFilter["name"] = []string{opts.Volume}

volResponse, err := volumes.List(conn, new(volumes.ListOptions).WithFilters(volFilter))
if err != nil {
return warningResponse, err
}

if len(volResponse) > 0 {
createOptions.Volume = []string{volResponse[0].Mountpoint}
}
createOptions.Volume = strings.Split(opts.Volume, ",")
}

createOptions.ImageVolume = opts.ImageVolume
Expand Down
8 changes: 3 additions & 5 deletions test/005-container.bats
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ load helpers_tui
pod_index=$(podman pod ls --sort name --format "{{ .Name }}" | nl -v 1 | grep "$TEST_CONTAINER_POD_NAME" | awk '{print $1}')
image_index=$(podman image ls --sort repository --noheading | nl -v 1 | grep 'httpd ' | awk '{print $1}')
net_index=$(podman network ls -q | nl -v 1 | grep "$TEST_CONTAINER_NETWORK_NAME" | awk '{print $1}')
vol_index=$(podman volume ls -q | nl -v 1 | grep "$TEST_CONTAINER_VOLUME_NAME" | awk '{print $1}')


# switch to containers view
Expand Down Expand Up @@ -73,9 +72,8 @@ load helpers_tui

# switch to "volumes settings" create view
# select volume from dropdown widget
podman_tui_send_inputs "Down" "Tab" "Down"
podman_tui_select_item $vol_index
podman_tui_send_inputs "Enter"
podman_tui_send_inputs "Down" "Tab"
podman_tui_send_inputs "${TEST_CONTAINER_VOLUME_NAME}:${TEST_CONTAINER_VOLUME_MOUNT_POINT}:rw"
sleep 1

# go to "Create" button and press Enter
Expand Down Expand Up @@ -107,7 +105,7 @@ load helpers_tui

assert "$cnt_pod_name" =~ "$TEST_CONTAINER_POD_NAME" "expected container pod: $TEST_CONTAINER_POD_NAME"

assert "$cnt_mounts" =~ "$TEST_CONTAINER_VOLUME_NAME" "expected container volume: $TEST_CONTAINER_VOLUME_NAME"
assert "$cnt_mounts" =~ "$TEST_CONTAINER_VOLUME_MOUNT_POINT" "expected container volume mount point: $TEST_CONTAINER_VOLUME_MOUNT_POINT"
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
1 change: 1 addition & 0 deletions test/helpers_tui.bash
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ 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_COMMIT_IMAGE_NAME="${TEST_NAME}_commited_image"

TEST_CONTAINER_PORT="8888:80"
Expand Down
26 changes: 8 additions & 18 deletions ui/containers/cntdialogs/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ type ContainerCreateDialog struct {
containerHealthStartupRetriesField *tview.InputField
containerHealthStartupSuccessField *tview.InputField
containerHealthStartupTimeoutField *tview.InputField
containerVolumeField *tview.DropDown
containerVolumeField *tview.InputField
containerImageVolumeField *tview.DropDown
cancelHandler func()
createHandler func()
Expand Down Expand Up @@ -177,7 +177,7 @@ func NewContainerCreateDialog() *ContainerCreateDialog {
containerDNSServersField: tview.NewInputField(),
containerDNSOptionsField: tview.NewInputField(),
containerDNSSearchField: tview.NewInputField(),
containerVolumeField: tview.NewDropDown(),
containerVolumeField: tview.NewInputField(),
containerImageVolumeField: tview.NewDropDown(),
containerHealthCmdField: tview.NewInputField(),
containerHealthIntervalField: tview.NewInputField(),
Expand Down Expand Up @@ -647,7 +647,6 @@ func (d *ContainerCreateDialog) setupVolumePageUI() {
d.containerVolumeField.SetLabelWidth(volumePageLabelWidth)
d.containerVolumeField.SetBackgroundColor(bgColor)
d.containerVolumeField.SetLabelColor(style.DialogFgColor)
d.containerVolumeField.SetListStyles(ddUnselectedStyle, ddselectedStyle)
d.containerVolumeField.SetFieldBackgroundColor(inputFieldBgColor)

// image volume
Expand Down Expand Up @@ -698,13 +697,12 @@ func (d *ContainerCreateDialog) dropdownHasFocus() bool {
if d.containerImageField.HasFocus() || d.containerPodField.HasFocus() {
return true
}
if d.containerVolumeField.HasFocus() || d.containerImageVolumeField.HasFocus() {
return true
}
if d.containerNetworkField.HasFocus() || d.containerHealthOnFailureField.HasFocus() {

if d.containerNetworkField.HasFocus() || d.containerImageVolumeField.HasFocus() {
return true
}
return false

return d.containerHealthOnFailureField.HasFocus()
}

// Focus is called when this primitive receives focus.
Expand Down Expand Up @@ -844,11 +842,6 @@ func (d *ContainerCreateDialog) initCustomInputHanlers() {
event = utils.ParseKeyEventKey(event)
return event
})
// container volume dropdown
d.containerVolumeField.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
event = utils.ParseKeyEventKey(event)
return event
})
// container image volume dropdown
d.containerImageVolumeField.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
event = utils.ParseKeyEventKey(event)
Expand Down Expand Up @@ -1101,8 +1094,7 @@ func (d *ContainerCreateDialog) initData() {
d.containerDNSServersField.SetText("")
d.containerDNSSearchField.SetText("")
d.containerDNSOptionsField.SetText("")
d.containerVolumeField.SetOptions(volumeOptions, nil)
d.containerVolumeField.SetCurrentOption(0)
d.containerVolumeField.SetText("")
d.containerImageVolumeField.SetOptions(imageVolumeOptions, nil)
d.containerImageVolumeField.SetCurrentOption(0)

Expand Down Expand Up @@ -1227,7 +1219,6 @@ func (d *ContainerCreateDialog) ContainerCreateOptions() containers.CreateOption
dnsSearchDomains []string
publish []string
expose []string
volume string
imageVolume string
selinuxOpts []string
)
Expand Down Expand Up @@ -1274,7 +1265,6 @@ func (d *ContainerCreateDialog) ContainerCreateOptions() containers.CreateOption
dnsSearchDomains = append(dnsSearchDomains, ds)
}
}
_, volume = d.containerVolumeField.GetCurrentOption()
_, imageVolume = d.containerImageVolumeField.GetCurrentOption()

// security options
Expand Down Expand Up @@ -1304,7 +1294,7 @@ func (d *ContainerCreateDialog) ContainerCreateOptions() containers.CreateOption
DNSServer: dnsServers,
DNSOptions: dnsOptions,
DNSSearchDomain: dnsSearchDomains,
Volume: volume,
Volume: d.containerVolumeField.GetText(),
ImageVolume: imageVolume,
SelinuxOpts: selinuxOpts,
ApparmorProfile: d.containerApparmorField.GetText(),
Expand Down
Loading