Skip to content

Commit

Permalink
Merge pull request #119 from thin-edge/fix-exclude-oci-labels
Browse files Browse the repository at this point in the history
fix: exclude oci labels when cloning a container
  • Loading branch information
reubenmiller authored Jan 26, 2025
2 parents 5c7fb2f + a547a89 commit 2d38b93
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
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

0 comments on commit 2d38b93

Please sign in to comment.