Skip to content

Commit ee5f453

Browse files
authored
Merge pull request #256 from samuelkarp/api-namespaces-strip
adaptation: ensure namespace adjustment is tested
2 parents 0094756 + 56a6375 commit ee5f453

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

pkg/adaptation/adaptation_suite_test.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ import (
3434
. "github.com/onsi/ginkgo/v2"
3535
. "github.com/onsi/gomega"
3636

37+
rspec "github.com/opencontainers/runtime-spec/specs-go"
38+
3739
nri "github.com/containerd/nri/pkg/adaptation"
3840
"github.com/containerd/nri/pkg/api"
3941
"github.com/containerd/nri/pkg/plugin"
4042
validator "github.com/containerd/nri/plugins/default-validator/builtin"
41-
rspec "github.com/opencontainers/runtime-spec/specs-go"
4243
)
4344

4445
var _ = Describe("Configuration", func() {
@@ -508,6 +509,7 @@ var _ = Describe("Plugin container creation adjustments", func() {
508509
case "namespace":
509510
ns := &api.LinuxNamespace{
510511
Type: "cgroup",
512+
Path: "/var/run/cgroupns/replaced",
511513
}
512514
a.AddOrReplaceNamespace(ns)
513515

@@ -678,6 +680,12 @@ var _ = Describe("Plugin container creation adjustments", func() {
678680
UseHierarchy: api.Bool(false),
679681
},
680682
},
683+
Namespaces: []*api.LinuxNamespace{
684+
{
685+
Type: "cgroup",
686+
Path: "/var/run/cgroupns/original",
687+
},
688+
},
681689
},
682690
}
683691
)
@@ -779,6 +787,7 @@ var _ = Describe("Plugin container creation adjustments", func() {
779787
Namespaces: []*api.LinuxNamespace{
780788
{
781789
Type: "cgroup",
790+
Path: "/var/run/cgroupns/replaced",
782791
},
783792
},
784793
},

pkg/api/strip.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@ func (l *LinuxContainerAdjustment) Strip() *LinuxContainerAdjustment {
116116
empty = false
117117
}
118118

119+
if len(l.Namespaces) == 0 {
120+
l.Namespaces = nil
121+
} else {
122+
empty = false
123+
}
124+
119125
if empty {
120126
return nil
121127
}

0 commit comments

Comments
 (0)