Skip to content

Commit 446d064

Browse files
Revert "[POA-3109] Handle panic while stopping apidump process while … (#95)
…daemonset exit (#90)" This reverts commit 2909f60.
1 parent d164ef1 commit 446d064

File tree

5 files changed

+23
-14
lines changed

5 files changed

+23
-14
lines changed

cmd/internal/kube/daemonset/apidump_process.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ func (d *Daemonset) StartApiDumpProcess(podUID types.UID) error {
3737
// Decrement the wait group counter
3838
d.ApidumpProcessesWG.Done()
3939

40-
// Close the stop channel once the apidump process is exited
41-
close(podArgs.StopChan)
42-
4340
nextState := TrafficMonitoringEnded
4441

4542
if err := recover(); err != nil {
@@ -103,17 +100,18 @@ func (d *Daemonset) StartApiDumpProcess(podUID types.UID) error {
103100
return nil
104101
}
105102

106-
// SignalApiDumpProcessToStop signals the API dump process to stop for a given pod
103+
// StopApiDumpProcess signals the API dump process to stop for a given pod
107104
// identified by its UID. It retrieves the process's stop channel object from a map
108105
// and sends a stop signal to trigger apidump shutdown.
109-
func (d *Daemonset) SignalApiDumpProcessToStop(podUID types.UID, stopErr error) error {
106+
func (d *Daemonset) StopApiDumpProcess(podUID types.UID, stopErr error) error {
110107
podArgs, err := d.getPodArgsFromMap(podUID)
111108
if err != nil {
112109
return err
113110
}
114111

115112
printer.Infof("Stopping API dump process for pod %s\n", podArgs.PodName)
116113
podArgs.StopChan <- stopErr
114+
close(podArgs.StopChan)
117115

118116
return nil
119117
}

cmd/internal/kube/daemonset/daemonset.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,11 @@ func (d *Daemonset) StopAllApiDumpProcesses() {
343343
podUID := k.(types.UID)
344344
podArgs := v.(*PodArgs)
345345

346+
if podArgs.isEndState() {
347+
printer.Debugf("API dump process for pod %s already stopped, state: %s\n", podArgs.PodName, podArgs.PodTrafficMonitorState)
348+
return true
349+
}
350+
346351
// Since this state can happen at any time so no check for allowed current states
347352
err := podArgs.changePodTrafficMonitorState(DaemonSetShutdown)
348353
if err != nil {
@@ -351,7 +356,7 @@ func (d *Daemonset) StopAllApiDumpProcesses() {
351356
return true
352357
}
353358

354-
err = d.SignalApiDumpProcessToStop(podUID, errors.Errorf("Daemonset agent is shutting down, stopping pod: %s", podArgs.PodName))
359+
err = d.StopApiDumpProcess(podUID, errors.Errorf("Daemonset agent is shutting down, stopping pod: %s", podArgs.PodName))
355360
if err != nil {
356361
printer.Errorf("Failed to stop api dump process, pod name: %s, error: %v\n", podArgs.PodName, err)
357362
}

cmd/internal/kube/daemonset/kube_events_worker.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ func (d *Daemonset) handlePodDeleteEvent(pod coreV1.Pod) {
8787
return
8888
}
8989

90+
if podArgs.isEndState() {
91+
printer.Debugf("Pod %s already stopped monitoring, state: %s\n", podArgs.PodName, podArgs.PodTrafficMonitorState)
92+
return
93+
}
94+
9095
var podStatus PodTrafficMonitorState
9196
switch pod.Status.Phase {
9297
case coreV1.PodSucceeded:
@@ -105,7 +110,7 @@ func (d *Daemonset) handlePodDeleteEvent(pod coreV1.Pod) {
105110
return
106111
}
107112

108-
err = d.SignalApiDumpProcessToStop(pod.UID, errors.Errorf("got pod delete event, pod: %s", podArgs.PodName))
113+
err = d.StopApiDumpProcess(pod.UID, errors.Errorf("got pod delete event, pod: %s", podArgs.PodName))
109114
if err != nil {
110115
printer.Errorf("Failed to stop api dump process, pod name: %s, error: %v\n", podArgs.PodName, err)
111116
}

cmd/internal/kube/daemonset/pod_args.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,6 @@ func (p *PodArgs) changePodTrafficMonitorState(
8484
p.StateChangeMutex.Lock()
8585
defer p.StateChangeMutex.Unlock()
8686

87-
if isTrafficMonitoringInFinalState(p) {
88-
return errors.New(fmt.Sprintf("API dump process for pod %s already in final state, state: %s\n", p.PodName, p.PodTrafficMonitorState))
89-
}
90-
9187
// Check if the current state is allowed for the transition
9288
// If the allowedCurrentStates is empty, then any state is allowed
9389
if len(allowedCurrentStates) != 0 && !slices.Contains(allowedCurrentStates, p.PodTrafficMonitorState) {
@@ -102,8 +98,8 @@ func (p *PodArgs) changePodTrafficMonitorState(
10298
return nil
10399
}
104100

105-
// isTrafficMonitoringInFinalState checks if the pod traffic monitor state is in the final state.
106-
func isTrafficMonitoringInFinalState(p *PodArgs) bool {
101+
// isEndState checks if the pod traffic monitor state is in the final state.
102+
func (p *PodArgs) isEndState() bool {
107103
switch p.PodTrafficMonitorState {
108104
case TrafficMonitoringEnded, TrafficMonitoringFailed, RemovePodFromMap:
109105
return true

cmd/internal/kube/daemonset/pods_healthcheck_worker.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ func (d *Daemonset) handleTerminatedPod(podUID types.UID, podStatusErr error, po
6060
return
6161
}
6262

63+
if podArgs.isEndState() {
64+
printer.Debugf("Pod %s already stopped monitoring, state: %s\n", podArgs.PodName, podArgs.PodTrafficMonitorState)
65+
return
66+
}
67+
6368
// If pod doesn't exists anymore, we don't need to check the pod status
6469
// We can directly change the state to PodTerminated
6570
if podDoesNotExists {
@@ -73,7 +78,7 @@ func (d *Daemonset) handleTerminatedPod(podUID types.UID, podStatusErr error, po
7378
return
7479
}
7580

76-
err = d.SignalApiDumpProcessToStop(podUID, podStatusErr)
81+
err = d.StopApiDumpProcess(podUID, podStatusErr)
7782
if err != nil {
7883
printer.Errorf("Failed to stop api dump process, pod name: %s, error: %v\n", podArgs.PodName, err)
7984
}

0 commit comments

Comments
 (0)