MCPcopy Create free account
hub / github.com/cloudtty/cloudtty / CreateServiceFor

Method CreateServiceFor

pkg/workerpool/worker_pool.go:524–556  ·  view source on GitHub ↗
(_ context.Context, worker *corev1.Pod)

Source from the content-addressed store, hash-verified

522}
523
524func (w *WorkerPool) CreateServiceFor(_ context.Context, worker *corev1.Pod) error {
525 serviceBytes, err := util.ParseTemplate(manifests.ServiceTmplV1, struct {
526 Name string
527 Namespace string
528 Worker string
529 Type string
530 }{
531 Name: worker.GetName(),
532 Namespace: worker.GetNamespace(),
533 Worker: worker.GetName(),
534 Type: string(corev1.ServiceTypeClusterIP),
535 })
536 if err != nil {
537 return errors.Wrap(err, "failed to parse service manifest")
538 }
539
540 decoder := scheme.Codecs.UniversalDeserializer()
541 obj, _, err := decoder.Decode(serviceBytes, nil, nil)
542 if err != nil {
543 klog.ErrorS(err, "failed to decode service manifest", "worker", klog.KObj(worker))
544 return err
545 }
546
547 svc := obj.(*corev1.Service)
548 svc.SetLabels(map[string]string{constants.WorkerOwnerLabelKey: worker.Name})
549
550 // set reference for service, once the cloudshell is deleted, the service is else deleted.
551 if err := ctrlutil.SetControllerReference(worker, svc, w.scheme); err != nil {
552 return err
553 }
554
555 return util.CreateOrUpdateService(w.Client, svc)
556}
557
558func (w *WorkerPool) deleteWorker(worker *corev1.Pod) error {
559 return w.Delete(context.TODO(), worker)

Callers 1

createWorkerMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected