Skip to content

Commit 92416ac

Browse files
authored
Merge pull request #107 from arangodb/detect-missing-deployment
Quickly fail when deployment no longer exists
2 parents 250ad21 + 8a7e1a8 commit 92416ac

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

pkg/deployment/deployment.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ package deployment
2525
import (
2626
"fmt"
2727
"reflect"
28+
"sync/atomic"
2829
"time"
2930

3031
"github.com/rs/zerolog"
@@ -86,6 +87,7 @@ type Deployment struct {
8687

8788
eventCh chan *deploymentEvent
8889
stopCh chan struct{}
90+
stopped int32
8991

9092
eventsCli corev1.EventInterface
9193

@@ -154,7 +156,9 @@ func (d *Deployment) Update(apiObject *api.ArangoDeployment) {
154156
// Called when the deployment was deleted by the user.
155157
func (d *Deployment) Delete() {
156158
d.deps.Log.Info().Msg("deployment is deleted by user")
157-
close(d.stopCh)
159+
if atomic.CompareAndSwapInt32(&d.stopped, 0, 1) {
160+
close(d.stopCh)
161+
}
158162
}
159163

160164
// send given event into the deployment event queue.

pkg/deployment/deployment_inspector.go

+9
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828

2929
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1alpha"
3030
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
31+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3132
)
3233

3334
// inspectDeployment inspects the entire deployment, creates
@@ -44,6 +45,14 @@ func (d *Deployment) inspectDeployment(lastInterval time.Duration) time.Duration
4445
hasError := false
4546
ctx := context.Background()
4647

48+
// Check deployment still exists
49+
if _, err := d.deps.DatabaseCRCli.DatabaseV1alpha().ArangoDeployments(d.apiObject.GetNamespace()).Get(d.apiObject.GetName(), metav1.GetOptions{}); k8sutil.IsNotFound(err) {
50+
// Deployment is gone
51+
log.Info().Msg("Deployment is gone")
52+
d.Delete()
53+
return nextInterval
54+
}
55+
4756
// Is the deployment in failed state, if so, give up.
4857
if d.status.Phase == api.DeploymentPhaseFailed {
4958
log.Debug().Msg("Deployment is in Failed state.")

pkg/storage/local_storage.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"context"
2727
"fmt"
2828
"reflect"
29+
"sync/atomic"
2930
"time"
3031

3132
"github.com/rs/zerolog"
@@ -89,6 +90,7 @@ type LocalStorage struct {
8990

9091
eventCh chan *localStorageEvent
9192
stopCh chan struct{}
93+
stopped int32
9294

9395
eventsCli corev1.EventInterface
9496

@@ -136,7 +138,9 @@ func (ls *LocalStorage) Update(apiObject *api.ArangoLocalStorage) {
136138
// Called when the local storage was deleted by the user.
137139
func (ls *LocalStorage) Delete() {
138140
ls.deps.Log.Info().Msg("local storage is deleted by user")
139-
close(ls.stopCh)
141+
if atomic.CompareAndSwapInt32(&ls.stopped, 0, 1) {
142+
close(ls.stopCh)
143+
}
140144
}
141145

142146
// send given event into the local storage event queue.

0 commit comments

Comments
 (0)