(req *Request)
| 479 | } |
| 480 | |
| 481 | func (w *WorkerPool) createWorker(req *Request) error { |
| 482 | nodeSelector, err := util.JSONStringToMap(req.NodeSelector) |
| 483 | if err != nil { |
| 484 | return fmt.Errorf("failed to unmarshal node selector for cloudshell, err: %v", err) |
| 485 | } |
| 486 | podBytes, err := util.ParseTemplate(manifests.PodTmplV1, struct { |
| 487 | Name string |
| 488 | Namespace string |
| 489 | Image string |
| 490 | NodeSelector map[string]string |
| 491 | Resources *cloudshellv1alpha1.ResourceSetting |
| 492 | }{ |
| 493 | Name: fmt.Sprintf("cloudshell-worker-%s", rand.String(10)), |
| 494 | Namespace: req.Namespace, |
| 495 | Image: req.Image, |
| 496 | NodeSelector: nodeSelector, |
| 497 | Resources: req.Resources, |
| 498 | }) |
| 499 | if err != nil { |
| 500 | return errors.Wrap(err, "failed create cloudshell job") |
| 501 | } |
| 502 | |
| 503 | decoder := scheme.Codecs.UniversalDeserializer() |
| 504 | obj, _, err := decoder.Decode(podBytes, nil, nil) |
| 505 | if err != nil { |
| 506 | klog.ErrorS(err, "failed to decode pod manifest") |
| 507 | return err |
| 508 | } |
| 509 | pod := obj.(*corev1.Pod) |
| 510 | |
| 511 | pod.SetLabels(map[string]string{ |
| 512 | constants.WorkerOwnerLabelKey: "", constants.WorkerRequestLabelKey: req.Cloudshell, constants.WorkerNameLabelKey: pod.GetName(), |
| 513 | }) |
| 514 | |
| 515 | controllerutil.AddFinalizer(pod, ControllerFinalizer) |
| 516 | |
| 517 | if err := w.Create(context.TODO(), pod); err != nil { |
| 518 | return err |
| 519 | } |
| 520 | klog.InfoS("worker created", "cloudshell", req.Cloudshell) |
| 521 | return w.CreateServiceFor(context.TODO(), pod) |
| 522 | } |
| 523 | |
| 524 | func (w *WorkerPool) CreateServiceFor(_ context.Context, worker *corev1.Pod) error { |
| 525 | serviceBytes, err := util.ParseTemplate(manifests.ServiceTmplV1, struct { |
no test coverage detected