nri
nri copied to clipboard
RemoveMount does not work
containerd version: v1.7.14 nri version: 0.6.1
i want to remove Specific mount using this code in nri
for _, m := range container.Mounts {
if strings.HasSuffix(m.Source, mountSuffix) {
adjust.RemoveMount(m.Destination)
}
}```
but after pod created,Nothing has changed. May I ask if I used the wrong way?
nri code:
pkg/adaption/result.go
func (r *result) adjustMounts(mounts []*Mount, plugin string) error {
if len(mounts) == 0 {
return nil
}
create, id := r.request.create, r.request.create.Container.Id
// first split removals from the rest of adjustments
add := []*Mount{}
del := map[string]*Mount{}
mod := map[string]*Mount{}
for _, m := range mounts {
if key, marked := m.IsMarkedForRemoval(); marked {
del[key] = m
} else {
add = append(add, m)
mod[key] = m
}
}
// next remove marked mounts from collected adjustments
cleared := []*Mount{}
for _, m := range r.reply.adjust.Mounts {
if _, removed := del[m.Destination]; removed {
r.owners.clearMount(id, m.Destination)
continue
}
cleared = append(cleared, m)
}
r.reply.adjust.Mounts = cleared
// next remove marked and modified mounts from container creation request
cleared = []*Mount{}
for _, m := range create.Container.Mounts {
if _, removed := del[m.Destination]; removed {
continue
}
if _, modified := mod[m.Destination]; modified {
continue
}
cleared = append(cleared, m)
}
create.Container.Mounts = cleared
// next, apply additions/modifications to collected adjustments
for _, m := range add {
if err := r.owners.claimMount(id, m.Destination, plugin); err != nil {
return err
}
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...)
return nil
}
it only append mount from add: r.reply.adjust.Mounts = append(r.reply.adjust.Mounts, m). That's why del mount was not passed to containerd
Thanks, both for the report and the analysis !
/assign @liangjingtao11