-
Couldn't load subscription status.
- Fork 881
gc: Add flag 'mark-only' to mark garbage pods without deleting them. #2400
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 |
|---|---|---|
|
|
@@ -48,12 +48,14 @@ Use --grace-period=0s to effectively disable the grace-period.`, | |
| } | ||
| flagGracePeriod time.Duration | ||
| flagPreparedExpiration time.Duration | ||
| flagMarkOnly bool | ||
| ) | ||
|
|
||
| func init() { | ||
| cmdRkt.AddCommand(cmdGC) | ||
| cmdGC.Flags().DurationVar(&flagGracePeriod, "grace-period", defaultGracePeriod, "duration to wait before discarding inactive pods from garbage") | ||
| cmdGC.Flags().DurationVar(&flagPreparedExpiration, "expire-prepared", defaultPreparedExpiration, "duration to wait before expiring prepared pods") | ||
| cmdGC.Flags().BoolVar(&flagMarkOnly, "mark-only", false, "if set to true, then the exited/aborted pods will be moved to the garbage directories without actually deleting them, this is useful for marking the exit time of a pod") | ||
| } | ||
|
|
||
| func runGC(cmd *cobra.Command, args []string) (exit int) { | ||
|
|
@@ -67,6 +69,10 @@ func runGC(cmd *cobra.Command, args []string) (exit int) { | |
| return 1 | ||
| } | ||
|
|
||
| if flagMarkOnly { | ||
|
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. Why skip renameExpired? 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. @jonboulle If we don't skip renameExpired, then when doing |
||
| return | ||
| } | ||
|
|
||
| if err := renameExpired(flagPreparedExpiration); err != nil { | ||
| stderr.PrintE("failed to rename expired prepared pods", err) | ||
| return 1 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| // Copyright 2015 The rkt Authors | ||
|
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. 2016 |
||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package main | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "io/ioutil" | ||
| "os" | ||
| "path/filepath" | ||
| "testing" | ||
|
|
||
| "github.com/coreos/rkt/tests/testutils" | ||
| ) | ||
|
|
||
| func TestGC(t *testing.T) { | ||
| ctx := testutils.NewRktRunCtx() | ||
| defer ctx.Cleanup() | ||
|
|
||
| // Finished pods. | ||
| patchImportAndRun("inspect-gc-test-run.aci", []string{"--exec=/inspect --print-msg=HELLO_API --exit-code=0"}, t, ctx) | ||
|
|
||
| // Prepared pods. | ||
| patchImportAndPrepare("inspect-gc-test-prepare.aci", []string{"--exec=/inspect --print-msg=HELLO_API --exit-code=0"}, t, ctx) | ||
|
|
||
| // Abort prepare. | ||
| imagePath := patchTestACI("inspect-gc-test-abort.aci", []string{"--exec=/inspect --print-msg=HELLO_API --exit-code=0"}...) | ||
| defer os.Remove(imagePath) | ||
| cmd := fmt.Sprintf("%s --insecure-options=image prepare %s %s", ctx.Cmd(), imagePath, imagePath) | ||
| spawnAndWaitOrFail(t, cmd, 1) | ||
|
|
||
| gcCmd := fmt.Sprintf("%s gc --mark-only=true --expire-prepared=0 --grace-period=0", ctx.Cmd()) | ||
| spawnAndWaitOrFail(t, gcCmd, 0) | ||
|
|
||
| gcDirs := []string{ | ||
| filepath.Join(ctx.DataDir(), "pods", "exited-garbage"), | ||
| filepath.Join(ctx.DataDir(), "pods", "prepared"), | ||
| filepath.Join(ctx.DataDir(), "pods", "garbage"), | ||
| } | ||
|
|
||
| for _, dir := range gcDirs { | ||
| pods, err := ioutil.ReadDir(dir) | ||
| if err != nil { | ||
| t.Fatalf("cannot read gc directory %q: %v", dir, err) | ||
| } | ||
| if len(pods) == 0 { | ||
| t.Fatalf("pods should still exist in directory %q", dir) | ||
| } | ||
| } | ||
|
|
||
| gcCmd = fmt.Sprintf("%s gc --mark-only=false --expire-prepared=0 --grace-period=0", ctx.Cmd()) | ||
| spawnAndWaitOrFail(t, gcCmd, 0) | ||
|
|
||
| for _, dir := range gcDirs { | ||
| pods, err := ioutil.ReadDir(dir) | ||
| if err != nil { | ||
| t.Fatalf("cannot read gc directory %q: %v", dir, err) | ||
| } | ||
| if len(pods) != 0 { | ||
| t.Fatalf("no pods should exist in directory %q, but found: %v", dir, pods) | ||
| } | ||
| } | ||
| } | ||
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 don't like the wording, better to reference the phases/passes: https://github.com/coreos/rkt/blob/master/Documentation/devel/pod-lifecycle.md#garbage-collection
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.
or similar