@@ -30,22 +30,31 @@ import (
30
30
31
31
type RuntimeInfo = containerdexecutor.RuntimeInfo
32
32
33
+ type WorkerOptions struct {
34
+ Root string
35
+ Address string
36
+ SnapshotterName string
37
+ Namespace string
38
+ CgroupParent string
39
+ Rootless bool
40
+ Labels map [string ]string
41
+ DNS * oci.DNSConfig
42
+ NetworkOpt netproviders.Opt
43
+ ApparmorProfile string
44
+ Selinux bool
45
+ ParallelismSem * semaphore.Weighted
46
+ TraceSocket string
47
+ Runtime * RuntimeInfo
48
+ }
49
+
33
50
// NewWorkerOpt creates a WorkerOpt.
34
51
func NewWorkerOpt (
35
- root string ,
36
- address , snapshotterName , ns , cgroupParent string ,
37
- rootless bool ,
38
- labels map [string ]string ,
39
- dns * oci.DNSConfig ,
40
- nopt netproviders.Opt ,
41
- apparmorProfile string ,
42
- selinux bool ,
43
- parallelismSem * semaphore.Weighted ,
44
- traceSocket string ,
45
- runtime * RuntimeInfo ,
52
+ workerOpts WorkerOptions ,
46
53
opts ... containerd.ClientOpt ,
47
54
) (base.WorkerOpt , error ) {
48
- opts = append (opts , containerd .WithDefaultNamespace (ns ))
55
+ opts = append (opts , containerd .WithDefaultNamespace (workerOpts .Namespace ))
56
+
57
+ address := workerOpts .Address
49
58
50
59
if goRuntime .GOOS == "windows" {
51
60
// TODO(profnandaa): once the upstream PR[1] is merged and
@@ -58,29 +67,17 @@ func NewWorkerOpt(
58
67
return base.WorkerOpt {}, errors .Wrapf (err , "failed to connect client to %q . make sure containerd is running" , address )
59
68
}
60
69
return newContainerd (
61
- root ,
62
70
client ,
63
- snapshotterName ,
64
- ns ,
65
- cgroupParent ,
66
- rootless ,
67
- labels ,
68
- dns ,
69
- nopt ,
70
- apparmorProfile ,
71
- selinux ,
72
- parallelismSem ,
73
- traceSocket ,
74
- runtime ,
71
+ workerOpts ,
75
72
)
76
73
}
77
74
78
- func newContainerd (root string , client * containerd.Client , snapshotterName , ns , cgroupParent string , rootless bool , labels map [ string ] string , dns * oci. DNSConfig , nopt netproviders. Opt , apparmorProfile string , selinux bool , parallelismSem * semaphore. Weighted , traceSocket string , runtime * RuntimeInfo ) (base.WorkerOpt , error ) {
79
- if strings .Contains (snapshotterName , "/" ) {
80
- return base.WorkerOpt {}, errors .Errorf ("bad snapshotter name: %q" , snapshotterName )
75
+ func newContainerd (client * containerd.Client , workerOpts WorkerOptions ) (base.WorkerOpt , error ) {
76
+ if strings .Contains (workerOpts . SnapshotterName , "/" ) {
77
+ return base.WorkerOpt {}, errors .Errorf ("bad snapshotter name: %q" , workerOpts . SnapshotterName )
81
78
}
82
- name := "containerd-" + snapshotterName
83
- root = filepath .Join (root , name )
79
+ name := "containerd-" + workerOpts . SnapshotterName
80
+ root : = filepath .Join (workerOpts . Root , name )
84
81
if err := os .MkdirAll (root , 0700 ); err != nil {
85
82
return base.WorkerOpt {}, errors .Wrapf (err , "failed to create %s" , root )
86
83
}
@@ -97,7 +94,7 @@ func newContainerd(root string, client *containerd.Client, snapshotterName, ns,
97
94
return base.WorkerOpt {}, err
98
95
}
99
96
100
- np , npResolvedMode , err := netproviders .Providers (nopt )
97
+ np , npResolvedMode , err := netproviders .Providers (workerOpts . NetworkOpt )
101
98
if err != nil {
102
99
return base.WorkerOpt {}, err
103
100
}
@@ -108,21 +105,21 @@ func newContainerd(root string, client *containerd.Client, snapshotterName, ns,
108
105
}
109
106
xlabels := map [string ]string {
110
107
wlabel .Executor : "containerd" ,
111
- wlabel .Snapshotter : snapshotterName ,
108
+ wlabel .Snapshotter : workerOpts . SnapshotterName ,
112
109
wlabel .Hostname : hostname ,
113
110
wlabel .Network : npResolvedMode ,
114
- wlabel .SELinuxEnabled : strconv .FormatBool (selinux ),
111
+ wlabel .SELinuxEnabled : strconv .FormatBool (workerOpts . Selinux ),
115
112
}
116
- if apparmorProfile != "" {
117
- xlabels [wlabel .ApparmorProfile ] = apparmorProfile
113
+ if workerOpts . ApparmorProfile != "" {
114
+ xlabels [wlabel .ApparmorProfile ] = workerOpts . ApparmorProfile
118
115
}
119
- xlabels [wlabel .ContainerdNamespace ] = ns
116
+ xlabels [wlabel .ContainerdNamespace ] = workerOpts . Namespace
120
117
xlabels [wlabel .ContainerdUUID ] = serverInfo .UUID
121
- for k , v := range labels {
118
+ for k , v := range workerOpts . Labels {
122
119
xlabels [k ] = v
123
120
}
124
121
125
- lm := leaseutil .WithNamespace (client .LeasesService (), ns )
122
+ lm := leaseutil .WithNamespace (client .LeasesService (), workerOpts . Namespace )
126
123
127
124
gc := func (ctx context.Context ) (gc.Stats , error ) {
128
125
l , err := lm .Create (ctx )
@@ -132,7 +129,7 @@ func newContainerd(root string, client *containerd.Client, snapshotterName, ns,
132
129
return nil , lm .Delete (ctx , leases.Lease {ID : l .ID }, leases .SynchronousDelete )
133
130
}
134
131
135
- cs := containerdsnapshot .NewContentStore (client .ContentStore (), ns )
132
+ cs := containerdsnapshot .NewContentStore (client .ContentStore (), workerOpts . Namespace )
136
133
137
134
resp , err := client .IntrospectionService ().Plugins (context .TODO (), []string {"type==io.containerd.runtime.v1" , "type==io.containerd.runtime.v2" })
138
135
if err != nil {
@@ -154,7 +151,7 @@ func newContainerd(root string, client *containerd.Client, snapshotterName, ns,
154
151
}
155
152
}
156
153
157
- snap := containerdsnapshot .NewSnapshotter (snapshotterName , client .SnapshotService (snapshotterName ), ns , nil )
154
+ snap := containerdsnapshot .NewSnapshotter (workerOpts . SnapshotterName , client .SnapshotService (workerOpts . SnapshotterName ), workerOpts . Namespace , nil )
158
155
159
156
if err := cache .MigrateV2 (
160
157
context .TODO (),
@@ -172,12 +169,25 @@ func newContainerd(root string, client *containerd.Client, snapshotterName, ns,
172
169
return base.WorkerOpt {}, err
173
170
}
174
171
172
+ executorOpts := containerdexecutor.ExecutorOptions {
173
+ Client : client ,
174
+ Root : root ,
175
+ CgroupParent : workerOpts .CgroupParent ,
176
+ ApparmorProfile : workerOpts .ApparmorProfile ,
177
+ DNSConfig : workerOpts .DNS ,
178
+ Selinux : workerOpts .Selinux ,
179
+ TraceSocket : workerOpts .TraceSocket ,
180
+ Rootless : workerOpts .Rootless ,
181
+ Runtime : workerOpts .Runtime ,
182
+ NetworkProviders : np ,
183
+ }
184
+
175
185
opt := base.WorkerOpt {
176
186
ID : id ,
177
187
Labels : xlabels ,
178
188
MetadataStore : md ,
179
189
NetworkProviders : np ,
180
- Executor : containerdexecutor .New (client , root , cgroupParent , np , dns , apparmorProfile , selinux , traceSocket , rootless , runtime ),
190
+ Executor : containerdexecutor .New (executorOpts ),
181
191
Snapshotter : snap ,
182
192
ContentStore : cs ,
183
193
Applier : winlayers .NewFileSystemApplierWithWindows (cs , df ),
@@ -186,7 +196,7 @@ func newContainerd(root string, client *containerd.Client, snapshotterName, ns,
186
196
Platforms : platformSpecs ,
187
197
LeaseManager : lm ,
188
198
GarbageCollect : gc ,
189
- ParallelismSem : parallelismSem ,
199
+ ParallelismSem : workerOpts . ParallelismSem ,
190
200
MountPoolRoot : filepath .Join (root , "cachemounts" ),
191
201
}
192
202
return opt , nil
0 commit comments