cri-o/server/container_exec.go
Jacek J. Łakis b75b6f6e4b container: add exec command prototype
Signed-off-by: Jacek J. Łakis <jacek.lakis@intel.com>
2017-04-24 18:44:48 +02:00

38 lines
920 B
Go

package server
import (
"fmt"
"github.com/Sirupsen/logrus"
"github.com/kubernetes-incubator/cri-o/oci"
"golang.org/x/net/context"
pb "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime"
)
// Exec prepares a streaming endpoint to execute a command in the container.
func (s *Server) Exec(ctx context.Context, req *pb.ExecRequest) (*pb.ExecResponse, error) {
logrus.Debugf("ExecRequest %+v", req)
c, err := s.getContainerFromRequest(req.ContainerId)
if err != nil {
return nil, err
}
if err = s.runtime.UpdateStatus(c); err != nil {
return nil, err
}
cState := s.runtime.ContainerStatus(c)
if !(cState.Status == oci.ContainerStateRunning || cState.Status == oci.ContainerStateCreated) {
return nil, fmt.Errorf("container is not created or running")
}
if req.Cmd == nil {
return nil, fmt.Errorf("exec command cannot be empty")
}
url := "url"
return &pb.ExecResponse{
Url: url,
}, nil
}