Skip to content

Commit cd7825d

Browse files
author
Maksym Pavlenko
authored
Merge pull request containerd#9883 from abel-von/modify-sandbox-client
sandbox: modify sandbox client
2 parents c0e34fb + 6781371 commit cd7825d

File tree

1 file changed

+5
-18
lines changed

1 file changed

+5
-18
lines changed

client/sandbox.go

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ import (
3434
type Sandbox interface {
3535
// ID is a sandbox identifier
3636
ID() string
37-
// PID returns sandbox's process PID or error if its not yet started.
38-
PID() (uint32, error)
37+
// Metadata returns metadata of the sandbox
38+
Metadata() api.Sandbox
3939
// NewContainer creates new container that will belong to this sandbox
4040
NewContainer(ctx context.Context, id string, opts ...NewContainerOpts) (Container, error)
4141
// Labels returns the labels set on the sandbox
@@ -51,7 +51,6 @@ type Sandbox interface {
5151
}
5252

5353
type sandboxClient struct {
54-
pid *uint32
5554
client *Client
5655
metadata api.Sandbox
5756
}
@@ -60,12 +59,8 @@ func (s *sandboxClient) ID() string {
6059
return s.metadata.ID
6160
}
6261

63-
func (s *sandboxClient) PID() (uint32, error) {
64-
if s.pid == nil {
65-
return 0, fmt.Errorf("sandbox not started")
66-
}
67-
68-
return *s.pid, nil
62+
func (s *sandboxClient) Metadata() api.Sandbox {
63+
return s.metadata
6964
}
7065

7166
func (s *sandboxClient) NewContainer(ctx context.Context, id string, opts ...NewContainerOpts) (Container, error) {
@@ -82,12 +77,11 @@ func (s *sandboxClient) Labels(ctx context.Context) (map[string]string, error) {
8277
}
8378

8479
func (s *sandboxClient) Start(ctx context.Context) error {
85-
resp, err := s.client.SandboxController(s.metadata.Sandboxer).Start(ctx, s.ID())
80+
_, err := s.client.SandboxController(s.metadata.Sandboxer).Start(ctx, s.ID())
8681
if err != nil {
8782
return err
8883
}
8984

90-
s.pid = &resp.Pid
9185
return nil
9286
}
9387

@@ -154,7 +148,6 @@ func (c *Client) NewSandbox(ctx context.Context, sandboxID string, opts ...NewSa
154148
}
155149

156150
return &sandboxClient{
157-
pid: nil, // Not yet started
158151
client: c,
159152
metadata: metadata,
160153
}, nil
@@ -167,13 +160,7 @@ func (c *Client) LoadSandbox(ctx context.Context, id string) (Sandbox, error) {
167160
return nil, err
168161
}
169162

170-
status, err := c.SandboxController(sandbox.Sandboxer).Status(ctx, id, false)
171-
if err != nil {
172-
return nil, fmt.Errorf("failed to load sandbox %s, status request failed: %w", id, err)
173-
}
174-
175163
return &sandboxClient{
176-
pid: &status.Pid,
177164
client: c,
178165
metadata: sandbox,
179166
}, nil

0 commit comments

Comments
 (0)