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

RemoveMount does not work #80

Open
liangjingtao11 opened this issue May 7, 2024 · 3 comments
Open

RemoveMount does not work #80

liangjingtao11 opened this issue May 7, 2024 · 3 comments
Assignees
Milestone

Comments

@liangjingtao11
Copy link

liangjingtao11 commented May 7, 2024

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?
@liangjingtao11
Copy link
Author

liangjingtao11 commented May 11, 2024

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

@klihub
Copy link
Member

klihub commented May 14, 2024

Thanks, both for the report and the analysis !

@liangjingtao11
Copy link
Author

/assign @liangjingtao11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants