Skip to content

Commit

Permalink
adaptation: fix mount removal in adjustments.
Browse files Browse the repository at this point in the history
When a container mount is removed without replacing it
by another mount to the same destination, NRI needs to
pass the deletion to the runtime among the adjustments.
Otherwise the mount will not get removed.

Co-authored-by: Krisztian Litkey <[email protected]>
Signed-off-by: jingtao.liang <[email protected]>
  • Loading branch information
jingtaoliang and klihub committed Sep 6, 2024
1 parent e1d8260 commit 0d3b376
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
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
}

0 comments on commit 0d3b376

Please sign in to comment.