This repository was archived by the owner on Feb 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 882
gc: Add flag 'mark-only' to mark garbage pods without deleting them. #2400
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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- --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- --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) | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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