-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Remove rkt pods when exiting #3562
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import ( | |
"fmt" | ||
"io/ioutil" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"reflect" | ||
"strings" | ||
|
@@ -166,16 +167,16 @@ func TestRktDriver_Start_Wait(t *testing.T) { | |
if err != nil { | ||
t.Fatalf("err: %v", err) | ||
} | ||
defer resp.Handle.Kill() | ||
handle := resp.Handle.(*rktHandle) | ||
defer handle.Kill() | ||
|
||
// Update should be a no-op | ||
err = resp.Handle.Update(task) | ||
if err != nil { | ||
if err := handle.Update(task); err != nil { | ||
t.Fatalf("err: %v", err) | ||
} | ||
|
||
// Signal should be an error | ||
if err = resp.Handle.Signal(syscall.SIGTERM); err == nil { | ||
if err := resp.Handle.Signal(syscall.SIGTERM); err == nil { | ||
t.Fatalf("err: %v", err) | ||
} | ||
|
||
|
@@ -187,6 +188,18 @@ func TestRktDriver_Start_Wait(t *testing.T) { | |
case <-time.After(time.Duration(testutil.TestMultiplier()*15) * time.Second): | ||
t.Fatalf("timeout") | ||
} | ||
|
||
// Make sure pod was removed #3561 | ||
var stderr bytes.Buffer | ||
cmd := exec.Command(rktCmd, "status", handle.uuid) | ||
cmd.Stdout = ioutil.Discard | ||
cmd.Stderr = &stderr | ||
if err := cmd.Run(); err == nil { | ||
t.Fatalf("expected error running 'rkt status %s' on removed container", handle.uuid) | ||
} | ||
if out := stderr.String(); !strings.Contains(out, "no matches found") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems brittle if the returned error message ever changes, but other than checking for a non empty error message I don't have a better idea. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I hate resorting to |
||
t.Fatalf("expected 'no matches found' but received: %s", out) | ||
} | ||
} | ||
|
||
func TestRktDriver_Start_Wait_Skip_Trust(t *testing.T) { | ||
|
@@ -576,3 +589,23 @@ func TestRktDriver_HandlerExec(t *testing.T) { | |
t.Fatalf("error killing handle: %v", err) | ||
} | ||
} | ||
|
||
func TestRktDriver_Remove_Error(t *testing.T) { | ||
if !testutil.IsTravis() { | ||
t.Parallel() | ||
} | ||
if os.Getenv("NOMAD_TEST_RKT") == "" { | ||
t.Skip("skipping rkt tests") | ||
} | ||
|
||
ctestutils.RktCompatible(t) | ||
|
||
// Removing a non-existent pod should return an error | ||
if err := rktRemove("00000000-0000-0000-0000-000000000000"); err == nil { | ||
t.Fatalf("expected an error") | ||
} | ||
|
||
if err := rktRemove("zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"); err == nil { | ||
t.Fatalf("expected an 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.
Thinking: Should it use the created resources feature so that cleanup gets retried?
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 just tried to match Docker's behavior and this is how we do it there. I'll update rkt to use created resources.
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.
Investigated this route and it's a bit more work than I'd like to put in this PR. It involves returning CreatedResources from Driver.Start which isn't already happening and ensuring TaskDriver cleans up containers exactly when desired. Following Dockers lead for now seems safest.