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
|
||||
func New(runtimePath string, sandboxDir string, containerDir string) (*Runtime, error) {
|
||||
func New(runtimePath string, containerDir string) (*Runtime, error) {
|
||||
r := &Runtime{
|
||||
name: filepath.Base(runtimePath),
|
||||
path: runtimePath,
|
||||
sandboxDir: sandboxDir,
|
||||
containerDir: containerDir,
|
||||
}
|
||||
return r, nil
|
||||
|
@ -35,11 +34,6 @@ func (r *Runtime) Path() string {
|
|||
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
|
||||
func (r *Runtime) ContainerDir() string {
|
||||
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) {
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,7 @@ func (s *Server) CreatePodSandbox(ctx context.Context, req *pb.CreatePodSandboxR
|
|||
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 {
|
||||
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")
|
||||
|
||||
labels := req.GetConfig().GetLabels()
|
||||
s.sandboxes = append(s.sandboxes, &sandbox{
|
||||
s.addSandbox(&sandbox{
|
||||
name: name,
|
||||
logDir: logDir,
|
||||
labels: labels,
|
||||
|
|
|
@ -10,23 +10,37 @@ const (
|
|||
|
||||
// Server implements the RuntimeService and ImageService
|
||||
type Server struct {
|
||||
runtime *oci.Runtime
|
||||
sandboxes []*sandbox
|
||||
runtime *oci.Runtime
|
||||
sandboxDir string
|
||||
state *serverState
|
||||
}
|
||||
|
||||
// New creates a new Server with options provided
|
||||
func New(runtimePath, sandboxDir, containerDir string) (*Server, error) {
|
||||
r, err := oci.New(runtimePath, sandboxDir, containerDir)
|
||||
r, err := oci.New(runtimePath, containerDir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
sandboxes := make(map[string]*sandbox)
|
||||
return &Server{
|
||||
runtime: r,
|
||||
runtime: r,
|
||||
sandboxDir: sandboxDir,
|
||||
state: &serverState{
|
||||
sandboxes: sandboxes,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
type serverState struct {
|
||||
sandboxes map[string]*sandbox
|
||||
}
|
||||
|
||||
type sandbox struct {
|
||||
name string
|
||||
logDir string
|
||||
labels map[string]string
|
||||
}
|
||||
|
||||
func (s *Server) addSandbox(sb *sandbox) {
|
||||
s.state.sandboxes[sb.name] = sb
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue