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

Function execCommand

pkg/controllers/cloudshell_controller.go:1142–1178  ·  view source on GitHub ↗
(cloudshell *cloudshellv1alpha1.CloudShell, command []string, config *rest.Config)

Source from the content-addressed store, hash-verified

1140}
1141
1142func execCommand(cloudshell *cloudshellv1alpha1.CloudShell, command []string, config *rest.Config) error {
1143 config.GroupVersion = &corev1.SchemeGroupVersion
1144 config.NegotiatedSerializer = scheme.Codecs.WithoutConversion()
1145 config.APIPath = "/api"
1146
1147 clusterClient, err := kubernetes.NewForConfig(config)
1148 if err != nil {
1149 return err
1150 }
1151
1152 options := &exec.ExecOptions{
1153 Command: command,
1154 Executor: &exec.DefaultRemoteExecutor{},
1155 Config: config,
1156 PodClient: clusterClient.CoreV1(),
1157 StreamOptions: exec.StreamOptions{
1158 IOStreams: genericiooptions.IOStreams{
1159 In: bytes.NewBuffer([]byte{}),
1160 Out: bytes.NewBuffer([]byte{}),
1161 ErrOut: bytes.NewBuffer([]byte{}),
1162 },
1163 Stdin: false,
1164 Namespace: cloudshell.Namespace,
1165 PodName: cloudshell.Labels[constants.CloudshellPodLabelKey],
1166 },
1167 }
1168
1169 if err := options.Validate(); err != nil {
1170 return err
1171 }
1172
1173 if err := options.Run(); err != nil {
1174 klog.ErrorS(err, "Failed to run command", "cloudshell", cloudshell.Name, "command", command)
1175 return err
1176 }
1177 return nil
1178}

Callers 2

StartupWorkerMethod · 0.85
ResetWorkerMethod · 0.85

Calls 2

ValidateMethod · 0.80
RunMethod · 0.45

Tested by

no test coverage detected