Skip to content

fix use nerdctl stop a container but restart strategy still active - #6966

Closed
ningmingxiao wants to merge 1 commit into
containerd:mainfrom
ningmingxiao:dev10
Closed

ningmingxiao wants to merge 1 commit into
containerd:mainfrom
ningmingxiao:dev10

Conversation

@ningmingxiao

Copy link
Copy Markdown
Contributor

No description provided.

@k8s-ci-robot

Copy link
Copy Markdown

Hi @ningmingxiao. Thanks for your PR.

I'm waiting for a containerd member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@ningmingxiao

ningmingxiao commented May 20, 2022 •

Copy link
Copy Markdown
Contributor Author

@AkihiroSuda
@junnplus
I use nerdctl run -d --restart=always busybox sh -c "top"
nerdctl stop containerid, this container always restart.but docker doesn't restart it

@ningmingxiao ningmingxiao changed the title fix use nerdctl stop restart strategy still active fix use nerdctl stop a container but restart strategy still active May 20, 2022
@AkihiroSuda AkihiroSuda added this to the 1.7 milestone May 20, 2022
@ningmingxiao
ningmingxiao force-pushed the dev10 branch 2 times, most recently from bdc600f to 45c61bd Compare May 20, 2022 11:01
@AkihiroSuda
AkihiroSuda requested a review from junnplus May 23, 2022 01:26
@junnplus

Copy link
Copy Markdown
Member

Although for compatibility with docker, but it is no different from unless-stopped, I take a conservative view.

@AkihiroSuda

Copy link
Copy Markdown
Member

How does Docker implement always and unless-stopped? Are they really same?

@pacoxu

pacoxu commented Jun 7, 2022 •

Copy link
Copy Markdown
Contributor

Comment thread runtime/restart/restart.go Resolved

@pacoxu pacoxu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@cpuguy83 cpuguy83 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you update the commit (and PR body) to explain what this change is and why its needed?
Is there an issue open that describes the problem?

@ningmingxiao

Copy link
Copy Markdown
Contributor Author

Can you update the commit (and PR body) to explain what this change is and why its needed? Is there an issue open that describes the problem?

I use nerdctl with --restart=always to run a container,then use nerdctl stop it,but this container still auto start.

@dmcgowan dmcgowan removed this from the 1.7 milestone Feb 13, 2023
@dmcgowan dmcgowan added the status/needs-discussion Needs discussion and decision from maintainers label Feb 13, 2023
@dmcgowan

Copy link
Copy Markdown
Member

I use nerdctl with --restart=always to run a container,then use nerdctl stop it,but this container still auto start.

Why not use unless-stopped though? I understand trying to replicate some other behavior, but changing unless-stopped to be the same as always was not the original intent. Accepting this change would require deprecating unless-stopped to keep the options clean (which I don't think is what is expected here). There is value in using always a policy and using stop as a way to force a restart.

Is there another way we can give nerdctl more control of the behavior here while keeping always and unless-stopped with separate behavior?

@ningmingxiao
ningmingxiao force-pushed the dev10 branch 2 times, most recently from 78f1851 to 060125b Compare February 14, 2023 04:34
@ningmingxiao

ningmingxiao commented Feb 14, 2023 •

Copy link
Copy Markdown
Contributor Author

I use nerdctl with --restart=always to run a container,then use nerdctl stop it,but this container still auto start.

Why not use unless-stopped though? I understand trying to replicate some other behavior, but changing unless-stopped to be the same as always was not the original intent. Accepting this change would require deprecating unless-stopped to keep the options clean (which I don't think is what is expected here). There is value in using always a policy and using stop as a way to force a restart.

Is there another way we can give nerdctl more control of the behavior here while keeping always and unless-stopped with separate behavior?

always and unless-stopped almost the same,except container with restart=always will auto start with daemon if container is not runing,so I add a func to start container wtih restart=always when containerd start

@ningmingxiao
ningmingxiao force-pushed the dev10 branch 8 times, most recently from cc7f41f to 567a366 Compare February 14, 2023 10:55
@ningmingxiao

Copy link
Copy Markdown
Contributor Author

ping @dmcgowan

@ningmingxiao

Copy link
Copy Markdown
Contributor Author

Do you have any suggestions for my pr? @AkihiroSuda

func (m *monitor) reconcile(ctx context.Context) error {
if m.reconcileTimes >= 0 && m.reconcileTimes < 2 {
m.reconcileTimes++
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hard to read this

@ningmingxiao ningmingxiao Feb 17, 2023 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I write old version like

func (m *monitor) reconcile(ctx context.Context) error {
m.reconcileTimes++
//then check it out of limit
if m.reconcileTimes == math.MaxInt64 {
m.reconcileTimes = 2
}
...
}

but I found m.reconcileTimes doesn't need to plus 1 at every time, I just need m.reconcileTimes=1 ,so I use

	if m.reconcileTimes >= 0 && m.reconcileTimes < 2 {
		m.reconcileTimes++
	}

instead

@@ -122,13 +122,17 @@ func (rp *Policy) MaximumRetryCount() int {

// Reconcile reconciles the restart policy of a container.
func Reconcile(status containerd.Status, labels map[string]string) bool {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Needs an integration test

@k8s-ci-robot

Copy link
Copy Markdown

PR needs rebase.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open 90 days with no activity. This PR will be closed in 7 days unless new comments are made or the stale label is removed.

@github-actions github-actions Bot added the Stale label May 17, 2024
@github-actions

Copy link
Copy Markdown

This PR was closed because it has been stalled for 7 days with no activity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ok-to-test needs-rebase Stale status/needs-discussion Needs discussion and decision from maintainers

Projects

Status: Done
Archived in project

Development

Successfully merging this pull request may close these issues.

7 participants