Skip to content

Commit

Permalink
generate systemd: improve pod-flags filter
Browse files Browse the repository at this point in the history
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: containers#6766
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
  • Loading branch information
vrothberg committed Jun 25, 2020
1 parent 35cca19 commit 2fed50f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions pkg/systemd/generate/common.go
@@ -1,6 +1,8 @@
package generate

import (
"strings"

"github.com/pkg/errors"
)

Expand Down Expand Up @@ -44,6 +46,9 @@ func filterPodFlags(command []string) []string {
i++
continue
}
if strings.HasPrefix(s, "--pod=") || strings.HasPrefix(s, "--pod-id-file=") {
continue
}
processed = append(processed, s)
}
return processed
Expand Down
9 changes: 7 additions & 2 deletions pkg/systemd/generate/common_test.go
@@ -1,6 +1,7 @@
package generate

import (
"strings"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -14,12 +15,16 @@ func TestFilterPodFlags(t *testing.T) {
{[]string{"podman", "pod", "create"}},
{[]string{"podman", "pod", "create", "--name", "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"}},
}

for _, test := range tests {
processed := filterPodFlags(test.input)
assert.NotContains(t, processed, "--pod-id-file")
assert.NotContains(t, processed, "--pod")
for _, s := range processed {
assert.False(t, strings.HasPrefix(s, "--pod-id-file"))
assert.False(t, strings.HasPrefix(s, "--pod"))
}
}
}

0 comments on commit 2fed50f

Please sign in to comment.