podlet icon indicating copy to clipboard operation
podlet copied to clipboard

error: unexpected argument '--name' found

Open strzinek opened this issue 1 year ago • 2 comments

When invoking the podlet podman pod create --name test, which is the first example of podman pod create usage in the official podman documentation, the command fails with an error in the title.

strzinek avatar Jun 10 '24 18:06 strzinek

same error also appears when using podlet generate pod pod_id command.

$ podlet generate pod c4a2

Error: 
   0: error creating Quadlet file(s) from an existing object
   1: error parsing `podman pod create` command from `["podman", "pod", "create", "--name", "db0", "--publish", "8080:80", "--publish", "3306:3306"]`
   2: error: unexpected argument '--name' found

        tip: to pass '--name' as a value, use '-- --name'

   2: Usage: create [OPTIONS] <NAME>

      For more information, try '--help'.
   2: 

Location:
   src/cli/generate.rs:277

Backtrace omitted. Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.

error only occurs if pod is created with --name flag. podman pod create --publish 8080:80 --publish 3306:3306 db0 command works fine, however it is supposed to work even with the --name flag, right?

pienapin avatar Jun 18 '24 02:06 pienapin

Running into the same problem. Or rather, the pod has a different name when started via systemd than what it was created with. Thus, all container units that were built by podlet with -pod $NAME suddenly point to the wrong name.

rapus95 avatar Jul 01 '24 00:07 rapus95

I'm also having an issue with this - I cannot seem to get podlet to create the file with PodName=.

podlet podman pod create --name test
error: unexpected argument '--name' found

podlet podman pod create test
# test.pod
[Pod]

This causes confusion because even though the correct name is known in example 1, PodName= is still not passed so it gets a name like systemd-test.pod

Similar command for a container works as expected

podlet podman run --name test testimage
# test.container
[Container]
ContainerName=test
Image=testimage

spmfox avatar Aug 24 '24 16:08 spmfox

I've found that podlet does not support a good number of quadlet options and created a podlet-helper.sh script that fills in some of the gaps. Here are a few sed commands I use to add PodName and some others.

function fix_podlet_pod()
{
	local quadlet_path="${1:-}"
	local pod_name="${2:-}"

	[ "$#" -eq 2 ] || usage
	[ -f "$quadlet_path" ] || die "$quadlet_path: No such file"
	[ -n "$pod_name" ] || die "$pod_name: Pod name is required"

	if grep -q "PodName=" "$quadlet_path"; then
		die "$quadlet_path: PodName option is defined; fixed already?"
	fi

	if grep -q "NetworkAlias=" "$quadlet_path"; then
		die "$quadlet_path: NetworkAlias option is defined; fixed already?"
	fi

	# Define `PodName` (most important and podlet doesn't support it!?)
	sed -i -r "s/\\[Pod\\]/[Pod]\nPodName=${pod_name}/" "$quadlet_path"

	# Move `--network-alias` into `NetworkAlias` option
	sed -i -r 's/PodmanArgs=(.*)--network-alias ([^ ]+)\s?(.*)/NetworkAlias=\2\nPodmanArgs=\1\3/' "$quadlet_path"

	# Remove `PodmanArgs` if empty
	sed -i -r '/^PodmanArgs=$/d' "$quadlet_path"
}

function fix_podlet_container()
{
	local quadlet_path="${1:-}"
	local pod_quadlet_basename="${2:-}"

	[ "$#" -eq 2 ] || usage
	[ -f "$quadlet_path" ] || die "$quadlet_path: No such file"
	[ -n "$pod_quadlet_basename" ] || die "$pod_quadlet_basename: Pod quadlet basename is required"

	if grep -q "Pod=" "$quadlet_path"; then
		die "$quadlet_path: PodName option is defined; fixed already?"
	fi

	# Define `Pod` (most important and podlet doesn't support it!?)
	sed -i -r "s/PodmanArgs=(.*)--pod ([^ ]+)\s?(.*)/Pod=${pod_quadlet_basename}\nPodmanArgs=\1\3/" "$quadlet_path"

	# Remove `PodmanArgs` if empty
	sed -i -r '/^PodmanArgs=$/d' "$quadlet_path"
}

function fix_podlet_network()
{
	local quadlet_path="${1:-}"
	local network_name="${2:-}"

	[ "$#" -eq 2 ] || usage
	[ -f "$quadlet_path" ] || die "$quadlet_path: No such file"
	[ -n "$network_name" ] || die "$network_name: Network name is required"

	if grep -q "NetworkName=" "$quadlet_path"; then
		die "$quadlet_path: NetworkName option is defined; fixed already?"
	fi

	# Define `NetworkName` (most important and podlet doesn't support it!?)
	sed -i -r "s/\\[Network\\]/[Network]\nNetworkName=${network_name}/" "$quadlet_path"
}

lovette avatar Aug 29 '24 13:08 lovette

A question for you all, do you think the PodName= option in .pod Quadlet files should always be set by Podlet? Or should it only be set when the --name flag is used?

k9withabone avatar Sep 14 '24 00:09 k9withabone

I'd say only when --name is used, that way default behavior prevails otherwise.

lovette avatar Sep 17 '24 15:09 lovette