Skip to content

Commit 5bc4afe

Browse files
authored
Merge pull request #2266 from YaoZengzeng/bug-log
bugfix: complete json tag for StreamServerReusePort and add some useful log for stop & remove pod operation
2 parents 4e47fda + 7e18e53 commit 5bc4afe

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

cri/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ type Config struct {
2020
// StreamServerPort is the port which cri stream server is listening on.
2121
StreamServerPort string `json:"stream-server-port,omitempty"`
2222
// StreamServerReusePort specify whether cri stream server share port with pouchd.
23-
StreamServerReusePort bool
23+
StreamServerReusePort bool `json:"stream-server-reuse-port,omitempty"`
2424
}

cri/v1alpha1/cri.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ func (c *CriManager) StopPodSandbox(ctx context.Context, r *runtime.StopPodSandb
329329
if err != nil {
330330
return nil, fmt.Errorf("failed to stop container %q of sandbox %q: %v", container.ID, podSandboxID, err)
331331
}
332+
logrus.Infof("success to stop container %q of sandbox %q", container.ID, podSandboxID)
332333
}
333334

334335
container, err := c.ContainerMgr.Get(ctx, podSandboxID)
@@ -360,6 +361,8 @@ func (c *CriManager) StopPodSandbox(ctx context.Context, r *runtime.StopPodSandb
360361
}
361362
} else if !os.IsNotExist(err) {
362363
return nil, fmt.Errorf("failed to stat network namespace file %s of sandbox %s: %v", sandboxMeta.NetNSPath, podSandboxID, err)
364+
} else {
365+
logrus.Warnf("failed to find network namespace file %s of sandbox %s which may have been already stopped", sandboxMeta.NetNSPath, podSandboxID)
363366
}
364367
}
365368

@@ -394,6 +397,7 @@ func (c *CriManager) RemovePodSandbox(ctx context.Context, r *runtime.RemovePodS
394397
if err != nil {
395398
return nil, fmt.Errorf("failed to remove container %q of sandbox %q: %v", container.ID, podSandboxID, err)
396399
}
400+
logrus.Infof("success remove container %q of sandbox %q", container.ID, podSandboxID)
397401
}
398402

399403
// Remove the sandbox container.
@@ -573,20 +577,19 @@ func (c *CriManager) CreateContainer(ctx context.Context, r *runtime.CreateConta
573577

574578
containerName := makeContainerName(sandboxConfig, config)
575579

576-
var createErr error
577-
createResp, createErr := c.ContainerMgr.Create(ctx, containerName, createConfig)
578-
if createErr != nil {
580+
createResp, err := c.ContainerMgr.Create(ctx, containerName, createConfig)
581+
if err != nil {
579582
return nil, fmt.Errorf("failed to create container for sandbox %q: %v", podSandboxID, err)
580583
}
581584

582585
containerID := createResp.ID
583586

584587
defer func() {
585588
// If the container failed to be created, clean up the container.
586-
if createErr != nil {
587-
err := c.ContainerMgr.Remove(ctx, containerID, &apitypes.ContainerRemoveOptions{Volumes: true, Force: true})
589+
if err != nil {
590+
removeErr := c.ContainerMgr.Remove(ctx, containerID, &apitypes.ContainerRemoveOptions{Volumes: true, Force: true})
588591
if err != nil {
589-
logrus.Errorf("failed to remove the container when creating container failed: %v", err)
592+
logrus.Errorf("failed to remove the container when creating container failed: %v", removeErr)
590593
}
591594
}
592595
}()
@@ -597,7 +600,7 @@ func (c *CriManager) CreateContainer(ctx context.Context, r *runtime.CreateConta
597600
// NOTE: If we attach log here, the IO of container will be created
598601
// by this function first, so we should decide whether open the stdin
599602
// here. It's weird actually, make it more elegant in the future.
600-
err := c.attachLog(logPath, containerID, config.Stdin)
603+
err = c.attachLog(logPath, containerID, config.Stdin)
601604
if err != nil {
602605
return nil, err
603606
}

cri/v1alpha2/cri.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ func (c *CriManager) StopPodSandbox(ctx context.Context, r *runtime.StopPodSandb
406406
if err != nil {
407407
return nil, fmt.Errorf("failed to stop container %q of sandbox %q: %v", container.ID, podSandboxID, err)
408408
}
409+
logrus.Infof("success to stop container %q of sandbox %q", container.ID, podSandboxID)
409410
}
410411

411412
container, err := c.ContainerMgr.Get(ctx, podSandboxID)
@@ -437,6 +438,8 @@ func (c *CriManager) StopPodSandbox(ctx context.Context, r *runtime.StopPodSandb
437438
}
438439
} else if !os.IsNotExist(err) {
439440
return nil, fmt.Errorf("failed to stat network namespace file %s of sandbox %s: %v", sandboxMeta.NetNSPath, podSandboxID, err)
441+
} else {
442+
logrus.Warnf("failed to find network namespace file %s of sandbox %s which may have been already stopped", sandboxMeta.NetNSPath, podSandboxID)
440443
}
441444
}
442445

@@ -471,6 +474,7 @@ func (c *CriManager) RemovePodSandbox(ctx context.Context, r *runtime.RemovePodS
471474
if err != nil {
472475
return nil, fmt.Errorf("failed to remove container %q of sandbox %q: %v", container.ID, podSandboxID, err)
473476
}
477+
logrus.Infof("success to remove container %q of sandbox %q", container.ID, podSandboxID)
474478
}
475479

476480
// Remove the sandbox container.
@@ -663,20 +667,19 @@ func (c *CriManager) CreateContainer(ctx context.Context, r *runtime.CreateConta
663667

664668
containerName := makeContainerName(sandboxConfig, config)
665669

666-
var createErr error
667-
createResp, createErr := c.ContainerMgr.Create(ctx, containerName, createConfig)
668-
if createErr != nil {
670+
createResp, err := c.ContainerMgr.Create(ctx, containerName, createConfig)
671+
if err != nil {
669672
return nil, fmt.Errorf("failed to create container for sandbox %q: %v", podSandboxID, err)
670673
}
671674

672675
containerID := createResp.ID
673676

674677
defer func() {
675678
// If the container failed to be created, clean up the container.
676-
if createErr != nil {
677-
err := c.ContainerMgr.Remove(ctx, containerID, &apitypes.ContainerRemoveOptions{Volumes: true, Force: true})
678-
if err != nil {
679-
logrus.Errorf("failed to remove the container when creating container failed: %v", err)
679+
if err != nil {
680+
removeErr := c.ContainerMgr.Remove(ctx, containerID, &apitypes.ContainerRemoveOptions{Volumes: true, Force: true})
681+
if removeErr != nil {
682+
logrus.Errorf("failed to remove the container when creating container failed: %v", removeErr)
680683
}
681684
}
682685
}()
@@ -687,7 +690,7 @@ func (c *CriManager) CreateContainer(ctx context.Context, r *runtime.CreateConta
687690
// NOTE: If we attach log here, the IO of container will be created
688691
// by this function first, so we should decide whether open the stdin
689692
// here. It's weird actually, make it more elegant in the future.
690-
err := c.attachLog(logPath, containerID, config.Stdin)
693+
err = c.attachLog(logPath, containerID, config.Stdin)
691694
if err != nil {
692695
return nil, err
693696
}

0 commit comments

Comments
 (0)