Skip to content
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

Record pod history in daemon restart e2e #14965

Merged
merged 1 commit into from
Oct 5, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
50 changes: 47 additions & 3 deletions test/e2e/daemon_restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ const (
restartTimeout = 10 * time.Minute
numPods = 10
sshPort = 22
ADD = "ADD"
DEL = "DEL"
UPDATE = "UPDATE"
)

// nodeExec execs the given cmd on node via SSH. Note that the nodeName is an sshable name,
Expand Down Expand Up @@ -126,6 +129,35 @@ func (r *restartDaemonConfig) restart() {
r.waitUp()
}

// podTracker records a serial history of events that might've affects pods.
type podTracker struct {
cache.ThreadSafeStore
}

func (p *podTracker) remember(pod *api.Pod, eventType string) {
if eventType == UPDATE && pod.Status.Phase == api.PodRunning {
Copy link
Member

Choose a reason for hiding this comment

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

Add a comment why you skip in this case?

return
}
p.Add(fmt.Sprintf("[%v] %v: %v", time.Now(), eventType, pod.Name), pod)
}

func (p *podTracker) String() (msg string) {
for _, k := range p.ListKeys() {
obj, exists := p.Get(k)
if !exists {
continue
}
pod := obj.(*api.Pod)
msg += fmt.Sprintf("%v Phase %v Host %v\n", k, pod.Status.Phase, pod.Spec.NodeName)
}
return
}

func newPodTracker() *podTracker {
return &podTracker{cache.NewThreadSafeStore(
cache.Indexers{}, cache.Indices{})}
}

// replacePods replaces content of the store with the given pods.
func replacePods(pods []*api.Pod, store cache.Store) {
found := make([]interface{}, 0, len(pods))
Expand Down Expand Up @@ -162,6 +194,7 @@ var _ = Describe("DaemonRestart", func() {
var controller *controllerFramework.Controller
var newPods cache.Store
var stopCh chan struct{}
var tracker *podTracker

BeforeEach(func() {

Expand All @@ -188,6 +221,7 @@ var _ = Describe("DaemonRestart", func() {
replacePods(*config.CreatedPods, existingPods)

stopCh = make(chan struct{})
tracker = newPodTracker()
newPods, controller = controllerFramework.NewInformer(
&cache.ListWatch{
ListFunc: func() (runtime.Object, error) {
Expand All @@ -199,7 +233,17 @@ var _ = Describe("DaemonRestart", func() {
},
&api.Pod{},
0,
controllerFramework.ResourceEventHandlerFuncs{},
controllerFramework.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
tracker.remember(obj.(*api.Pod), ADD)
},
UpdateFunc: func(oldObj, newObj interface{}) {
tracker.remember(newObj.(*api.Pod), UPDATE)
},
DeleteFunc: func(obj interface{}) {
tracker.remember(obj.(*api.Pod), DEL)
},
},
)
go controller.Run(stopCh)
})
Expand Down Expand Up @@ -235,7 +279,7 @@ var _ = Describe("DaemonRestart", func() {
}
if len(newKeys.List()) != len(existingKeys.List()) ||
!newKeys.IsSuperset(existingKeys) {
Failf("RcManager created/deleted pods after restart")
Failf("RcManager created/deleted pods after restart \n\n %+v", tracker)
}
})

Expand Down Expand Up @@ -270,7 +314,7 @@ var _ = Describe("DaemonRestart", func() {
postRestarts, badNodes := getContainerRestarts(framework.Client, ns, labelSelector)
if postRestarts != preRestarts {
dumpNodeDebugInfo(framework.Client, badNodes)
Failf("Net container restart count went from %v -> %v after kubelet restart on nodes %v", preRestarts, postRestarts, badNodes)
Failf("Net container restart count went from %v -> %v after kubelet restart on nodes %v \n\n %+v", preRestarts, postRestarts, badNodes, tracker)
}
})
})