(cloudshell *cloudshellv1alpha1.CloudShell, command []string, config *rest.Config)
| 1140 | } |
| 1141 | |
| 1142 | func 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 | } |
no test coverage detected