(ctx context.Context, cloudshell *cloudshellv1alpha1.CloudShell)
| 290 | } |
| 291 | |
| 292 | func (c *Controller) syncCloudShell(ctx context.Context, cloudshell *cloudshellv1alpha1.CloudShell) (*time.Duration, error) { |
| 293 | t := nextRequeueTimeDuration(cloudshell) |
| 294 | |
| 295 | // remove cloudshell while ttl is timeout. |
| 296 | if t != nil && *t < 0 { |
| 297 | if err := c.removeCloudshell(ctx, cloudshell); err != nil { |
| 298 | return nil, err |
| 299 | } |
| 300 | if cloudshell.Spec.Cleanup { |
| 301 | return nil, c.Delete(ctx, cloudshell) |
| 302 | } |
| 303 | |
| 304 | return nil, c.UpdateCloudshellStatus(ctx, cloudshell, cloudshellv1alpha1.PhaseCompleted) |
| 305 | } |
| 306 | |
| 307 | worker, err := c.GetBindingWorkerFor(cloudshell) |
| 308 | if err != nil { |
| 309 | return nil, fmt.Errorf("failed to get binding worker for cloudshell, err: %v", err) |
| 310 | } |
| 311 | if worker != nil && !util.IsPodReady(worker) { |
| 312 | klog.InfoS("bound worker is not ready, reassigning", "cloudshell", klog.KObj(cloudshell), "worker", worker.Name) |
| 313 | if err := c.workerPool.Back(worker); err != nil { |
| 314 | klog.ErrorS(err, "failed to back worker for reassignment", "cloudshell", klog.KObj(cloudshell), "worker", worker.Name) |
| 315 | } |
| 316 | if cloudshell.Labels != nil { |
| 317 | delete(cloudshell.Labels, constants.CloudshellPodLabelKey) |
| 318 | } |
| 319 | if err := c.Update(ctx, cloudshell); err != nil { |
| 320 | return nil, err |
| 321 | } |
| 322 | worker = nil |
| 323 | } |
| 324 | |
| 325 | // TODO: when cloudshell image be changed, the image of binding worker is different with the spce.image |
| 326 | |
| 327 | if worker == nil { |
| 328 | nodeSelectorString, err := util.MapToJSONString(c.nodeSelector) |
| 329 | if err != nil { |
| 330 | return nil, fmt.Errorf("failed to marshal node selector for cloudshell, err: %v", err) |
| 331 | } |
| 332 | req := &worerkpool.Request{ |
| 333 | Cloudshell: cloudshell.GetName(), |
| 334 | Namespace: cloudshell.GetNamespace(), |
| 335 | Image: cloudshell.Spec.Image, |
| 336 | NodeSelector: nodeSelectorString, |
| 337 | Resources: c.resources, |
| 338 | CloudShellQueue: c.queue, |
| 339 | } |
| 340 | |
| 341 | worker, err = c.workerPool.Borrow(req) |
| 342 | if err != nil { |
| 343 | if err == worerkpool.ErrNotWorker { |
| 344 | klog.InfoS("wait worker poll to create worker", "cloudshell", klog.KObj(cloudshell)) |
| 345 | return nil, nil |
| 346 | } |
| 347 | |
| 348 | klog.ErrorS(err, "failed to borrow worker for pool", "cloudshell", klog.KObj(cloudshell)) |
| 349 | return nil, err |
no test coverage detected