1
0
Fork 0
mirror of https://github.com/arangodb/kube-arangodb.git synced 2024-12-14 11:57:37 +00:00

[Feature] Allow plan cleanup (#673)

This commit is contained in:
Adam Janikowski 2020-11-27 13:49:28 +01:00 committed by GitHub
parent 6f7c363fb4
commit 7c16bb29bc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 1 deletions

View file

@ -5,6 +5,7 @@
- Migrate CRD to apiextensions.k8s.io/v1
- Add customizable log levels per service
- Move Upgrade as InitContainer and fix Direct Image discovery mode
- Allow to remove currently executed plan by annotation
## [1.1.2](https://github.com/arangodb/kube-arangodb/tree/1.1.2) (2020-11-11)
- Fix Bootstrap phase and move it under Plan

View file

@ -27,4 +27,5 @@ const (
ArangoDeploymentPodMaintenanceAnnotation = ArangoDeploymentAnnotationPrefix + "/maintenance"
ArangoDeploymentPodRotateAnnotation = ArangoDeploymentAnnotationPrefix + "/rotate"
ArangoDeploymentPodReplaceAnnotation = ArangoDeploymentAnnotationPrefix + "/replace"
ArangoDeploymentPlanCleanAnnotation = "plan." + ArangoDeploymentAnnotationPrefix + "/clean"
)

View file

@ -29,6 +29,9 @@ import (
"sync/atomic"
"time"
"github.com/arangodb/kube-arangodb/pkg/deployment/patch"
"k8s.io/apimachinery/pkg/types"
"github.com/arangodb/kube-arangodb/pkg/operator/scope"
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
func (d *Deployment) getArangoDeployment() *api.ArangoDeployment {
return d.apiObject
}
func (d *Deployment) ApplyPatch(p ...patch.Item) error {
parser := patch.Patch(p)
data, err := parser.Marshal()
if err != nil {
return err
}
c := d.deps.DatabaseCRCli.DatabaseV1().ArangoDeployments(d.apiObject.GetNamespace())
depl, err := c.Patch(d.apiObject.GetName(), types.JSONPatchType, data)
if err != nil {
return err
}
d.apiObject = depl
return nil
}

View file

@ -26,6 +26,8 @@ import (
"context"
"time"
"github.com/arangodb/kube-arangodb/pkg/deployment/patch"
operatorErrors "github.com/arangodb/kube-arangodb/pkg/util/errors"
"github.com/arangodb/kube-arangodb/pkg/deployment/resources/inspector"
@ -99,6 +101,8 @@ func (d *Deployment) inspectDeployment(lastInterval util.Interval) util.Interval
return nextInterval
}
d.apiObject = updated
if inspectNextInterval, err := d.inspectDeploymentWithError(ctx, nextInterval, cachedStatus); err != nil {
if !operatorErrors.IsReconcile(err) {
nextInterval = inspectNextInterval
@ -210,7 +214,18 @@ func (d *Deployment) inspectDeploymentWithError(ctx context.Context, lastInterva
}
// Create scale/update plan
if err, updated := d.reconciler.CreatePlan(ctx, cachedStatus); err != nil {
if _, ok := d.apiObject.Annotations[deployment.ArangoDeploymentPlanCleanAnnotation]; ok {
if err := d.ApplyPatch(patch.ItemRemove(patch.NewPath("metadata", "annotations", deployment.ArangoDeploymentPlanCleanAnnotation))); err != nil {
return minInspectionInterval, errors.Wrapf(err, "Unable to create remove annotation patch")
}
if err := d.WithStatusUpdate(func(s *api.DeploymentStatus) bool {
s.Plan = nil
return true
}, true); err != nil {
return minInspectionInterval, errors.Wrapf(err, "Unable clean plan")
}
} else if err, updated := d.reconciler.CreatePlan(ctx, cachedStatus); err != nil {
return minInspectionInterval, errors.Wrapf(err, "Plan creation failed")
} else if updated {
return minInspectionInterval, nil