Skip to content
This repository has been archived by the owner on Feb 24, 2020. It is now read-only.

pkg/pod: add WaitReady, dry Sandbox methods #3462

Merged
merged 6 commits into from
Dec 14, 2016

Conversation

s-urbaniak
Copy link
Contributor

This adds a WaitReady method to be able to wait for pod readiness on the
command line.

It also reduces reduntant implementations in stage1 for checking mutable pods
and pod manifest update logic.

Fixes #3461

@s-urbaniak s-urbaniak force-pushed the waitReady branch 2 times, most recently from 7b8898d to 8e4e579 Compare December 8, 2016 16:22
@s-urbaniak
Copy link
Contributor Author

/cc @euank

@s-urbaniak s-urbaniak added this to the v1.22.0 milestone Dec 8, 2016
@lucab
Copy link
Member

lucab commented Dec 8, 2016

It looks like there is a deadlock race.

@s-urbaniak
Copy link
Contributor Author

ack :-/

@s-urbaniak
Copy link
Contributor Author

I think I have to do refreshState in IsSupervisorReady and check if the pod is actually running.

@s-urbaniak
Copy link
Contributor Author

instead of refreshing the state in IsSupervisorReady I refresh in WaitReady (as WaitExited does) in order to keep the current semantics that most of the state query methods do not synchronize the actual pod's filesystem state.

However I added some more documentation to the existing methods and the Pod struct itself to make it more explicit which methods (i.e. the state transitioning ones) and some query methods (ContainerPid1, Wait*) refresh the actual pod state.

@s-urbaniak s-urbaniak force-pushed the waitReady branch 2 times, most recently from aaff747 to e69031b Compare December 9, 2016 14:15
if err != nil {
return err
}
defer f.Close()
Copy link
Member

Choose a reason for hiding this comment

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

From here on we have the file and we defer-closing on success; instead, on error, should we try to rm it?

if err != nil {
return err
}
defer tmpf.Close()
Copy link
Member

Choose a reason for hiding this comment

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

Same comment related to file removal.

// This method blocks indefinitely and refreshes the pod state.
func (p *Pod) WaitExited() error {
// isExited implies isExitedGarbage.
for !p.isExited && !p.isAbortedPrepare && !p.isGarbage && !p.isGone {
Copy link
Member

Choose a reason for hiding this comment

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

similar to p.AfterRun, a helper of p.TerminalState could make this clearer..

Also, technically this isn't technically a "wait exited" because isAbortedPrepare is a pre-run, but terminal, state, so this is really WaitFinished or WaitTerminal

}
}

// TODO(vc): return error or let caller detect the !p.isExited possibilities?
Copy link
Member

Choose a reason for hiding this comment

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

I would rather nix this TODO and just document in the function comment that the pod will be in a terminal state if there is no error, but it's up to the caller to determine what that state is.

@@ -46,6 +48,7 @@ const (
func init() {
cmdRkt.AddCommand(cmdStatus)
cmdStatus.Flags().BoolVar(&flagWait, "wait", false, "toggle waiting for the pod to exit")
Copy link
Member

Choose a reason for hiding this comment

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

"for the pod to reach a terminal state" is technically more correct; the caller should still ask status afterwards.

I'm not sure if there's a reason not to include a timeout here. I expect to kill the rkt process after a timeout if one isn't provided here regardless.

@@ -46,6 +48,7 @@ const (
func init() {
cmdRkt.AddCommand(cmdStatus)
cmdStatus.Flags().BoolVar(&flagWait, "wait", false, "toggle waiting for the pod to exit")
cmdStatus.Flags().DurationVar(&flagWaitReady, "wait-ready", time.Duration(0), "time to wait until the pod is ready. If time is less or equal zero it doesn't wait at all.")
Copy link
Member

Choose a reason for hiding this comment

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

I would expect '-1' to mean 'wait forever'.

@euank
Copy link
Member

euank commented Dec 9, 2016

I realize I mostly commented on code that was just being moved, not written anew. This looks okay to me on a first pass.

s-urbaniak added a commit to s-urbaniak/rkt that referenced this pull request Dec 12, 2016
This changes the rkt status --wait to accept a timeout rather than a
boolean value.

Addresses rkt#3462 (comment)
s-urbaniak added a commit to s-urbaniak/rkt that referenced this pull request Dec 12, 2016
This changes the rkt status --wait to accept a timeout in addition to a
boolean value.

Addresses rkt#3462 (comment)
s-urbaniak added a commit to s-urbaniak/rkt that referenced this pull request Dec 12, 2016
This changes the rkt status --wait to accept a timeout in addition to a
boolean value.

Addresses rkt#3462 (comment)
s-urbaniak added a commit to s-urbaniak/rkt that referenced this pull request Dec 12, 2016
This changes the rkt status --wait to accept a timeout in addition to a
boolean value.

Addresses rkt#3462 (comment)
s-urbaniak added a commit to s-urbaniak/rkt that referenced this pull request Dec 12, 2016
This changes the rkt status --wait to accept a timeout in addition to a
boolean value.

Addresses rkt#3462 (comment)
Copy link
Member

@lucab lucab left a comment

Choose a reason for hiding this comment

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

Only some typos and missing docs. Code and UX looks good.

return p.isExitedDeleting || p.isDeleting || p.isExited || p.isGarbage
}

// IsFinshed returns true if the pod is in a terminal state, else false.
Copy link
Member

Choose a reason for hiding this comment

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

IsFinished (typo: a missing "i")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

stderr.PrintE("unable to wait for pod", err)
if dReady != 0 {
if err := p.WaitReady(newContext(dReady)); err != nil {
stderr.PrintE("error waiting for pod readyiness", err)
Copy link
Member

Choose a reason for hiding this comment

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

Spelling should be fixed in the whole PR, it is written "readiness".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

)

var (
cmdStatus = &cobra.Command{
Use: "status [--wait] UUID",
Use: "status [--wait=bool|timeout] [--wait-ready=bool|timeout] UUID",
Copy link
Member

Choose a reason for hiding this comment

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

status.md should be updated with these changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

s-urbaniak added a commit to s-urbaniak/rkt that referenced this pull request Dec 12, 2016
This changes the rkt status --wait to accept a timeout in addition to a
boolean value.

Addresses rkt#3462 (comment)
@s-urbaniak
Copy link
Contributor Author

@lucab addressed review comments, PTAL

@@ -75,6 +75,7 @@ func TestAppSandboxSmoke(t *testing.T) {
cmd = strings.Fields(fmt.Sprintf("%s app add --debug %s %s --name=%s", ctx.Cmd(), podUUID, imageName, appName))
addCmd := exec.Command(cmd[0], cmd[1:]...)
addCmd.Env = append(addCmd.Env, "RKT_EXPERIMENT_APP=true")
fmt.Printf("Running command: %v\n", cmd)
Copy link
Member

Choose a reason for hiding this comment

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

nit: all these fmt.Printfs should be removed or changed to t.Logf

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah, I left it there, because this output is unbuffered, but I'll change it back to t.Logf.

// wait up to one minute for the pod supervisor to be ready
cmd := strings.Fields(fmt.Sprintf("%s status --wait-ready=%s %s", ctx.Cmd(), timeout, podUUID))
statusCmd := exec.Command(cmd[0], cmd[1:]...)
fmt.Printf("Running command: %v\n", cmd)
Copy link
Member

Choose a reason for hiding this comment

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

Same for this file

@euank
Copy link
Member

euank commented Dec 12, 2016

LGTM apart from the presumably leftover printfs

s-urbaniak added a commit to s-urbaniak/rkt that referenced this pull request Dec 13, 2016
This changes the rkt status --wait to accept a timeout in addition to a
boolean value.

Addresses rkt#3462 (comment)
s-urbaniak added a commit to s-urbaniak/rkt that referenced this pull request Dec 14, 2016
This changes the rkt status --wait to accept a timeout in addition to a
boolean value.

Addresses rkt#3462 (comment)
Copy link
Member

@lucab lucab left a comment

Choose a reason for hiding this comment

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

LGTM

This reduces reduntant implementations for checking mutable pod
manifests and pod manifest update logic.
Currently it is unclear which methods in pkg/pod refresh the pod
state and which don't. This fixes it by documenting it.
This adds a WaitReady method to be able to wait for pod readiness on the
command line.

Fixes rkt#3461
This is a minor cleanup in pkg/pod.
This changes the rkt status --wait to accept a timeout in addition to a
boolean value.

Addresses rkt#3462 (comment)
@s-urbaniak
Copy link
Contributor Author

Merging, as the the rawhide failure seems to be a flake.

@s-urbaniak s-urbaniak merged commit 8fd6c41 into rkt:master Dec 14, 2016
@lucab lucab mentioned this pull request Jan 5, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants