-
Notifications
You must be signed in to change notification settings - Fork 2
feat: support stargz snapshotter for devbox with lvm powerd #29
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
base: v1.7
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /* | ||
| Copyright The containerd Authors. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package devboxsnapshotter | ||
|
|
||
| const ( | ||
| StargzSnapshotter = "stargz" | ||
| SealosDevboxContentIDAnnotation = "devbox.sealos.io/content-id" | ||
| SealosDevboxStorageLimitAnnotation = "devbox.sealos.io/storage-limit" | ||
| ) | ||
|
|
||
| // LabelsFromAnnotations keeps only the annotations used by the devbox-backed | ||
| // writable-layer flow. containerd.WithNewSnapshot will translate these labels | ||
| // to the snapshotter-specific containerd.io/snapshot/devbox-* keys when needed. | ||
| func LabelsFromAnnotations(annotations map[string]string) map[string]string { | ||
| if len(annotations) == 0 { | ||
| return nil | ||
| } | ||
|
|
||
| labels := make(map[string]string) | ||
| if contentID := annotations[SealosDevboxContentIDAnnotation]; contentID != "" { | ||
| labels[SealosDevboxContentIDAnnotation] = contentID | ||
| } | ||
| if storageLimit := annotations[SealosDevboxStorageLimitAnnotation]; storageLimit != "" { | ||
| labels[SealosDevboxStorageLimitAnnotation] = storageLimit | ||
| } | ||
| return labels | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /* | ||
| Copyright The containerd Authors. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package sbserver | ||
|
|
||
| import "github.com/containerd/containerd/pkg/cri/internal/devboxsnapshotter" | ||
|
|
||
| const devboxSnapshotter = "devbox" | ||
|
|
||
| func snapshotterNeedsDevboxLabels(name string) bool { | ||
| switch name { | ||
| case devboxSnapshotter, devboxsnapshotter.StargzSnapshotter: | ||
| return true | ||
| default: | ||
| return false | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -612,9 +612,14 @@ func generateUserString(username string, uid, gid *runtime.Int64Value) (string, | |
| } | ||
|
|
||
| // snapshotterOpts returns any Linux specific snapshotter options for the rootfs snapshot | ||
| func devboxSnapshotterOpts(snapshotterName string, config *runtime.PodSandboxConfig) (snapshots.Opt, error) { | ||
| // fmt.Printf("devboxSnapshotterOpts: snapshotterName=%s, config=%+v\n", snapshotterName, config) | ||
| // add container annotations to snapshot labels | ||
| func devboxSnapshotterOpts(_ string, config *runtime.PodSandboxConfig) (snapshots.Opt, error) { | ||
| if config == nil || len(config.Annotations) == 0 { | ||
| return nil, nil | ||
| } | ||
|
|
||
| // Preserve the original devbox annotations here and let | ||
| // containerd.WithNewSnapshot translate them for snapshotters that consume | ||
| // containerd.io/snapshot/devbox-* labels. | ||
| labels := make(map[string]string) | ||
| maps.Copy(labels, config.Annotations) | ||
| return snapshots.WithLabels(labels), nil | ||
|
Comment on lines
+620
to
625
|
||
|
|
@@ -634,7 +639,7 @@ func snapshotterOpts(snapshotterName string, config *runtime.ContainerConfig, sa | |
| uid := sandboxConfig.Annotations[devboxUIDEnvKey] | ||
| if uid != "" { | ||
| snapshotOpts = append(snapshotOpts, snapshots.WithLabels(map[string]string{ | ||
| "devbox.sealos.io/uid": uid, | ||
| devboxUIDEnvKey: uid, | ||
| })) | ||
| } | ||
| return snapshotOpts, nil | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,6 +43,7 @@ import ( | |
| "github.com/containerd/containerd/pkg/cap" | ||
| "github.com/containerd/containerd/pkg/cri/annotations" | ||
| "github.com/containerd/containerd/pkg/cri/config" | ||
| "github.com/containerd/containerd/pkg/cri/internal/devboxsnapshotter" | ||
| "github.com/containerd/containerd/pkg/cri/opts" | ||
| customopts "github.com/containerd/containerd/pkg/cri/opts" | ||
| "github.com/containerd/containerd/pkg/cri/util" | ||
|
|
@@ -2285,3 +2286,51 @@ func TestSnapshotterOpts(t *testing.T) { | |
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestDevboxSnapshotterOpts(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| snapshotter string | ||
| annotations map[string]string | ||
| expectedLabels map[string]string | ||
| }{ | ||
| { | ||
| name: "stargz keeps original annotations", | ||
| snapshotter: devboxsnapshotter.StargzSnapshotter, | ||
| annotations: map[string]string{ | ||
| devboxsnapshotter.SealosDevboxContentIDAnnotation: "workspace-1", | ||
| devboxsnapshotter.SealosDevboxStorageLimitAnnotation: "20Gi", | ||
| }, | ||
|
Comment on lines
+2298
to
+2303
|
||
| expectedLabels: map[string]string{ | ||
| devboxsnapshotter.SealosDevboxContentIDAnnotation: "workspace-1", | ||
| devboxsnapshotter.SealosDevboxStorageLimitAnnotation: "20Gi", | ||
| }, | ||
| }, | ||
| { | ||
| name: "devbox snapshotter keeps original annotations only", | ||
| snapshotter: DevboxSnapshotter, | ||
| annotations: map[string]string{ | ||
| devboxsnapshotter.SealosDevboxContentIDAnnotation: "workspace-3", | ||
| devboxsnapshotter.SealosDevboxStorageLimitAnnotation: "5Gi", | ||
| }, | ||
| expectedLabels: map[string]string{ | ||
| devboxsnapshotter.SealosDevboxContentIDAnnotation: "workspace-3", | ||
| devboxsnapshotter.SealosDevboxStorageLimitAnnotation: "5Gi", | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| opt, err := devboxSnapshotterOpts(tt.snapshotter, &runtime.PodSandboxConfig{ | ||
| Annotations: tt.annotations, | ||
| }) | ||
| require.NoError(t, err) | ||
| require.NotNil(t, opt) | ||
|
|
||
| info := &snapshots.Info{Labels: make(map[string]string)} | ||
| opt(info) | ||
| assert.Equal(t, tt.expectedLabels, info.Labels) | ||
| }) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /* | ||
| Copyright The containerd Authors. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package server | ||
|
|
||
| import "github.com/containerd/containerd/pkg/cri/internal/devboxsnapshotter" | ||
|
|
||
| func isDevboxWritableSnapshotter(name string) bool { | ||
| switch name { | ||
| case DevboxSnapshotter, devboxsnapshotter.StargzSnapshotter: | ||
| return true | ||
| default: | ||
| return false | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -448,7 +448,7 @@ func handleContainerExit(ctx context.Context, e *eventtypes.TaskExit, cntr conta | |||||||||||
| return status, err | ||||||||||||
| } | ||||||||||||
| fmt.Println("Container snapshotter:", container.Snapshotter, "ID:", cntr.Container.ID()) | ||||||||||||
|
||||||||||||
| fmt.Println("Container snapshotter:", container.Snapshotter, "ID:", cntr.Container.ID()) | |
| logrus.WithFields(logrus.Fields{ | |
| "snapshotter": container.Snapshotter, | |
| "containerID": cntr.Container.ID(), | |
| }).Debug("Container snapshotter information on exit") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
snapshotterOptsis now called withsandboxConfig, but the Windows implementation (pkg/cri/sbserver/container_create_windows.go) still has the old 2-arg signature. This will break Windows builds (compile-time mismatch). Update the WindowssnapshotterOptssignature to acceptsandboxConfig *runtime.PodSandboxConfig(unused) and adjust any callers accordingly.