Skip to content

Commit 1882a1b

Browse files
authored
Merge pull request #9 from hellolijj/master
update demo
2 parents 834a4d8 + 27f9b74 commit 1882a1b

37 files changed

+636
-235
lines changed

CONTRIBUTORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ root <[email protected]>
7474
Rudy Zhang <[email protected]>
7575
Runrioter Wung <[email protected]>
7676
77+
7778
7879
shaloulcy <[email protected]>
7980
shanbo.lkw <[email protected]>

MAINTAINERS.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Maintainers
22

3+
## Maintainers List
4+
35
|GitHub ID| Name | Email|Company|
46
|:---:| :----:| :---:|:--: |
57
|[allencloud](https://github.com/allencloud)|Allen Sun|[email protected]|Alibaba Group|
@@ -11,3 +13,26 @@
1113
|[sunyuan3](https://github.com/sunyuan3)|Yuan Sun|[email protected] |Alibaba Group|
1214
|[HusterWan](https://github.com/HusterWan)|Michael Wan|[email protected]|Alibaba Group|
1315
|[ZYecho](https://github.com/ZYecho)|Yue Zhang|[email protected]|ISCAS|
16+
|[fuweid](https://github.com/fuweid)|Wei Fu|[email protected]|Alibaba Group|
17+
|[zhuangqh](https://github.com/zhuangqh)|Jerry Zhuang|[email protected]| Alibaba Group|
18+
19+
## Component Owner/Backup
20+
21+
In order to make all components in PouchContainer well-maintained, an owner/backup responsibility policy is set for all maintainers. No matter the owner or the backup, they have responsibilities to make/review design and programme code for the corresponding component. They work for success of the decoupled component, and efforts all maintainers do guarantee PouchContainer's success.
22+
23+
We encourage all community participants to communicate with component owner/backup to get more information or guidance via all kinds of channels, such as @him in GitHub issue or pull request, email him via listed email address and so on. And component owner/backups are obligated to provide kind and patient help to the community.
24+
25+
The component owner and backup are listed as below:
26+
27+
|Component|Owner|Backup|Notes|
28+
|:---:|:----:|:---:|:--:|
29+
|CRI/Kubernetes|zhuangqh|Starnop|CRI stablibity/improvement, collaborate with upstream|
30+
|API/CLI|allencloud|fuweid|API/CLI definitions/change reviews|
31+
|runtime/OCI|Ace-Tang| zhuangqh|multiple runtime support, runc/kata/gvisor|
32+
|storage|rudyfly|fuweid|volumes, diskquota, volume plugin protocols|
33+
|network|rudyfly|HusterWan|libnetwork, cni plugins|
34+
|image|fuweid|ZYecho|image storage/distribution/management |
35+
|ctrd|fuweid|Ace-Tang|component used in pouchd to communicated with containerd|
36+
|ContainerMgr|HusterWan|Ace-Tang|container lifecycle management in pouchd|
37+
|Test|sunyuan3|chuanchang|test framework and software quality|
38+
|Document|allencloud|rufyfly|Document Roadmap and quality improvement|

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ plugin: ## build hook plugin
322322
@./hack/module --add-plugin=github.com/alibaba/pouch/hookplugins/criplugin
323323
@./hack/module --add-plugin=github.com/alibaba/pouch/hookplugins/volumeplugin
324324
@./hack/module --add-plugin=github.com/alibaba/pouch/hookplugins/apiplugin
325+
@./hack/module --add-plugin=github.com/alibaba/pouch/hookplugins/imageplugin
325326

326327
.PHONY: help
327328
help: ## this help

apis/opts/config/runtime_test.go

Lines changed: 98 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,59 @@ import (
1010
)
1111

1212
func TestNewRuntime(t *testing.T) {
13-
assert := assert.New(t)
13+
type args struct {
14+
val *map[string]types.Runtime
15+
}
1416

15-
for _, r := range []*map[string]types.Runtime{
16-
nil,
17-
{},
17+
//create a nil map that makes *rts = nil
18+
var nilmap = map[string]types.Runtime(nil)
19+
20+
tests := []struct {
21+
name string
22+
args args
23+
want *Runtime
24+
}{
1825
{
19-
"a": {},
20-
"b": {Path: "foo"},
26+
name: "rts = nil",
27+
args: args{
28+
val: nil,
29+
},
30+
want: &Runtime{
31+
values: &map[string]types.Runtime{},
32+
},
33+
},
34+
{
35+
name: "*rts = nil",
36+
args: args{
37+
val: &nilmap,
38+
},
39+
want: &Runtime{
40+
values: &map[string]types.Runtime{},
41+
},
42+
},
43+
{
44+
name: "rts is valid",
45+
args: args{
46+
val: &map[string]types.Runtime{
47+
"runtime_name1": {},
48+
"runtime_name2": {Path: "$PATH"},
49+
},
50+
},
51+
want: &Runtime{
52+
values: &map[string]types.Runtime{
53+
"runtime_name1": {},
54+
"runtime_name2": {Path: "$PATH"},
55+
},
56+
},
2157
},
22-
} {
23-
runtime := NewRuntime(r)
24-
// just test no panic here
25-
assert.NotEmpty(t, runtime)
58+
}
59+
for _, tt := range tests {
60+
t.Run(tt.name, func(t *testing.T) {
61+
got := NewRuntime(tt.args.val)
62+
if !reflect.DeepEqual(got, tt.want) {
63+
t.Errorf("NewRuntime() = %v, want %v", got, tt.want)
64+
}
65+
})
2666
}
2767
}
2868

@@ -114,3 +154,51 @@ func TestRuntimeType(t *testing.T) {
114154
}
115155
}
116156
}
157+
158+
func TestRuntimeString(t *testing.T) {
159+
type fields struct {
160+
values *map[string]types.Runtime
161+
}
162+
163+
tests := []struct {
164+
name string
165+
fields fields
166+
want string
167+
}{
168+
{
169+
name: "get string of Runtime with one element",
170+
fields: fields{
171+
values: &(map[string]types.Runtime{
172+
"runtime_name": {Path: "$PATH"},
173+
}),
174+
},
175+
want: "[runtime_name]",
176+
},
177+
{
178+
name: "get string of Runtime with nil",
179+
fields: fields{
180+
values: &(map[string]types.Runtime{}),
181+
},
182+
want: "[]",
183+
},
184+
{
185+
name: "get string of Runtime with empty string",
186+
fields: fields{
187+
values: &(map[string]types.Runtime{
188+
"": {Path: "$PATH"},
189+
}),
190+
},
191+
want: "[]",
192+
},
193+
}
194+
for _, tt := range tests {
195+
t.Run(tt.name, func(t *testing.T) {
196+
r := &Runtime{
197+
values: tt.fields.values,
198+
}
199+
if got := r.String(); !reflect.DeepEqual(got, tt.want) {
200+
t.Errorf("Runtime.String() = %v, want %v", got, tt.want)
201+
}
202+
})
203+
}
204+
}

apis/swagger.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2246,6 +2246,11 @@ definitions:
22462246
type: "array"
22472247
items:
22482248
type: "string"
2249+
Snapshotter:
2250+
description: |
2251+
The snapshotter container choose, can be different with
2252+
default snapshotter. The Field only set through hook plugin.
2253+
type: "string"
22492254

22502255
ContainerCreateResp:
22512256
description: "response returned by daemon when container create successfully"

apis/types/container_config.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/cli.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func (c *Cli) InitLog() {
8585
logrus.SetFormatter(formatter)
8686
}
8787

88-
// Client returns API client torwards daemon.
88+
// Client returns API client towards daemon.
8989
func (c *Cli) Client() client.CommonAPIClient {
9090
return c.APIClient
9191
}
@@ -165,7 +165,7 @@ type ExitError struct {
165165
Status string
166166
}
167167

168-
// Error inplements error interface.
168+
// Error implements error interface.
169169
func (e ExitError) Error() string {
170170
return fmt.Sprintf("Exit Code: %d, Status: %s", e.Code, e.Status)
171171
}

cri/v1alpha1/cri.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func NewCriManager(config *config.Config, ctrMgr mgr.ContainerMgr, imgMgr mgr.Im
161161
return nil, fmt.Errorf("failed to create sandbox meta store: %v", err)
162162
}
163163

164-
imageFSPath := imageFSPath(path.Join(config.HomeDir, "containerd/root"), ctrd.CurrentSnapshotterName())
164+
imageFSPath := imageFSPath(path.Join(config.HomeDir, "containerd/root"), ctrd.CurrentSnapshotterName(context.TODO()))
165165
c.ImageFSUUID, err = getDeviceUUID(imageFSPath)
166166
if err != nil {
167167
return nil, fmt.Errorf("failed to get imagefs uuid of %q: %v", imageFSPath, err)

cri/v1alpha2/cri.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ func NewCriManager(config *config.Config, ctrMgr mgr.ContainerMgr, imgMgr mgr.Im
184184
return nil, fmt.Errorf("failed to create sandbox meta store: %v", err)
185185
}
186186

187-
c.imageFSPath = imageFSPath(path.Join(config.HomeDir, "containerd/root"), ctrd.CurrentSnapshotterName())
187+
c.imageFSPath = imageFSPath(path.Join(config.HomeDir, "containerd/root"), ctrd.CurrentSnapshotterName(context.TODO()))
188188
logrus.Infof("Get image filesystem path %q", c.imageFSPath)
189189

190190
if !config.CriConfig.DisableCriStatsCollect {

ctrd/client.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import (
1313
"github.com/containerd/containerd"
1414
eventstypes "github.com/containerd/containerd/api/events"
1515
"github.com/containerd/containerd/api/services/introspection/v1"
16+
"github.com/containerd/containerd/plugin"
17+
"github.com/containerd/containerd/snapshots"
1618
"github.com/containerd/typeurl"
1719
"github.com/pkg/errors"
1820
"github.com/sirupsen/logrus"
@@ -305,3 +307,56 @@ func (c *Client) collectContainerdEvents() {
305307
}
306308
}
307309
}
310+
311+
// CheckSnapshotterValid checks whether the given snapshotter is valid
312+
func (c *Client) CheckSnapshotterValid(snapshotter string, allowMultiSnapshotter bool) error {
313+
var (
314+
driverFound = false
315+
)
316+
317+
plugins, err := c.Plugins(context.Background(), []string{fmt.Sprintf("type==%s", plugin.SnapshotPlugin)})
318+
if err != nil {
319+
logrus.Errorf("failed to get containerd plugins: %v", err)
320+
return err
321+
}
322+
323+
for _, p := range plugins {
324+
if p.Status != PluginStatusOk {
325+
continue
326+
}
327+
328+
if p.ID == snapshotter {
329+
driverFound = true
330+
continue
331+
}
332+
333+
// if allowMultiSnapshotter, ignore check snapshots exist
334+
if !allowMultiSnapshotter {
335+
// check if other snapshotter exists snapshots
336+
exist, err := c.checkSnapshotsExist(p.ID)
337+
if err != nil {
338+
return fmt.Errorf("failed to check snapshotter driver %s: %v", p.ID, err)
339+
}
340+
341+
if exist {
342+
return fmt.Errorf("current snapshotter driver is %s, cannot change to %s", p.ID, snapshotter)
343+
}
344+
}
345+
}
346+
347+
if !driverFound {
348+
return fmt.Errorf("containerd not support snapshotter driver %s", snapshotter)
349+
}
350+
351+
return nil
352+
}
353+
354+
func (c *Client) checkSnapshotsExist(snapshotter string) (existSnapshot bool, err error) {
355+
fn := func(c context.Context, s snapshots.Info) error {
356+
existSnapshot = true
357+
return nil
358+
}
359+
360+
err = c.WalkSnapshot(context.Background(), snapshotter, fn)
361+
return
362+
}

0 commit comments

Comments
 (0)