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

pkg/pod: flatten the pod state if-ladders #3404

Merged
merged 2 commits into from Nov 23, 2016
Merged

Conversation

euank
Copy link
Member

@euank euank commented Nov 23, 2016

I think this is more readable.

This is just a refactor, as well as adding a few tests so the refactor was more likely to be correct.

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.

One concern related to a logic re-ordering which I'm not sure about.

}
stdout.Print(string(result))
case "json-pretty":
result, err := json.MarshalIndent(pods, "", "\t")
if err != nil {
stderr.PrintE("error marshaling the pods", err)
return 254
stderr.FatalE("error marshaling the pods", err)
Copy link
Member

Choose a reason for hiding this comment

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

I guess the changes in this file are spurious and belong to #3403.

{dir: p.preparedPath(), impliedStates: []*bool{&p.isPrepared}},
// For run, assume exited until the lock is tested
{dir: p.runPath(), impliedStates: []*bool{&p.isExited}},
{dir: p.garbagePath(), impliedStates: []*bool{&p.isGarbage}},
Copy link
Member

Choose a reason for hiding this comment

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

There seems to be a re-ordering happening here between garbage and exitedgarbage. I'm not sure if it is on purpose and if the result is equivalent, but reading the original code I would have expected the last two here to be swapped.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll swap them back, that wasn't intentional.

However, since the valid transitions are run -> exited garbage and prepare -> garbage, the order between those two shouldn't matter, so long as they're after their respective prior states.

{dir: p.runPath(), impliedStates: []*bool{&p.isExited}},
{dir: p.garbagePath(), impliedStates: []*bool{&p.isGarbage}},
// Exited garbage implies exited
{dir: p.exitedGarbagePath(), impliedStates: []*bool{&p.isExitedGarbage, &p.isExited}},
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 as above.

// dirStates is a list of directories -> state that directory existing
// implies.
// Its order matches the order states occur.
dirStates := []struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks, this is a much nicer way of expressing this logic.

What about each row having two sets of states - the isLocked and isUnlocked states? That would make the logic a bit further down simpler to grok.

Copy link
Member Author

@euank euank Nov 23, 2016

Choose a reason for hiding this comment

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

I gave it a try, but I'm not sure it actually ends up being that much more readable with only a trivial amount more work. here's the wip exploration, but the end result neither worked nor looked that much prettier.

I'd rather take this and stack on further refactoring as separate PRs so long as we all agree this specific change is good by itself.

Copy link
Member

Choose a reason for hiding this comment

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

sgtm

@s-urbaniak
Copy link
Contributor

There's been enough review comments, I just wanted to give a general 👍 for this :-)

@euank
Copy link
Member Author

euank commented Nov 23, 2016

Addressed @lucab's comments and squashed

@lucab lucab changed the title Flatten the pod state if-ladders in pkg/pod pkg/pod: flatten the pod state if-ladders Nov 23, 2016
@lucab lucab merged commit 89cfd3f into rkt:master Nov 23, 2016
@euank euank deleted the flatten-a-ladder branch November 23, 2016 23:15
euank added a commit to euank/rkt that referenced this pull request Jan 6, 2017
If `getPod` was called for a pod that no longer existed, a panic could
occur when trying to lock it.

This regression was introduced in rkt#3404

Fixes rkt#3513
@lucab lucab mentioned this pull request Jan 13, 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.

None yet

4 participants