6
6
7
7
"github.com/pkg/errors"
8
8
apps "k8s.io/api/apps/v1"
9
- v1 "k8s.io/api/core/v1"
9
+ v1 "k8s.io/api/apps/v1"
10
+ corev1 "k8s.io/api/core/v1"
10
11
kerrors "k8s.io/apimachinery/pkg/api/errors"
11
12
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
12
13
@@ -15,20 +16,21 @@ import (
15
16
)
16
17
17
18
// startChunkServers start all chunkservers for each device of every node
18
- func (c * Cluster ) startChunkServers () error {
19
+ func (c * Cluster ) startChunkServers () ([]* v1.Deployment , error ) {
20
+ results := make ([]* v1.Deployment , 0 )
19
21
if len (job2DeviceInfos ) == 0 {
20
22
logger .Errorf ("no job to format device and provision chunk file" )
21
- return nil
23
+ return results , nil
22
24
}
23
25
24
26
if len (chunkserverConfigs ) == 0 {
25
27
logger .Errorf ("no device need to start chunkserver" )
26
- return nil
28
+ return results , nil
27
29
}
28
30
29
31
if len (job2DeviceInfos ) != len (chunkserverConfigs ) {
30
32
logger .Errorf ("no device need to start chunkserver" )
31
- return errors .New ("failed to start chunkserver because of job numbers is not equal with chunkserver config" )
33
+ return results , errors .New ("failed to start chunkserver because of job numbers is not equal with chunkserver config" )
32
34
}
33
35
34
36
_ = c .createStartCSConfigMap ()
@@ -41,18 +43,19 @@ func (c *Cluster) startChunkServers() error {
41
43
42
44
err := c .createConfigMap (csConfig )
43
45
if err != nil {
44
- return errors .Wrapf (err , "failed to create chunkserver configmap for %v" , config .ChunkserverConfigMapName )
46
+ return results , errors .Wrapf (err , "failed to create chunkserver configmap for %v" ,
47
+ config .ChunkserverConfigMapName )
45
48
}
46
49
47
50
d , err := c .makeDeployment (& csConfig )
48
51
if err != nil {
49
- return errors .Wrap (err , "failed to create chunkserver Deployment" )
52
+ return results , errors .Wrap (err , "failed to create chunkserver Deployment" )
50
53
}
51
54
52
55
newDeployment , err := c .context .Clientset .AppsV1 ().Deployments (c .namespacedName .Namespace ).Create (d )
53
56
if err != nil {
54
57
if ! kerrors .IsAlreadyExists (err ) {
55
- return errors .Wrapf (err , "failed to create chunkserver deployment %s" , csConfig .ResourceName )
58
+ return results , errors .Wrapf (err , "failed to create chunkserver deployment %s" , csConfig .ResourceName )
56
59
}
57
60
logger .Infof ("deployment for chunkserver %s already exists. updating if needed" , csConfig .ResourceName )
58
61
@@ -63,12 +66,11 @@ func (c *Cluster) startChunkServers() error {
63
66
} else {
64
67
logger .Infof ("Deployment %s has been created , waiting for startup" , newDeployment .GetName ())
65
68
// TODO:wait for the new deployment
66
- // deploymentsToWaitFor = append(deploymentsToWaitFor , newDeployment)
69
+ results = append (results , newDeployment )
67
70
}
68
71
// update condition type and phase etc.
69
72
}
70
-
71
- return nil
73
+ return results , nil
72
74
}
73
75
74
76
// createCSClientConfigMap create cs_client configmap
@@ -88,14 +90,15 @@ func (c *Cluster) createCSClientConfigMap() error {
88
90
// 3. replace ${} to specific parameters
89
91
replacedCsClientData , err := config .ReplaceConfigVars (csClientCMData , & chunkserverConfigs [0 ])
90
92
if err != nil {
91
- return errors .Wrap (err , "failed to Replace cs_client config template to generate a new cs_client configmap to start server." )
93
+ return errors .Wrap (err ,
94
+ "failed to Replace cs_client config template to generate a new cs_client configmap to start server." )
92
95
}
93
96
94
97
csClientConfigMap := map [string ]string {
95
98
config .CSClientConfigMapDataKey : replacedCsClientData ,
96
99
}
97
100
98
- cm := & v1 .ConfigMap {
101
+ cm := & corev1 .ConfigMap {
99
102
ObjectMeta : metav1.ObjectMeta {
100
103
Name : config .CSClientConfigMapName ,
101
104
Namespace : c .namespacedName .Namespace ,
@@ -146,7 +149,7 @@ func (c *Cluster) CreateS3ConfigMap() error {
146
149
config .S3ConfigMapDataKey : configMapData ,
147
150
}
148
151
149
- cm := & v1 .ConfigMap {
152
+ cm := & corev1 .ConfigMap {
150
153
ObjectMeta : metav1.ObjectMeta {
151
154
Name : config .S3ConfigMapName ,
152
155
Namespace : c .namespacedName .Namespace ,
@@ -175,7 +178,7 @@ func (c *Cluster) createStartCSConfigMap() error {
175
178
startChunkserverScriptFileDataKey : script .START ,
176
179
}
177
180
178
- cm := & v1 .ConfigMap {
181
+ cm := & corev1 .ConfigMap {
179
182
ObjectMeta : metav1.ObjectMeta {
180
183
Name : startChunkserverConfigMapName ,
181
184
Namespace : c .namespacedName .Namespace ,
@@ -217,7 +220,8 @@ func (c *Cluster) createConfigMap(csConfig chunkserverConfig) error {
217
220
// 3. replace ${} to specific parameters
218
221
replacedChunkServerData , err := config .ReplaceConfigVars (chunkserverData , & csConfig )
219
222
if err != nil {
220
- return errors .Wrap (err , "failed to Replace chunkserver config template to generate a new chunkserver configmap to start server." )
223
+ return errors .Wrap (err ,
224
+ "failed to Replace chunkserver config template to generate a new chunkserver configmap to start server." )
221
225
}
222
226
223
227
// for debug
@@ -227,7 +231,7 @@ func (c *Cluster) createConfigMap(csConfig chunkserverConfig) error {
227
231
config .ChunkserverConfigMapDataKey : replacedChunkServerData ,
228
232
}
229
233
230
- cm := & v1 .ConfigMap {
234
+ cm := & corev1 .ConfigMap {
231
235
ObjectMeta : metav1.ObjectMeta {
232
236
Name : csConfig .CurrentConfigMapName ,
233
237
Namespace : c .namespacedName .Namespace ,
@@ -237,7 +241,8 @@ func (c *Cluster) createConfigMap(csConfig chunkserverConfig) error {
237
241
238
242
err = c .ownerInfo .SetControllerReference (cm )
239
243
if err != nil {
240
- return errors .Wrapf (err , "failed to set owner reference to chunkserverconfig configmap %q" , config .ChunkserverConfigMapName )
244
+ return errors .Wrapf (err , "failed to set owner reference to chunkserverconfig configmap %q" ,
245
+ config .ChunkserverConfigMapName )
241
246
}
242
247
243
248
// Create chunkserver config in cluster
@@ -254,19 +259,19 @@ func (c *Cluster) makeDeployment(csConfig *chunkserverConfig) (*apps.Deployment,
254
259
vols , _ := c .createTopoAndToolVolumeAndMount ()
255
260
volumes = append (volumes , vols ... )
256
261
257
- podSpec := v1 .PodTemplateSpec {
262
+ podSpec := corev1 .PodTemplateSpec {
258
263
ObjectMeta : metav1.ObjectMeta {
259
264
Name : csConfig .ResourceName ,
260
265
Labels : c .getChunkServerPodLabels (csConfig ),
261
266
},
262
- Spec : v1 .PodSpec {
263
- Containers : []v1 .Container {
267
+ Spec : corev1 .PodSpec {
268
+ Containers : []corev1 .Container {
264
269
c .makeCSDaemonContainer (csConfig ),
265
270
},
266
271
NodeName : csConfig .NodeName ,
267
- RestartPolicy : v1 .RestartPolicyAlways ,
272
+ RestartPolicy : corev1 .RestartPolicyAlways ,
268
273
HostNetwork : true ,
269
- DNSPolicy : v1 .DNSClusterFirstWithHostNet ,
274
+ DNSPolicy : corev1 .DNSClusterFirstWithHostNet ,
270
275
Volumes : volumes ,
271
276
},
272
277
}
@@ -301,7 +306,7 @@ func (c *Cluster) makeDeployment(csConfig *chunkserverConfig) (*apps.Deployment,
301
306
}
302
307
303
308
// makeCSDaemonContainer create chunkserver container
304
- func (c * Cluster ) makeCSDaemonContainer (csConfig * chunkserverConfig ) v1 .Container {
309
+ func (c * Cluster ) makeCSDaemonContainer (csConfig * chunkserverConfig ) corev1 .Container {
305
310
306
311
privileged := true
307
312
runAsUser := int64 (0 )
@@ -321,7 +326,7 @@ func (c *Cluster) makeCSDaemonContainer(csConfig *chunkserverConfig) v1.Containe
321
326
argsChunkserverPort := strconv .Itoa (csConfig .Port )
322
327
argsConfigFileMountPath := path .Join (config .ChunkserverConfigMapMountPathDir , config .ChunkserverConfigMapDataKey )
323
328
324
- container := v1 .Container {
329
+ container := corev1 .Container {
325
330
Name : "chunkserver" ,
326
331
Command : []string {
327
332
"/bin/bash" ,
@@ -339,16 +344,16 @@ func (c *Cluster) makeCSDaemonContainer(csConfig *chunkserverConfig) v1.Containe
339
344
Image : c .spec .CurveVersion .Image ,
340
345
ImagePullPolicy : c .spec .CurveVersion .ImagePullPolicy ,
341
346
VolumeMounts : volMounts ,
342
- Ports : []v1 .ContainerPort {
347
+ Ports : []corev1 .ContainerPort {
343
348
{
344
349
Name : "listen-port" ,
345
350
ContainerPort : int32 (csConfig .Port ),
346
351
HostPort : int32 (csConfig .Port ),
347
- Protocol : v1 .ProtocolTCP ,
352
+ Protocol : corev1 .ProtocolTCP ,
348
353
},
349
354
},
350
- Env : []v1 .EnvVar {{Name : "TZ" , Value : "Asia/Hangzhou" }},
351
- SecurityContext : & v1 .SecurityContext {
355
+ Env : []corev1 .EnvVar {{Name : "TZ" , Value : "Asia/Hangzhou" }},
356
+ SecurityContext : & corev1 .SecurityContext {
352
357
Privileged : & privileged ,
353
358
RunAsUser : & runAsUser ,
354
359
RunAsNonRoot : & runAsNonRoot ,
0 commit comments