Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes: fix mount removal in adjustments, add a test case for it. #107

Merged
merged 2 commits into from
Sep 18, 2024
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
19 changes: 19 additions & 0 deletions pkg/adaptation/adaptation_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,9 @@ var _ = Describe("Plugin container creation adjustments", func() {
}
a.AddMount(mnt)

case "remove mount":
a.RemoveMount("/remove/test/destination")

case "environment":
if overwrite {
a.RemoveEnv("key")
Expand Down Expand Up @@ -560,6 +563,13 @@ var _ = Describe("Plugin container creation adjustments", func() {
PodSandboxId: "pod0",
Name: "ctr0",
State: api.ContainerState_CONTAINER_CREATED, // XXX FIXME-kludge
Mounts: []*api.Mount{
{
Type: "bind",
Source: "/remove/test",
Destination: "/remove/test/destination",
},
},
}
)

Expand Down Expand Up @@ -599,6 +609,15 @@ var _ = Describe("Plugin container creation adjustments", func() {
},
},
),
Entry("remove a mount", "remove mount",
&api.ContainerAdjustment{
Mounts: []*api.Mount{
{
Destination: api.MarkForRemoval("/remove/test/destination"),
},
},
},
),
Entry("adjust environment", "environment",
&api.ContainerAdjustment{
Env: []*api.KeyValue{
Expand Down
7 changes: 7 additions & 0 deletions pkg/adaptation/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,13 @@ func (r *result) adjustMounts(mounts []*Mount, plugin string) error {
r.reply.adjust.Mounts = append(r.reply.adjust.Mounts, m)
}

// next, apply deletions with no corresponding additions
for _, m := range del {
if _, ok := mod[api.ClearRemovalMarker(m.Destination)]; !ok {
r.reply.adjust.Mounts = append(r.reply.adjust.Mounts, m)
}
}

// finally, apply additions/modifications to plugin container creation request
create.Container.Mounts = append(create.Container.Mounts, add...)

Expand Down
11 changes: 11 additions & 0 deletions pkg/api/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,14 @@ func IsMarkedForRemoval(key string) (string, bool) {
func MarkForRemoval(key string) string {
return "-" + key
}

// ClearRemovalMarker returns a key cleared from any removal marker.
func ClearRemovalMarker(key string) string {
if key == "" {
return ""
}
if key[0] == '-' {
return key[1:]
}
return key
}
Loading