Skip to content

Commit a547a89

Browse files
committed
fix: exclude oci labels when cloning a container
1 parent 5c7fb2f commit a547a89

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

pkg/container/container.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1307,7 +1307,8 @@ func CloneContainerConfig(ref *container.Config, opts CloneOptions) *container.C
13071307
Tty: ref.Tty,
13081308
ExposedPorts: ref.ExposedPorts,
13091309
Domainname: ref.Domainname,
1310-
Labels: ref.Labels,
1310+
// Don't copy oci labels as they are included in the image itself
1311+
Labels: FilterLabels(ref.Labels, []string{"org.opencontainers."}),
13111312
}
13121313
if len(opts.Cmd) > 0 {
13131314
clonedConfig.Cmd = opts.Cmd
@@ -1396,3 +1397,14 @@ func FormatLabels(labels []string) map[string]string {
13961397
}
13971398
return labelMap
13981399
}
1400+
1401+
func FilterLabels(l map[string]string, exclude []string) map[string]string {
1402+
filtered := make(map[string]string)
1403+
1404+
for k, v := range l {
1405+
if !strings.HasPrefix(k, "org.opencontainers.") {
1406+
filtered[k] = v
1407+
}
1408+
}
1409+
return filtered
1410+
}

pkg/container/container_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package container
33
import (
44
"context"
55
"testing"
6+
7+
"github.com/stretchr/testify/assert"
68
)
79

810
func Test_ResolveDockerIOImage(t *testing.T) {
@@ -34,6 +36,18 @@ func Test_ResolveDockerIOImage(t *testing.T) {
3436

3537
}
3638

39+
func Test_FilterLabels(t *testing.T) {
40+
in := map[string]string{
41+
"foo": "bar",
42+
"org.opencontainers.image.authors": "thin-edge.io",
43+
"org.opencontainers.image.version": "1.2.3",
44+
}
45+
out := FilterLabels(in, []string{"org.opencontainers."})
46+
47+
assert.Len(t, out, 1)
48+
assert.Equal(t, out["foo"], "bar")
49+
}
50+
3751
func Test_PruneIMages(t *testing.T) {
3852
client, err := NewContainerClient()
3953
if err != nil {

0 commit comments

Comments
 (0)