8000 Add Recover · arangodb/kube-arangodb@27e0e13 · GitHub
[go: up one dir, main page]

Skip to content

Commit 27e0e13

Browse files
committed
Add Recover
1 parent e83bbf4 commit 27e0e13

File tree

8 files changed

+49
-27
lines changed

8 files changed

+49
-27
lines changed

docs/api/ArangoDeployment.V1.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3045,7 +3045,7 @@ Type: `boolean` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.
30453045

30463046
### .spec.gateway.enabled
30473047

3048-
Type: `boolean` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.42/pkg/apis/deployment/v1/deployment_spec_gateway.go#L4)</sup>
3048+
Type: `boolean` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.42/pkg/apis/deployment/v1/deployment_spec_gateway.go#L24)</sup>
30493049

30503050
***
30513051

pkg/apis/deployment/v1/deployment_spec.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -393,9 +393,12 @@ func (s DeploymentSpec) GetServerGroupSpec(group ServerGroup) ServerGroupSpec {
393393
case ServerGroupSyncWorkers:
394394
return s.SyncWorkers.WithGroup(group)
395395
case ServerGroupGateways:
396-
return s.Gateways.WithGroup(group)
396+
if g := s.Gateways; g != nil {
397+
return g.WithGroup(group)
398+
}
399+
return ServerGroupSpec{}.WithGroup(group)
397400
default:
398-
return ServerGroupSpec{}
401+
return ServerGroupSpec{}.WithGroup(group)
399402
}
400403
}
401404

@@ -436,11 +439,6 @@ func (s *DeploymentSpec) SetDefaults(deploymentName string) {
436439
if s.GetImagePullPolicy() == "" {
437440
s.ImagePullPolicy = util.NewType[core.PullPolicy](core.PullIfNotPresent)
438441
}
439-
if s.Gateway.IsEnabled() {
440-
if s.Gateways == nil {
441-
s.Gateways = &ServerGroupSpec{}
442-
}
443-
}
444442
s.ExternalAccess.SetDefaults()
445443
s.RocksDB.SetDefaults()
446444
s.Authentication.SetDefaults(deploymentName + "-jwt")
@@ -452,7 +450,16 @@ func (s *DeploymentSpec) SetDefaults(deploymentName string) {
452450
s.Coordinators.SetDefaults(ServerGroupCoordinators, s.GetMode().HasCoordinators(), s.GetMode())
453451
s.SyncMasters.SetDefaults(ServerGroupSyncMasters, s.Sync.IsEnabled(), s.GetMode())
454452
s.SyncWorkers.SetDefaults(ServerGroupSyncWorkers, s.Sync.IsEnabled(), s.GetMode())
455-
s.Gateways.SetDefaults(ServerGroupGateways, s.IsGatewayEnabled(), s.GetMode())
453+
454+
// Gateway
455+
if s.Gateway.IsEnabled() {
456+
if s.Gateways == nil {
457+
s.Gateways = &ServerGroupSpec{}
458+
}
459+
460+
s.Gateways.SetDefaults(ServerGroupGateways, true, s.GetMode())
461+
}
462+
456463
s.Metrics.SetDefaults(deploymentName+"-exporter-jwt-token", s.Authentication.IsAuthenticated())
457464
s.Chaos.SetDefaults()
458465
s.Bootstrap.SetDefaults(deploymentName)

pkg/apis/deployment/v1/server_group_spec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ func setStorageDefaultsFromResourceList(s *core.ResourceList, source core.Resour
675675

676676
// SetDefaultsFrom fills unspecified fields with a value from given source spec.
677677
func (s *ServerGroupSpec) SetDefaultsFrom(source *ServerGroupSpec) {
678-
if source == nil {
678+
if source == nil || s == nil {
679679
return
680680
}
681681

pkg/apis/deployment/v2alpha1/deployment_spec.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -393,9 +393,12 @@ func (s DeploymentSpec) GetServerGroupSpec(group ServerGroup) ServerGroupSpec {
393393
case ServerGroupSyncWorkers:
394394
return s.SyncWorkers.WithGroup(group)
395395
case ServerGroupGateways:
396-
return s.Gateways.WithGroup(group)
396+
if g := s.Gateways; g != nil {
397+
return g.WithGroup(group)
398+
}
399+
return ServerGroupSpec{}.WithGroup(group)
397400
default:
398-
return ServerGroupSpec{}
401+
return ServerGroupSpec{}.WithGroup(group)
399402
}
400403
}
401404

@@ -436,11 +439,6 @@ func (s *DeploymentSpec) SetDefaults(deploymentName string) {
436439
if s.GetImagePullPolicy() == "" {
437440
s.ImagePullPolicy = util.NewType[core.PullPolicy](core.PullIfNotPresent)
438441
}
439-
if s.Gateway.IsEnabled() {
440-
if s.Gateways == nil {
441-
s.Gateways = &ServerGroupSpec{}
442-
}
443-
}
444442
s.ExternalAccess.SetDefaults()
445443
s.RocksDB.SetDefaults()
446444
s.Authentication.SetDefaults(deploymentName + "-jwt")
@@ -452,7 +450,16 @@ func (s *DeploymentSpec) SetDefaults(deploymentName string) {
452450
s.Coordinators.SetDefaults(ServerGroupCoordinators, s.GetMode().HasCoordinators(), s.GetMode())
453451
s.SyncMasters.SetDefaults(ServerGroupSyncMasters, s.Sync.IsEnabled(), s.GetMode())
454452
s.SyncWorkers.SetDefaults(ServerGroupSyncWorkers, s.Sync.IsEnabled(), s.GetMode())
455-
s.Gateways.SetDefaults(ServerGroupGateways, s.IsGatewayEnabled(), s.GetMode())
453+
454+
// Gateway
455+
if s.Gateway.IsEnabled() {
456+
if s.Gateways == nil {
457+
s.Gateways = &ServerGroupSpec{}
458+
}
459+
460+
s.Gateways.SetDefaults(ServerGroupGateways, s.Gateway.IsEnabled(), s.GetMode())
461+
}
462+
456463
s.Metrics.SetDefaults(deploymentName+"-exporter-jwt-token", s.Authentication.IsAuthenticated())
457464
s.Chaos.SetDefaults()
458465
s.Bootstrap.SetDefaults(deploymentName)

pkg/apis/deployment/v2alpha1/server_group_spec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ func setStorageDefaultsFromResourceList(s *core.ResourceList, source core.Resour
675675

676676
// SetDefaultsFrom fills unspecified fields with a value from given source spec.
677677
func (s *ServerGroupSpec) SetDefaultsFrom(source *ServerGroupSpec) {
678-
if source == nil {
678+
if source == nil || s == nil {
679679
return
680680
}
681681

pkg/deployment/deployment_inspector.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"github.com/arangodb/kube-arangodb/pkg/upgrade"
3535
"github.com/arangodb/kube-arangodb/pkg/util"
3636
"github.com/arangodb/kube-arangodb/pkg/util/errors"
37+
"github.com/arangodb/kube-arangodb/pkg/util/errors/panics"
3738
"github.com/arangodb/kube-arangodb/pkg/util/globals"
3839
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
3940
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors"
@@ -186,7 +187,7 @@ func (d *Deployment) inspectDeployment(lastInterval util.Interval) util.Interval
186187
return nextInterval.ReduceTo(maxInspectionInterval)
187188
}
188189

189-
inspectNextInterval, err := d.inspectDeploymentWithError(ctxReconciliation, nextInterval)
190+
inspectNextInterval, err := panics.RecoverP2O1(d.inspectDeploymentWithError)(ctxReconciliation, nextInterval)
190191
if err != nil {
191192
if !errors.IsReconcile(err) {
192193
nextInterval = inspectNextInterval

pkg/operator/operator_deployment.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,6 @@ func (o *Operator) handleDeploymentEvent(event *Event) error {
149149
return errors.WithStack(errors.Errorf("ignore failed deployment (%s). Please delete its CR", apiObject.Name))
150150
}
151151

152-
defer func() {
153-
// recover() will return nil if there's no panic
154-
if r := recover(); r != nil {
155-
o.log.Error("Recovered from panic:", r)
156-
}
157-
}()
158-
159152
switch event.Type {
160153
case kwatch.Added:
161154
if _, ok := o.deployments[apiObject.Name]; ok {

pkg/util/errors/panics/recovery.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,17 @@ func recoverPanic(skipFrames int, in func() error) (err error) {
3333
func Recover(in func() error) (err error) {
3434
return recoverPanic(4, in)
3535
}
36+
37+
type RecoverP2O1Func[P1, P2, O1 any] func(p1 P1, p2 P2) (O1, error)
38+
39+
func RecoverP2O1[P1, P2, O1 any](in RecoverP2O1Func[P1, P2, O1]) RecoverP2O1Func[P1, P2, O1] {
40+
return func(p1 P1, p2 P2) (o1 O1, err error) {
41+
defer func() {
42+
if r := recover(); r != nil {
43+
err = newPanicError(r, GetStack(4))
44+
}
45+
}()
46+
47+
return in(p1, p2)
48+
}
49+
}

0 commit comments

Comments
 (0)
0