-
Notifications
You must be signed in to change notification settings - Fork 949
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
Conversation
Codecov Report
@@ 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
|
cri/v1alpha2/cri.go
Outdated
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") |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
cri/v1alpha2/cri.go
Outdated
@@ -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{ |
There was a problem hiding this comment.
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.
cri/v1alpha2/cri.go
Outdated
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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
2974c5a
to
c65a77a
Compare
c65a77a
to
3be703a
Compare
3be703a
to
6f0fc8f
Compare
6f0fc8f
to
dac6165
Compare
d0f3510
to
08a101b
Compare
cri/v1alpha2/cri.go
Outdated
ID: id, | ||
Config: config, | ||
Runtime: config.Annotations[anno.KubernetesRuntime], | ||
ContainerLogMap: containerLogMap, |
There was a problem hiding this comment.
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.
cri/v1alpha2/cri.go
Outdated
@@ -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 |
There was a problem hiding this comment.
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.
cri/v1alpha2/cri.go
Outdated
@@ -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 { |
There was a problem hiding this comment.
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 theerr
inerr = c.ContainerMgr.Remove()
is related to the whole scope of functionRemovePodSandbox
, which consumes more energy of mine.
@starnop WDYT?
8b2b31f
to
d8a23bc
Compare
All mentioned above have been updated. PTAL. THX. |
d8a23bc
to
65af91b
Compare
@@ -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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
65af91b
to
87f7ff2
Compare
cri/v1alpha2/cri.go
Outdated
} | ||
logPath, ok := sandboxMeta.ContainerLogMap[containerID] | ||
if !ok { | ||
logrus.Infof("log path of container: %q is empty", containerID) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
Signed-off-by: Starnop <[email protected]>
87f7ff2
to
8467cbf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also cc @fuweid
There was a problem hiding this 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) |
There was a problem hiding this comment.
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.
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
Ⅴ. Special notes for reviews