Skip to content

container: Remove RWLayer#46771

Closed
vvoland wants to merge 1 commit intomoby:masterfrom
vvoland:container-remove-rwlayer
Closed

container: Remove RWLayer#46771
vvoland wants to merge 1 commit intomoby:masterfrom
vvoland:container-remove-rwlayer

Conversation

@vvoland
Copy link
Copy Markdown
Contributor

@vvoland vvoland commented Nov 3, 2023

Don't store the RWLayer in the Container object - it's an implementation detail of the graphdriver ImageService and it shouldn't be exposed. The ID of the layer is always the same as the container ID so it can be used to move the direct RWLayer accesses to the graphdriver's ImageService implementation.

- What I did
Removed RWLayer field from Container struct and removed some ugly if daemon.UsesSnapshotter() branches.

- How I did it
Instead of storing RWLayer and accessing it when needed, obtain it directly from the layerStore. The ID of the RW layer always matches the container ID.

- How to verify it
CI.

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

@vvoland vvoland added area/daemon Core Engine kind/refactor PR's that refactor, or clean-up code containerd-integration Issues and PRs related to containerd integration labels Nov 3, 2023
@vvoland vvoland self-assigned this Nov 3, 2023
@vvoland vvoland force-pushed the container-remove-rwlayer branch 4 times, most recently from 7920ea3 to d309522 Compare November 3, 2023 17:52
@vvoland vvoland force-pushed the container-remove-rwlayer branch from d309522 to 1154e9b Compare November 20, 2023 11:13
Don't store the RWLayer in the Container object - it's an implementation
detail of the graphdriver ImageService and it shouldn't be exposed.
The ID of the layer is always the same as the container ID so it can be
used to move the direct RWLayer accesses to the graphdriver's
ImageService implementation.

Signed-off-by: Paweł Gronowski <[email protected]>
Copy link
Copy Markdown
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some rambling from glancing over the changes.


// CreateLayer creates a filesystem layer for a container.
// called from create.go
// TODO: accept an opt struct instead of container?
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see this TODO was removed; as we're changing the signature, is that still something we should consider?

}

// ReleaseLayer releases a layer allowing it to be removed
// ReleaseLayer releases the snapshot allowing it to be removed.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is confusing; ReleaseLayer releasing a snapshot (not a "layer"). How deeply is this function engrained elsewhere? Should we either have separate functions for containerd <--> graphdriver, or would a different (more generic) name work for the context it's used in?

Comment on lines +125 to +129
ls := i.client.LeasesService()
lease := leases.Lease{
ID: ctr.ID,
}
err := ls.Delete(ctx, lease, leases.SynchronousDelete)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit; I guess we can inline all of the above here (I think that's still readable, even if we inline the client?)

Suggested change
ls := i.client.LeasesService()
lease := leases.Lease{
ID: ctr.ID,
}
err := ls.Delete(ctx, lease, leases.SynchronousDelete)
err := i.client.LeasesService().Delete(ctx, leases.Lease{ID: ctr.ID}, leases.SynchronousDelete)

Comment on lines +130 to +133
if err != nil && cerrdefs.IsNotFound(err) {
return nil
}
return err
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing the err != nil is even redundant here (but perhaps more readable this way 😅)

Alternatively, we could do the reverse, which would make the final return explicit that there's no error;

Suggested change
if err != nil && cerrdefs.IsNotFound(err) {
return nil
}
return err
if err != nil && !cerrdefs.IsNotFound(err) {
return err
}
return nil

@@ -86,10 +87,8 @@ func (i *ImageService) CountImages(ctx context.Context) int {
}

// CreateLayer creates a filesystem layer for a container.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the same applies here; if this is creating a snapshot.

Wondering if we should consider removing the abstraction, and instead had separate methods for "Snapshot" vs "graphdriver".

Comment thread daemon/images/service.go
// called from create.go
// TODO: accept an opt struct instead of container?
func (i *ImageService) CreateLayer(container *container.Container, initFunc layer.MountInit) (layer.RWLayer, error) {
func (i *ImageService) CreateLayer(ctx context.Context, container *container.Container, _ string, _ *ocispec.Platform, setupInit func(string) error) error {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to the "abstraction". From this it really looks like the abstraction no longer really "works". We're now have to change the signature to effectively be for "snapshot", and more and more stubbing for graphdrivers. Perhaps diversifying starts to be a better options 🤔 (which would also allow for more descriptive naming, clearer on intent)

Comment thread daemon/inspect_test.go
is "gotest.tools/v3/assert/cmp"
)

func TestGetInspectData(t *testing.T) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test was no longer relevant? Or is there something else covering this?

@vvoland vvoland mentioned this pull request Dec 17, 2024
@thaJeztah
Copy link
Copy Markdown
Member

@thaJeztah thaJeztah closed this Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/daemon Core Engine containerd-integration Issues and PRs related to containerd integration kind/refactor PR's that refactor, or clean-up code status/2-code-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants