Common podExec helper code
@@ -80,8 +80,8 @@ func findPod(clientSet *kubernetes.Clientset, namespace string, name string) (st
return podList.Items[0].ObjectMeta.Name, nil
}
-func (v *vms) Vnc(name string, in io.Reader, out io.Writer) error {
- device := "vnc"
+func (v *vms) remoteExecHelper(name string, cmd []string, in io.Reader, out io.Writer) error {
+
podName, err := findPod(v.clientSet, v.namespace, name)
if err != nil {
return err
@@ -101,7 +101,6 @@ func (v *vms) Vnc(name string, in io.Reader, out io.Writer) error {
if err != nil {
return err
}
- cmd := []string{"/sock-connector", fmt.Sprintf("/var/run/kubevirt-private/%s/%s/virt-%s", v.namespace, name, device)}
containerName := "compute"
req := restClient.Post().
Resource("pods").
@@ -135,59 +134,15 @@ func (v *vms) Vnc(name string, in io.Reader, out io.Writer) error {
TerminalSizeQueue: nil,
})
}
-func (v *vms) SerialConsole(name string, device string, in io.Reader, out io.Writer) error {
- podName, err := findPod(v.clientSet, v.namespace, name)
- if err != nil {
- return err
- }
- config, err := clientcmd.BuildConfigFromFlags(v.master, v.kubeconfig)
- if err != nil {
- return err
+func (v *vms) Vnc(name string, in io.Reader, out io.Writer) error {
+ cmd := []string{"/sock-connector", fmt.Sprintf("/var/run/kubevirt-private/%s/%s/virt-vnc", v.namespace, name)}
+ return v.remoteExecHelper(name, cmd, in, out)
}
- gv := k8sv1.SchemeGroupVersion
- config.GroupVersion = &gv
- config.APIPath = "/api"
- config.NegotiatedSerializer = serializer.DirectCodecFactory{CodecFactory: scheme.Codecs}
-
- restClient, err := restclient.RESTClientFor(config)
- if err != nil {
- return err
- }
+func (v *vms) SerialConsole(name string, device string, in io.Reader, out io.Writer) error {
cmd := []string{"/sock-connector", fmt.Sprintf("/var/run/kubevirt-private/%s/%s/virt-%s", v.namespace, name, device)}
- containerName := "compute"
- req := restClient.Post().
- Resource("pods").
- Name(podName).
- Namespace(v.namespace).
- SubResource("exec").
- Param("container", containerName)
-
- req = req.VersionedParams(&k8sv1.PodExecOptions{
- Container: containerName,
- Command: cmd,
- Stdin: true,
- Stdout: true,
- Stderr: true,
- TTY: true,
- }, scheme.ParameterCodec)
-
- // execute request
- method := "POST"
- url := req.URL()
- exec, err := remotecommand.NewSPDYExecutor(config, method, url)
- if err != nil {
- return err
- }
-
- return exec.Stream(remotecommand.StreamOptions{
- Stdin: in,
- Stdout: out,
- Stderr: out,
- Tty: false,
- TerminalSizeQueue: nil,
- })
+ return v.remoteExecHelper(name, cmd, in, out)
}
func (v *vms) Get(name string, options k8smetav1.GetOptions) (vm *v1.VirtualMachine, err error) {
