Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: implement the feature of reopen log about cri #2447

Merged
merged 1 commit into from
Dec 11, 2018

Conversation

starnop
Copy link
Contributor

@starnop starnop commented Nov 7, 2018

Signed-off-by: Starnop [email protected]

Ⅰ. Describe what this PR did

Thanks for the PR of IO redesign , we could implement the function of ReopenContainerLog.

BTW, delete the skip test about ReopenContainerLog .

Ⅱ. Does this pull request fix one issue?

None.

Ⅲ. Why don't you add test cases (unit test/integration test)? (你真的觉得不需要加测试吗?)

None.

Ⅳ. Describe how to verify it

use critest

critest --runtime-endpoint /var/run/pouchcri.sock --ginkgo.focus="runtime should support reopening container log"

Ⅴ. Special notes for reviews

@codecov
Copy link

codecov bot commented Nov 7, 2018

Codecov Report

Merging #2447 into master will decrease coverage by 0.08%.
The diff coverage is 33.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2447      +/-   ##
==========================================
- Coverage   69.24%   69.15%   -0.09%     
==========================================
  Files         278      278              
  Lines       18528    18552      +24     
==========================================
  Hits        12829    12829              
- Misses       4242     4252      +10     
- Partials     1457     1471      +14
Flag Coverage Δ
#criv1alpha1test 31.28% <0%> (-0.03%) ⬇️
#criv1alpha2test 35.44% <30.55%> (+0.02%) ⬆️
#integrationtest 40.57% <0%> (-0.04%) ⬇️
#nodee2etest 32.53% <11.11%> (-0.16%) ⬇️
#unittest 26.81% <0%> (-0.04%) ⬇️
Impacted Files Coverage Δ
cri/v1alpha2/cri_types.go 100% <ø> (ø) ⬆️
daemon/mgr/container.go 58.77% <0%> (+0.08%) ⬆️
pkg/errtypes/errors.go 91.3% <0%> (-8.7%) ⬇️
cri/v1alpha2/cri.go 68.34% <37.5%> (-1.6%) ⬇️
pkg/streams/utils.go 82.14% <0%> (-9.53%) ⬇️
ctrd/watch.go 84.5% <0%> (-2.82%) ⬇️
pkg/meta/store.go 67.44% <0%> (-1.56%) ⬇️
daemon/mgr/container_utils.go 83.92% <0%> (-1.2%) ⬇️
... and 4 more

return nil, fmt.Errorf("failed to get container %q with error: %v", containerID, err)
}
if !container.IsRunning() {
return nil, fmt.Errorf("container is not running")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking that CRI should use the right status code for the error. For this one, we should use ErrPreconditionFail something like that. How do you think about this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, Agree with that. THX.

@@ -180,6 +183,20 @@ func NewCriManager(config *config.Config, ctrMgr mgr.ContainerMgr, imgMgr mgr.Im
return nil, fmt.Errorf("failed to create sandbox meta store: %v", err)
}

c.ContainerStore, err = meta.NewStore(meta.Config{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you provide more detail about this design? I think it should be described in the PR.

return nil, fmt.Errorf("failed to remove container %q of sandbox %q: %v", container.ID, podSandboxID, err)
}

if err = c.ContainerStore.Remove(container.ID); err != nil {
Copy link
Contributor

@HusterWan HusterWan Nov 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weird, we should redesign this feature

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a mapping is better. I will redesign it. THX.

ID: id,
Config: config,
Runtime: config.Annotations[anno.KubernetesRuntime],
ContainerLogMap: containerLogMap,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we use ContainerLogMap: make(map[string]string) to do initialization? since the containerLogMap is only used for assignment.

@@ -758,6 +761,12 @@ func (c *CriManager) CreateContainer(ctx context.Context, r *runtime.CreateConta
if err := c.ContainerMgr.AttachCRILog(ctx, containerID, logPath); err != nil {
return nil, err
}

sandboxMeta.ContainerLogMap[containerID] = logPath
Copy link
Contributor

@fuweid fuweid Nov 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we update the data before AttachCRILog? because we might miss the data.

@@ -489,28 +494,26 @@ func (c *CriManager) RemovePodSandbox(ctx context.Context, r *runtime.RemovePodS

// Remove all containers in the sandbox.
for _, container := range containers {
err = c.ContainerMgr.Remove(ctx, container.ID, &apitypes.ContainerRemoveOptions{Volumes: true, Force: true})
if err != nil {
if err = c.ContainerMgr.Remove(ctx, container.ID, &apitypes.ContainerRemoveOptions{Volumes: true, Force: true}); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest that you could use if err := c.ContainerMgr.Remove(); err != nil rather than if err = c.ContainerMgr.Remove(); err != nil. The only difference is that replace = with :=.

Here is my reason:

  • you should try to control the variable effect localization well. If you use =, then the effect area is very large, sometime it will override the whole context's variables. if := is enough, then we use it, you should only care about the single block's scope. This will reduce much confusions in the code. Since when I read your code, I am still thinking that if the = is on purpose and if the err in err = c.ContainerMgr.Remove() is related to the whole scope of function RemovePodSandbox , which consumes more energy of mine.

@starnop WDYT?

@starnop starnop force-pushed the cri-reopen-log branch 4 times, most recently from 8b2b31f to d8a23bc Compare November 27, 2018 08:15
@starnop
Copy link
Contributor Author

starnop commented Nov 27, 2018

All mentioned above have been updated. PTAL. THX.

@@ -765,6 +764,11 @@ func (c *CriManager) CreateContainer(ctx context.Context, r *runtime.CreateConta
// Get container log.
if config.GetLogPath() != "" {
logPath := filepath.Join(sandboxConfig.GetLogDirectory(), config.GetLogPath())
sandboxMeta.ContainerLogMap[containerID] = logPath
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@starnop containerLogMap has not been initialized

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

THX, I have updated it.

}
logPath, ok := sandboxMeta.ContainerLogMap[containerID]
if !ok {
logrus.Infof("log path of container: %q is empty", containerID)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you just print a log here. Empty logPath is not acceptable in attachCRILog.
Please also add a precheck at https://github.com/alibaba/pouch/blob/master/daemon/mgr/container.go#L975
if logPath is empty, immediately return error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For cri, it should not return error here when logPath is empty, in addition, we should return here straightly.

Copy link
Contributor

@zhuangqh zhuangqh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also cc @fuweid

Copy link
Contributor

@fuweid fuweid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -499,28 +501,26 @@ func (c *CriManager) RemovePodSandbox(ctx context.Context, r *runtime.RemovePodS

// Remove all containers in the sandbox.
for _, container := range containers {
err = c.ContainerMgr.Remove(ctx, container.ID, &apitypes.ContainerRemoveOptions{Volumes: true, Force: true})
if err != nil {
if err := c.ContainerMgr.Remove(ctx, container.ID, &apitypes.ContainerRemoveOptions{Volumes: true, Force: true}); err != nil {
return nil, fmt.Errorf("failed to remove container %q of sandbox %q: %v", container.ID, podSandboxID, err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can use errors.Wrap here because the Remove might return the 404 or specific error.

We can handle this in next pr. it is not blocked issue.

@fuweid
Copy link
Contributor

fuweid commented Dec 11, 2018

Two things should be done after this PR:

  1. use errors.Wrap in the gRPC service level because we can use Cause to check the specific error type.
  2. Missing recovery after restart pouch daemon

cc @starnop @zhuangqh

@fuweid fuweid merged commit f1d832a into AliyunContainerService:master Dec 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants