mirror of
https://github.com/containers/podman.git
synced 2025-06-28 22:53:21 +08:00
generate systemd: improve pod-flags filter
When generating systemd unit for pods, we need to remove certain pod-related flags from the containers' create commands. Make sure to account for all the syntax including a single argument with key and value being split by `=`. Fixes: #6766 Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
This commit is contained in:
@ -1,6 +1,8 @@
|
|||||||
package generate
|
package generate
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -44,6 +46,9 @@ func filterPodFlags(command []string) []string {
|
|||||||
i++
|
i++
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if strings.HasPrefix(s, "--pod=") || strings.HasPrefix(s, "--pod-id-file=") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
processed = append(processed, s)
|
processed = append(processed, s)
|
||||||
}
|
}
|
||||||
return processed
|
return processed
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package generate
|
package generate
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
@ -14,12 +15,16 @@ func TestFilterPodFlags(t *testing.T) {
|
|||||||
{[]string{"podman", "pod", "create"}},
|
{[]string{"podman", "pod", "create"}},
|
||||||
{[]string{"podman", "pod", "create", "--name", "foo"}},
|
{[]string{"podman", "pod", "create", "--name", "foo"}},
|
||||||
{[]string{"podman", "pod", "create", "--pod-id-file", "foo"}},
|
{[]string{"podman", "pod", "create", "--pod-id-file", "foo"}},
|
||||||
|
{[]string{"podman", "pod", "create", "--pod-id-file=foo"}},
|
||||||
{[]string{"podman", "run", "--pod", "foo"}},
|
{[]string{"podman", "run", "--pod", "foo"}},
|
||||||
|
{[]string{"podman", "run", "--pod=foo"}},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
processed := filterPodFlags(test.input)
|
processed := filterPodFlags(test.input)
|
||||||
assert.NotContains(t, processed, "--pod-id-file")
|
for _, s := range processed {
|
||||||
assert.NotContains(t, processed, "--pod")
|
assert.False(t, strings.HasPrefix(s, "--pod-id-file"))
|
||||||
|
assert.False(t, strings.HasPrefix(s, "--pod"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user