Skip to content
This repository was archived by the owner on Jan 16, 2023. It is now read-only.

Commit 57c574e

Browse files
committed
DEV-49675 Synchronous develop branch, add the recover panic logic for deployments
1 parent 978c9a1 commit 57c574e

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

pkg/sync/initsyncer.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ func (i *InitSyncer) InitSync() {
6565
}()
6666
case constants.DeploymentDeviceGroupName:
6767
go func() {
68+
// Due to panic error in this call stack will crash the application; recovering those panics here could make our application robust.
69+
defer err.RecoverError("Sync deployments")
6870
defer wg.Done()
6971
i.initSyncPodsOrServicesOrDeploys(constants.DeploymentDeviceGroupName, rest.ID)
7072
log.Infof("Finish syncing %v", constants.DeploymentDeviceGroupName)

pkg/watch/deployment/deployment.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ package deployment
55
import (
66
"fmt"
77

8+
"github.com/logicmonitor/k8s-argus/pkg/err"
9+
810
"github.com/logicmonitor/k8s-argus/pkg/constants"
911
"github.com/logicmonitor/k8s-argus/pkg/types"
1012
"github.com/logicmonitor/k8s-argus/pkg/utilities"
@@ -42,6 +44,8 @@ func (w *Watcher) ObjType() runtime.Object {
4244
// AddFunc is a function that implements the Watcher interface.
4345
func (w *Watcher) AddFunc() func(obj interface{}) {
4446
return func(obj interface{}) {
47+
// Due to panic error in this call stack will crash the application; recovering those panics here could make our application robust.
48+
defer err.RecoverError("Add deployment")
4549
deployment := obj.(*v1beta2.Deployment)
4650

4751
log.Infof("Handling add deployment event: %s", deployment.Name)
@@ -53,6 +57,8 @@ func (w *Watcher) AddFunc() func(obj interface{}) {
5357
// UpdateFunc is a function that implements the Watcher interface.
5458
func (w *Watcher) UpdateFunc() func(oldObj, newObj interface{}) {
5559
return func(oldObj, newObj interface{}) {
60+
// Due to panic error in this call stack will crash the application; recovering those panics here could make our application robust.
61+
defer err.RecoverError("Update deployment")
5662
old := oldObj.(*v1beta2.Deployment)
5763
new := newObj.(*v1beta2.Deployment)
5864

@@ -63,6 +69,8 @@ func (w *Watcher) UpdateFunc() func(oldObj, newObj interface{}) {
6369
// DeleteFunc is a function that implements the Watcher interface.
6470
func (w *Watcher) DeleteFunc() func(obj interface{}) {
6571
return func(obj interface{}) {
72+
// Due to panic error in this call stack will crash the application; recovering those panics here could make our application robust.
73+
defer err.RecoverError("Delete deployment")
6674
deployment := obj.(*v1beta2.Deployment)
6775

6876
// Delete the deployment.

0 commit comments

Comments
 (0)