Skip to content

Commit e66375b

Browse files
authored
[Fix] Cache and DBServer member removal (#689)
1 parent 9951738 commit e66375b

File tree

9 files changed

+65
-2
lines changed

9 files changed

+65
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A)
44
- Fix AKS Volume Resize mode
5+
- Use cached status in member client creation
6+
- Remove failed DBServers
57

68
## [1.1.4](https://github.com/arangodb/kube-arangodb/tree/1.1.4) (2021-02-15)
79
- Add support for spec.ClusterDomain to be able to use FQDN in ArangoDB cluster communication

pkg/deployment/context_impl.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,10 @@ func (d *Deployment) getAuth() (driver.Authentication, error) {
263263
return nil, nil
264264
}
265265

266-
secrets := d.GetKubeCli().CoreV1().Secrets(d.apiObject.GetNamespace())
266+
var secrets inspector.SecretReadInterface = d.GetKubeCli().CoreV1().Secrets(d.apiObject.GetNamespace())
267+
if currentState := d.currentState; currentState != nil {
268+
secrets = currentState.SecretReadInterface()
269+
}
267270

268271
var secret string
269272
if i := d.apiObject.Status.CurrentImage; i == nil || !features.JWTRotation().Supported(i.ArangoDBVersion, i.Enterprise) {
@@ -589,3 +592,11 @@ func (d *Deployment) GetOwnedPods() ([]v1.Pod, error) {
589592

590593
return podList, nil
591594
}
595+
596+
func (d *Deployment) GetCachedStatus() inspector.Inspector {
597+
return d.currentState
598+
}
599+
600+
func (d *Deployment) SetCachedStatus(i inspector.Inspector) {
601+
d.currentState = i
602+
}

pkg/deployment/deployment.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ type Deployment struct {
121121
inspectCRDTrigger trigger.Trigger
122122
updateDeploymentTrigger trigger.Trigger
123123
clientCache deploymentClient.Cache
124+
currentState inspector.Inspector
124125
recentInspectionErrors int
125126
clusterScalingIntegration *clusterScalingIntegration
126127
reconciler *reconcile.Reconciler

pkg/deployment/deployment_inspector.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ func (d *Deployment) inspectDeployment(lastInterval util.Interval) util.Interval
130130
func (d *Deployment) inspectDeploymentWithError(ctx context.Context, lastInterval util.Interval, cachedStatus inspector.Inspector) (nextInterval util.Interval, inspectError error) {
131131
t := time.Now()
132132

133+
d.SetCachedStatus(cachedStatus)
134+
defer d.SetCachedStatus(nil)
135+
133136
defer func() {
134137
d.deps.Log.Info().Msgf("Reconciliation loop took %s", time.Since(t))
135138
}()

pkg/deployment/reconcile/plan_builder_cluster.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,18 @@ func createClusterOperationPlan(ctx context.Context,
8888
api.NewAction(api.ActionTypeClusterMemberCleanup, api.ServerGroupCoordinators, string(id)),
8989
}
9090
}
91+
case driver.ServerRoleDBServer:
92+
if member.Status != driver.ServerStatusFailed {
93+
continue
94+
}
95+
96+
if !member.CanBeDeleted {
97+
continue
98+
}
99+
100+
return api.Plan{
101+
api.NewAction(api.ActionTypeClusterMemberCleanup, api.ServerGroupDBServers, string(id)),
102+
}
91103
}
92104
}
93105

pkg/deployment/resources/context.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ package resources
2525
import (
2626
"context"
2727

28+
"github.com/arangodb/kube-arangodb/pkg/deployment/resources/inspector"
29+
2830
"github.com/arangodb/kube-arangodb/pkg/operator/scope"
2931

3032
monitoringClient "github.com/coreos/prometheus-operator/pkg/client/versioned/typed/monitoring/v1"
@@ -103,4 +105,7 @@ type Context interface {
103105
// GetBackup receives information about a backup resource
104106
GetBackup(backup string) (*backupApi.ArangoBackup, error)
105107
GetScope() scope.Scope
108+
109+
GetCachedStatus() inspector.Inspector
110+
SetCachedStatus(i inspector.Inspector)
106111
}

pkg/deployment/resources/inspector/inspector.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ package inspector
2525
import (
2626
"sync"
2727

28+
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
29+
2830
monitoring "github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1"
2931
monitoringClient "github.com/coreos/prometheus-operator/pkg/client/versioned/typed/monitoring/v1"
3032

@@ -33,6 +35,11 @@ import (
3335
"k8s.io/client-go/kubernetes"
3436
)
3537

38+
// SecretReadInterface has methods to work with Secret resources with ReadOnly mode.
39+
type SecretReadInterface interface {
40+
Get(name string, options meta.GetOptions) (*core.Secret, error)
41+
}
42+
3643
func NewInspector(k kubernetes.Interface, m monitoringClient.MonitoringV1Interface, namespace string) (Inspector, error) {
3744
pods, err := podsToMap(k, namespace)
3845
if err != nil {
@@ -102,6 +109,7 @@ type Inspector interface {
102109

103110
Secret(name string) (*core.Secret, bool)
104111
IterateSecrets(action SecretAction, filters ...SecretFilter) error
112+
SecretReadInterface() SecretReadInterface
105113

106114
PersistentVolumeClaim(name string) (*core.PersistentVolumeClaim, bool)
107115
IteratePersistentVolumeClaims(action PersistentVolumeClaimAction, filters ...PersistentVolumeClaimFilter) error

pkg/deployment/resources/inspector/secrets.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ package inspector
2525
import (
2626
"github.com/arangodb/kube-arangodb/pkg/util/errors"
2727
core "k8s.io/api/core/v1"
28+
apiErrors "k8s.io/apimachinery/pkg/api/errors"
2829
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
30+
"k8s.io/apimachinery/pkg/runtime/schema"
2931
"k8s.io/client-go/kubernetes"
3032
)
3133

@@ -66,6 +68,25 @@ func (i *inspector) Secret(name string) (*core.Secret, bool) {
6668
return secret, true
6769
}
6870

71+
func (i *inspector) SecretReadInterface() SecretReadInterface {
72+
return &secretReadInterface{i: i}
73+
}
74+
75+
type secretReadInterface struct {
76+
i *inspector
77+
}
78+
79+
func (s secretReadInterface) Get(name string, options meta.GetOptions) (*core.Secret, error) {
80+
if s, ok := s.i.Secret(name); !ok {
81+
return nil, apiErrors.NewNotFound(schema.GroupResource{
82+
Group: core.GroupName,
83+
Resource: "Secret",
84+
}, name)
85+
} else {
86+
return s, nil
87+
}
88+
}
89+
6990
func secretsToMap(k kubernetes.Interface, namespace string) (map[string]*core.Secret, error) {
7091
secrets, err := getSecrets(k, namespace, "")
7192
if err != nil {

pkg/util/k8sutil/secrets.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ import (
3434

3535
// SecretInterface has methods to work with Secret resources.
3636
type SecretInterface interface {
37+
Get(name string, options meta.GetOptions) (*core.Secret, error)
3738
Create(*core.Secret) (*core.Secret, error)
3839
Update(*core.Secret) (*core.Secret, error)
39-
Get(name string, options meta.GetOptions) (*core.Secret, error)
4040
Delete(name string, options *meta.DeleteOptions) error
4141
Patch(name string, pt types.PatchType, data []byte, subresources ...string) (*core.Secret, error)
4242
}

0 commit comments

Comments
 (0)