MCPcopy Index your code
hub / github.com/cloudtty/cloudtty / CreateRouteRule

Method CreateRouteRule

pkg/controllers/cloudshell_controller.go:539–580  ·  view source on GitHub ↗

CreateRouteRule create a service resource in the same namespace of cloudshell no matter what expose model. if the expose model is ingress or virtualService, it will create additional resources, e.g: ingress or virtualService. and the accressUrl will be update.

(ctx context.Context, cloudshell *cloudshellv1alpha1.CloudShell, worker *corev1.Pod)

Source from the content-addressed store, hash-verified

537// if the expose model is ingress or virtualService, it will create additional resources, e.g: ingress or virtualService.
538// and the accressUrl will be update.
539func (c *Controller) CreateRouteRule(ctx context.Context, cloudshell *cloudshellv1alpha1.CloudShell, worker *corev1.Pod) (string, error) {
540 var accessURL string
541 switch cloudshell.Spec.ExposeMode {
542 case "", cloudshellv1alpha1.ExposureServiceNodePort:
543 // Default(No explicit `ExposeMode` specified in CR) mode is Nodeport
544 host, err := c.GetMasterNodeIP(ctx)
545 if err != nil {
546 klog.ErrorS(err, "unable to get control plane node IP addr", "cloudshell", klog.KObj(cloudshell))
547 return "", err
548 }
549
550 service, err := c.CreateCloudShellService(cloudshell, worker)
551 if err != nil {
552 return "", fmt.Errorf("failed to create service for cloudshell, err: %v", err)
553 }
554
555 var nodePort int32
556 for _, port := range service.Spec.Ports {
557 if port.NodePort != 0 {
558 nodePort = port.NodePort
559 break
560 }
561 }
562 accessURL = fmt.Sprintf("%s:%d", host, nodePort)
563 case cloudshellv1alpha1.ExposureIngress:
564 if err := c.CreateIngressForCloudshell(ctx, worker.GetName(), cloudshell); err != nil {
565 klog.ErrorS(err, "failed to create ingress for cloudshell", "cloudshell", klog.KObj(cloudshell))
566 return "", err
567 }
568
569 accessURL = SetRouteRulePath(cloudshell)
570 case cloudshellv1alpha1.ExposureVirtualService:
571 if err := c.CreateVirtualServiceForCloudshell(ctx, worker.GetName(), cloudshell); err != nil {
572 klog.ErrorS(err, "failed to create virtualservice for cloudshell", "cloudshell", klog.KObj(cloudshell))
573 return "", err
574 }
575
576 accessURL = SetRouteRulePath(cloudshell)
577 }
578
579 return accessURL, nil
580}
581
582// GetMasterNodeIP could find the one master node IP.
583func (c *Controller) GetMasterNodeIP(ctx context.Context) (string, error) {

Callers 1

syncCloudShellMethod · 0.95

Calls 5

GetMasterNodeIPMethod · 0.95
SetRouteRulePathFunction · 0.85

Tested by

no test coverage detected