Skip to content
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
14 changes: 13 additions & 1 deletion pkg/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -1307,7 +1307,8 @@ func CloneContainerConfig(ref *container.Config, opts CloneOptions) *container.C
Tty: ref.Tty,
ExposedPorts: ref.ExposedPorts,
Domainname: ref.Domainname,
Labels: ref.Labels,
// Don't copy oci labels as they are included in the image itself
Labels: FilterLabels(ref.Labels, []string{"org.opencontainers."}),
}
if len(opts.Cmd) > 0 {
clonedConfig.Cmd = opts.Cmd
Expand Down Expand Up @@ -1396,3 +1397,14 @@ func FormatLabels(labels []string) map[string]string {
}
return labelMap
}

func FilterLabels(l map[string]string, exclude []string) map[string]string {
filtered := make(map[string]string)

for k, v := range l {
if !strings.HasPrefix(k, "org.opencontainers.") {
filtered[k] = v
}
}
return filtered
}
14 changes: 14 additions & 0 deletions pkg/container/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package container
import (
"context"
"testing"

"github.com/stretchr/testify/assert"
)

func Test_ResolveDockerIOImage(t *testing.T) {
Expand Down Expand Up @@ -34,6 +36,18 @@ func Test_ResolveDockerIOImage(t *testing.T) {

}

func Test_FilterLabels(t *testing.T) {
in := map[string]string{
"foo": "bar",
"org.opencontainers.image.authors": "thin-edge.io",
"org.opencontainers.image.version": "1.2.3",
}
out := FilterLabels(in, []string{"org.opencontainers."})

assert.Len(t, out, 1)
assert.Equal(t, out["foo"], "bar")
}

func Test_PruneIMages(t *testing.T) {
client, err := NewContainerClient()
if err != nil {
Expand Down
Loading