Skip to content

Commit

Permalink
chore: include helpful trace and debug log entries
Browse files Browse the repository at this point in the history
  • Loading branch information
cognifloyd committed Apr 13, 2022
1 parent c88bbc3 commit 1b67d23
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 7 additions & 1 deletion runtime/kubernetes/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,8 @@ func (p *podTracker) inspectContainerStatuses(pod *v1.Pod) {
//
// https://pkg.go.dev/k8s.io/api/core/v1?tab=doc#PodStatus
if pod.Status.Phase == v1.PodPending {
p.Logger.Debugf("skipping container status inspection as pod %s is pending", p.TrackedPod)

// nothing to inspect if pod is in a pending state
return
}
Expand All @@ -333,7 +335,9 @@ func (p *podTracker) inspectContainerStatuses(pod *v1.Pod) {
// get the containerTracker for this container
tracker, ok := p.Containers[cst.Name]
if !ok {
// unknown container
// unknown container (probably a sidecar injected by an admissions controller)
p.Logger.Debugf("ignoring untracked container %s from pod %s", cst.Name, p.TrackedPod)

continue
}

Expand All @@ -342,6 +346,8 @@ func (p *podTracker) inspectContainerStatuses(pod *v1.Pod) {
// https://pkg.go.dev/k8s.io/api/core/v1?tab=doc#ContainerState
if cst.State.Terminated != nil {
tracker.terminatedOnce.Do(func() {
p.Logger.Debugf("container completed: %s in pod %s", cst.Name, p.TrackedPod)

// let WaitContainer know the container is terminated
close(tracker.Terminated)
})
Expand Down
8 changes: 8 additions & 0 deletions runtime/kubernetes/pod_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ func (p *podTracker) HandlePodAdd(newObj interface{}) {
return
}

p.Logger.Tracef("handling pod add event for %s", p.TrackedPod)

p.inspectContainerStatuses(newPod)
}

Expand All @@ -87,6 +89,8 @@ func (p *podTracker) HandlePodUpdate(oldObj, newObj interface{}) {
// }
//}

p.Logger.Tracef("handling pod update event for %s", p.TrackedPod)

p.inspectContainerStatuses(newPod)
}

Expand All @@ -98,6 +102,8 @@ func (p *podTracker) HandlePodDelete(oldObj interface{}) {
return
}

p.Logger.Tracef("handling pod delete event for %s", p.TrackedPod)

p.inspectContainerStatuses(oldPod)
}

Expand Down Expand Up @@ -143,6 +149,8 @@ func (p *podTracker) Start(ctx context.Context) {

// TrackContainers creates a containerTracker for each container.
func (p *podTracker) TrackContainers(containers []v1.Container) {
p.Logger.Tracef("tracking %d more containers for pod %s", len(containers), p.TrackedPod)

if p.Containers == nil {
p.Containers = map[string]*containerTracker{}
}
Expand Down

0 comments on commit 1b67d23

Please sign in to comment.