Skip to content

Commit 7c16bb2

Browse files
authored
[Feature] Allow plan cleanup (#673)
1 parent 6f7c363 commit 7c16bb2

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Migrate CRD to apiextensions.k8s.io/v1
66
- Add customizable log levels per service
77
- Move Upgrade as InitContainer and fix Direct Image discovery mode
8+
- Allow to remove currently executed plan by annotation
89

910
## [1.1.2](https://github.com/arangodb/kube-arangodb/tree/1.1.2) (2020-11-11)
1011
- Fix Bootstrap phase and move it under Plan

pkg/apis/deployment/annotations.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ const (
2727
ArangoDeploymentPodMaintenanceAnnotation = ArangoDeploymentAnnotationPrefix + "/maintenance"
2828
ArangoDeploymentPodRotateAnnotation = ArangoDeploymentAnnotationPrefix + "/rotate"
2929
ArangoDeploymentPodReplaceAnnotation = ArangoDeploymentAnnotationPrefix + "/replace"
30+
ArangoDeploymentPlanCleanAnnotation = "plan." + ArangoDeploymentAnnotationPrefix + "/clean"
3031
)

pkg/deployment/deployment.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ import (
2929
"sync/atomic"
3030
"time"
3131

32+
"github.com/arangodb/kube-arangodb/pkg/deployment/patch"
33+
"k8s.io/apimachinery/pkg/types"
34+
3235
"github.com/arangodb/kube-arangodb/pkg/operator/scope"
3336

3437
monitoringClient "github.com/coreos/prometheus-operator/pkg/client/versioned/typed/monitoring/v1"
@@ -511,3 +514,23 @@ func (d *Deployment) SetNumberOfServers(ctx context.Context, noCoordinators, noD
511514
func (d *Deployment) getArangoDeployment() *api.ArangoDeployment {
512515
return d.apiObject
513516
}
517+
518+
func (d *Deployment) ApplyPatch(p ...patch.Item) error {
519+
parser := patch.Patch(p)
520+
521+
data, err := parser.Marshal()
522+
if err != nil {
523+
return err
524+
}
525+
526+
c := d.deps.DatabaseCRCli.DatabaseV1().ArangoDeployments(d.apiObject.GetNamespace())
527+
528+
depl, err := c.Patch(d.apiObject.GetName(), types.JSONPatchType, data)
529+
if err != nil {
530+
return err
531+
}
532+
533+
d.apiObject = depl
534+
535+
return nil
536+
}

pkg/deployment/deployment_inspector.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import (
2626
"context"
2727
"time"
2828

29+
"github.com/arangodb/kube-arangodb/pkg/deployment/patch"
30+
2931
operatorErrors "github.com/arangodb/kube-arangodb/pkg/util/errors"
3032

3133
"github.com/arangodb/kube-arangodb/pkg/deployment/resources/inspector"
@@ -99,6 +101,8 @@ func (d *Deployment) inspectDeployment(lastInterval util.Interval) util.Interval
99101
return nextInterval
100102
}
101103

104+
d.apiObject = updated
105+
102106
if inspectNextInterval, err := d.inspectDeploymentWithError(ctx, nextInterval, cachedStatus); err != nil {
103107
if !operatorErrors.IsReconcile(err) {
104108
nextInterval = inspectNextInterval
@@ -210,7 +214,18 @@ func (d *Deployment) inspectDeploymentWithError(ctx context.Context, lastInterva
210214
}
211215

212216
// Create scale/update plan
213-
if err, updated := d.reconciler.CreatePlan(ctx, cachedStatus); err != nil {
217+
if _, ok := d.apiObject.Annotations[deployment.ArangoDeploymentPlanCleanAnnotation]; ok {
218+
if err := d.ApplyPatch(patch.ItemRemove(patch.NewPath("metadata", "annotations", deployment.ArangoDeploymentPlanCleanAnnotation))); err != nil {
219+
return minInspectionInterval, errors.Wrapf(err, "Unable to create remove annotation patch")
220+
}
221+
222+
if err := d.WithStatusUpdate(func(s *api.DeploymentStatus) bool {
223+
s.Plan = nil
224+
return true
225+
}, true); err != nil {
226+
return minInspectionInterval, errors.Wrapf(err, "Unable clean plan")
227+
}
228+
} else if err, updated := d.reconciler.CreatePlan(ctx, cachedStatus); err != nil {
214229
return minInspectionInterval, errors.Wrapf(err, "Plan creation failed")
215230
} else if updated {
216231
return minInspectionInterval, nil

0 commit comments

Comments
 (0)