(ctx context.Context, info sandbox.Sandbox, opts ...sandbox.CreateOpt)
| 121 | } |
| 122 | |
| 123 | func (c *controllerLocal) Create(ctx context.Context, info sandbox.Sandbox, opts ...sandbox.CreateOpt) (retErr error) { |
| 124 | var coptions sandbox.CreateOptions |
| 125 | sandboxID := info.ID |
| 126 | for _, opt := range opts { |
| 127 | opt(&coptions) |
| 128 | } |
| 129 | |
| 130 | if _, err := c.shims.Get(ctx, sandboxID); err == nil { |
| 131 | return fmt.Errorf("sandbox %s already running: %w", sandboxID, errdefs.ErrAlreadyExists) |
| 132 | } |
| 133 | |
| 134 | bundle, err := v2.NewBundle(ctx, c.root, c.state, sandboxID, info.Spec) |
| 135 | if err != nil { |
| 136 | return err |
| 137 | } |
| 138 | defer func() { |
| 139 | if retErr != nil { |
| 140 | bundle.Delete() |
| 141 | } |
| 142 | }() |
| 143 | |
| 144 | shim, err := c.shims.Start(ctx, sandboxID, bundle, runtime.CreateOpts{ |
| 145 | Spec: info.Spec, |
| 146 | RuntimeOptions: info.Runtime.Options, |
| 147 | Runtime: info.Runtime.Name, |
| 148 | TaskOptions: nil, |
| 149 | }) |
| 150 | if err != nil { |
| 151 | return fmt.Errorf("failed to start new shim for sandbox %s: %w", sandboxID, err) |
| 152 | } |
| 153 | |
| 154 | svc, err := sandbox.NewClient(shim.Client()) |
| 155 | if err != nil { |
| 156 | return err |
| 157 | } |
| 158 | |
| 159 | if _, err := svc.CreateSandbox(ctx, &runtimeAPI.CreateSandboxRequest{ |
| 160 | SandboxID: sandboxID, |
| 161 | BundlePath: shim.Bundle(), |
| 162 | Rootfs: mount.ToProto(coptions.Rootfs), |
| 163 | Options: typeurl.MarshalProto(coptions.Options), |
| 164 | NetnsPath: coptions.NetNSPath, |
| 165 | Annotations: coptions.Annotations, |
| 166 | }); err != nil { |
| 167 | c.cleanupShim(ctx, sandboxID, svc) |
| 168 | return fmt.Errorf("failed to create sandbox %s: %w", sandboxID, errgrpc.ToNative(err)) |
| 169 | } |
| 170 | |
| 171 | return nil |
| 172 | } |
| 173 | |
| 174 | func (c *controllerLocal) Start(ctx context.Context, sandboxID string) (sandbox.ControllerInstance, error) { |
| 175 | shim, err := c.shims.Get(ctx, sandboxID) |
nothing calls this directly
no test coverage detected