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

Method StartupWorker

pkg/controllers/cloudshell_controller.go:452–509  ·  view source on GitHub ↗
(_ context.Context, cloudshell *cloudshellv1alpha1.CloudShell, kubeConfigByte []byte)

Source from the content-addressed store, hash-verified

450}
451
452func (c *Controller) StartupWorker(_ context.Context, cloudshell *cloudshellv1alpha1.CloudShell, kubeConfigByte []byte) error {
453 // TODO: Some extra logic in order to upload and download files.
454 var podName, namespace, container, serverBufferSize, ps1, pingInterval, clientOptionsStr, credential string
455 serverBufferSize = c.ttydServiceBufferSize
456 pingInterval = c.ttydPingInterval
457 for _, env := range cloudshell.Spec.Env {
458 switch env.Name {
459 case "POD_NAME":
460 podName = env.Value
461 case "POD_NAMESPACE":
462 namespace = env.Value
463 case "CONTAINER":
464 container = env.Value
465 case "TTYD_SERVER_BUFFER_SIZE":
466 serverBufferSize = env.Value
467 case "TTYD_PING_INTERVAL":
468 pingInterval = env.Value
469 case "TTYD_CREDENTIAL":
470 credential = env.Value
471 case "PS1":
472 ps1 = env.Value
473 }
474 }
475
476 // clientOptions is a map, convert it to string, the pattern is "k1=v1|k2=v2|..."
477 // If k or v contains a delimiter(|), return an error.
478 if clientOptions := cloudshell.Spec.TtydClientOptions; clientOptions != nil {
479 var clientOptionsSlice []string
480 for k, v := range clientOptions {
481 if strings.Contains(k, ClientOptionsDelimiter) || strings.Contains(v, ClientOptionsDelimiter) {
482 return errors.New("clientOptions key or value contains delimiter(|)")
483 }
484 clientOptionsSlice = append(clientOptionsSlice, fmt.Sprintf("%s=%s", k, v))
485 }
486 clientOptionsStr = strings.Join(clientOptionsSlice, ClientOptionsDelimiter)
487 }
488
489 klog.InfoS("Cloudshell config", "cloudshell.name", cloudshell.Name, "CommandAction", cloudshell.Spec.CommandAction,
490 "serverBufferSize", serverBufferSize, "pingInterval", pingInterval, "clientOptions", clientOptionsStr, "credential", credential)
491 // start ttyd, ttyd args passed as shell parameter
492 // case: ttydCommand := []string{"/usr/lib/ttyd/startup.sh", "${KUBECONFIG}" "${ONCE}", "${URLARG}", "${COMMAND}"}
493 ttydCommand := []string{
494 startupScriptPath, // $0 startup.sh
495 string(kubeConfigByte), // $1 kubeconfig
496 fmt.Sprint(cloudshell.Spec.Once), // $2 once
497 fmt.Sprint(cloudshell.Spec.UrlArg), // $3 urlArg
498 cloudshell.Spec.CommandAction, // $4 command
499 podName, // $5 podName
500 namespace, // $6 namespace
501 container, // $7 container
502 ps1, // $8 ps1
503 serverBufferSize, // $9 serverBufferSize
504 pingInterval, // $10 pingInterval
505 clientOptionsStr, // $11 clientOptions
506 credential, // $12 credential
507 }
508 return execCommand(cloudshell, ttydCommand, c.config)
509}

Callers 1

StartupWorkerForMethod · 0.95

Calls 1

execCommandFunction · 0.85

Tested by

no test coverage detected