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
Moving some force deletion logic from the NC into the PodGC #35541
Merged
k8s-github-robot
merged 4 commits into
kubernetes:master
from
foxish:deletions-safe-again
Oct 28, 2016
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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 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 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 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 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 |
---|---|---|
|
@@ -25,6 +25,7 @@ import ( | |
"k8s.io/kubernetes/pkg/api/unversioned" | ||
"k8s.io/kubernetes/pkg/client/cache" | ||
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake" | ||
"k8s.io/kubernetes/pkg/labels" | ||
"k8s.io/kubernetes/pkg/util/sets" | ||
) | ||
|
||
|
@@ -194,7 +195,12 @@ func TestGCOrphaned(t *testing.T) { | |
gcc.podController = &FakeController{} | ||
gcc.nodeController = &FakeController{} | ||
|
||
gcc.gc() | ||
pods, err := gcc.podStore.List(labels.Everything()) | ||
if err != nil { | ||
t.Errorf("Error while listing all Pods: %v", err) | ||
return | ||
} | ||
gcc.gcOrphaned(pods) | ||
|
||
pass := true | ||
for _, pod := range deletedPodNames { | ||
|
@@ -210,3 +216,86 @@ func TestGCOrphaned(t *testing.T) { | |
} | ||
} | ||
} | ||
|
||
func TestGCUnscheduledTerminating(t *testing.T) { | ||
type nameToPhase struct { | ||
name string | ||
phase api.PodPhase | ||
deletionTimeStamp *unversioned.Time | ||
nodeName string | ||
} | ||
|
||
testCases := []struct { | ||
name string | ||
pods []nameToPhase | ||
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. I generally find it useful to have a "name" or even better "description" per test case, which is printed with the failure, to make it easier to locate problematic test. |
||
deletedPodNames sets.String | ||
}{ | ||
{ | ||
name: "Unscheduled pod in any phase must be deleted", | ||
pods: []nameToPhase{ | ||
{name: "a", phase: api.PodFailed, deletionTimeStamp: &unversioned.Time{}, nodeName: ""}, | ||
{name: "b", phase: api.PodSucceeded, deletionTimeStamp: &unversioned.Time{}, nodeName: ""}, | ||
{name: "c", phase: api.PodRunning, deletionTimeStamp: &unversioned.Time{}, nodeName: ""}, | ||
}, | ||
deletedPodNames: sets.NewString("a", "b", "c"), | ||
}, | ||
{ | ||
name: "Scheduled pod in any phase must not be deleted", | ||
pods: []nameToPhase{ | ||
{name: "a", phase: api.PodFailed, deletionTimeStamp: nil, nodeName: ""}, | ||
{name: "b", phase: api.PodSucceeded, deletionTimeStamp: nil, nodeName: "node"}, | ||
{name: "c", phase: api.PodRunning, deletionTimeStamp: &unversioned.Time{}, nodeName: "node"}, | ||
}, | ||
deletedPodNames: sets.NewString(), | ||
}, | ||
} | ||
|
||
for i, test := range testCases { | ||
client := fake.NewSimpleClientset() | ||
gcc := NewFromClient(client, -1) | ||
deletedPodNames := make([]string, 0) | ||
var lock sync.Mutex | ||
gcc.deletePod = func(_, name string) error { | ||
lock.Lock() | ||
defer lock.Unlock() | ||
deletedPodNames = append(deletedPodNames, name) | ||
return nil | ||
} | ||
|
||
creationTime := time.Unix(0, 0) | ||
for _, pod := range test.pods { | ||
creationTime = creationTime.Add(1 * time.Hour) | ||
gcc.podStore.Indexer.Add(&api.Pod{ | ||
ObjectMeta: api.ObjectMeta{Name: pod.name, CreationTimestamp: unversioned.Time{Time: creationTime}, | ||
DeletionTimestamp: pod.deletionTimeStamp}, | ||
Status: api.PodStatus{Phase: pod.phase}, | ||
Spec: api.PodSpec{NodeName: pod.nodeName}, | ||
}) | ||
} | ||
|
||
store := cache.NewStore(cache.MetaNamespaceKeyFunc) | ||
gcc.nodeStore = cache.StoreToNodeLister{Store: store} | ||
gcc.podController = &FakeController{} | ||
gcc.nodeController = &FakeController{} | ||
|
||
pods, err := gcc.podStore.List(labels.Everything()) | ||
if err != nil { | ||
t.Errorf("Error while listing all Pods: %v", err) | ||
return | ||
} | ||
gcc.gcUnscheduledTerminating(pods) | ||
|
||
pass := true | ||
for _, pod := range deletedPodNames { | ||
if !test.deletedPodNames.Has(pod) { | ||
pass = false | ||
} | ||
} | ||
if len(deletedPodNames) != len(test.deletedPodNames) { | ||
pass = false | ||
} | ||
if !pass { | ||
t.Errorf("[%v]pod's deleted expected and actual did not match.\n\texpected: %v\n\tactual: %v, test: %v", i, test.deletedPodNames, deletedPodNames, test.name) | ||
} | ||
} | ||
} |
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.
actually I'd rename this to 'forcefullyDeletePod', 'ungracefullyDeletPod' or something along those lines. Not necessarily in this PR:)
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.
Will do in a follow-up.