Further refactoring
Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
This commit is contained in:
parent
0bb2fb04d9
commit
c13dbaf6ab
3 changed files with 22 additions and 14 deletions
|
@ -8,11 +8,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// New creates a new Runtime with options provided
|
// New creates a new Runtime with options provided
|
||||||
func New(runtimePath string, sandboxDir string, containerDir string) (*Runtime, error) {
|
func New(runtimePath string, containerDir string) (*Runtime, error) {
|
||||||
r := &Runtime{
|
r := &Runtime{
|
||||||
name: filepath.Base(runtimePath),
|
name: filepath.Base(runtimePath),
|
||||||
path: runtimePath,
|
path: runtimePath,
|
||||||
sandboxDir: sandboxDir,
|
|
||||||
containerDir: containerDir,
|
containerDir: containerDir,
|
||||||
}
|
}
|
||||||
return r, nil
|
return r, nil
|
||||||
|
@ -35,11 +34,6 @@ func (r *Runtime) Path() string {
|
||||||
return r.path
|
return r.path
|
||||||
}
|
}
|
||||||
|
|
||||||
// SandboxDir returns the path to the base directory for storing sandbox configurations
|
|
||||||
func (r *Runtime) SandboxDir() string {
|
|
||||||
return r.sandboxDir
|
|
||||||
}
|
|
||||||
|
|
||||||
// ContainerDir returns the path to the base directory for storing container configurations
|
// ContainerDir returns the path to the base directory for storing container configurations
|
||||||
func (r *Runtime) ContainerDir() string {
|
func (r *Runtime) ContainerDir() string {
|
||||||
return r.containerDir
|
return r.containerDir
|
||||||
|
|
|
@ -39,7 +39,7 @@ func (s *Server) Version(ctx context.Context, req *pb.VersionRequest) (*pb.Versi
|
||||||
func (s *Server) CreatePodSandbox(ctx context.Context, req *pb.CreatePodSandboxRequest) (*pb.CreatePodSandboxResponse, error) {
|
func (s *Server) CreatePodSandbox(ctx context.Context, req *pb.CreatePodSandboxRequest) (*pb.CreatePodSandboxResponse, error) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
if err := os.MkdirAll(s.runtime.SandboxDir(), 0755); err != nil {
|
if err := os.MkdirAll(s.sandboxDir, 0755); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ func (s *Server) CreatePodSandbox(ctx context.Context, req *pb.CreatePodSandboxR
|
||||||
return nil, fmt.Errorf("PodSandboxConfig.Name should not be empty")
|
return nil, fmt.Errorf("PodSandboxConfig.Name should not be empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
podSandboxDir := filepath.Join(s.runtime.SandboxDir(), name)
|
podSandboxDir := filepath.Join(s.sandboxDir, name)
|
||||||
if _, err := os.Stat(podSandboxDir); err == nil {
|
if _, err := os.Stat(podSandboxDir); err == nil {
|
||||||
return nil, fmt.Errorf("pod sandbox (%s) already exists", podSandboxDir)
|
return nil, fmt.Errorf("pod sandbox (%s) already exists", podSandboxDir)
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ func (s *Server) CreatePodSandbox(ctx context.Context, req *pb.CreatePodSandboxR
|
||||||
g.AddBindMount(resolvPath, "/etc/resolv.conf", "ro")
|
g.AddBindMount(resolvPath, "/etc/resolv.conf", "ro")
|
||||||
|
|
||||||
labels := req.GetConfig().GetLabels()
|
labels := req.GetConfig().GetLabels()
|
||||||
s.sandboxes = append(s.sandboxes, &sandbox{
|
s.addSandbox(&sandbox{
|
||||||
name: name,
|
name: name,
|
||||||
logDir: logDir,
|
logDir: logDir,
|
||||||
labels: labels,
|
labels: labels,
|
||||||
|
|
|
@ -11,22 +11,36 @@ const (
|
||||||
// Server implements the RuntimeService and ImageService
|
// Server implements the RuntimeService and ImageService
|
||||||
type Server struct {
|
type Server struct {
|
||||||
runtime *oci.Runtime
|
runtime *oci.Runtime
|
||||||
sandboxes []*sandbox
|
sandboxDir string
|
||||||
|
state *serverState
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new Server with options provided
|
// New creates a new Server with options provided
|
||||||
func New(runtimePath, sandboxDir, containerDir string) (*Server, error) {
|
func New(runtimePath, sandboxDir, containerDir string) (*Server, error) {
|
||||||
r, err := oci.New(runtimePath, sandboxDir, containerDir)
|
r, err := oci.New(runtimePath, containerDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
sandboxes := make(map[string]*sandbox)
|
||||||
return &Server{
|
return &Server{
|
||||||
runtime: r,
|
runtime: r,
|
||||||
|
sandboxDir: sandboxDir,
|
||||||
|
state: &serverState{
|
||||||
|
sandboxes: sandboxes,
|
||||||
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type serverState struct {
|
||||||
|
sandboxes map[string]*sandbox
|
||||||
|
}
|
||||||
|
|
||||||
type sandbox struct {
|
type sandbox struct {
|
||||||
name string
|
name string
|
||||||
logDir string
|
logDir string
|
||||||
labels map[string]string
|
labels map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Server) addSandbox(sb *sandbox) {
|
||||||
|
s.state.sandboxes[sb.name] = sb
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue