Merge pull request #1010 from teawater/fix_crash

Fix the issue that pod or container config file without metadata will…
This commit is contained in:
Lantao Liu 2019-01-03 10:10:26 -08:00 committed by GitHub
commit 1fbd06479e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -92,7 +92,11 @@ func (c *criService) CreateContainer(ctx context.Context, r *runtime.CreateConta
// Reserve the container name to avoid concurrent `CreateContainer` request creating
// the same container.
id := util.GenerateID()
name := makeContainerName(config.GetMetadata(), sandboxConfig.GetMetadata())
metadata := config.GetMetadata()
if metadata == nil {
return nil, errors.New("container config must include metadata")
}
name := makeContainerName(metadata, sandboxConfig.GetMetadata())
logrus.Debugf("Generated id %q for container %q", id, name)
if err = c.containerNameIndex.Reserve(name, id); err != nil {
return nil, errors.Wrapf(err, "failed to reserve container name %q", name)

View File

@ -58,7 +58,11 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
// Generate unique id and name for the sandbox and reserve the name.
id := util.GenerateID()
name := makeSandboxName(config.GetMetadata())
metadata := config.GetMetadata()
if metadata == nil {
return nil, errors.New("sandbox config must include metadata")
}
name := makeSandboxName(metadata)
logrus.Debugf("Generated id %q for sandbox %q", id, name)
// Reserve the sandbox name to avoid concurrent `RunPodSandbox` request starting the
// same sandbox.