From 72a6535191a0d0aaff9165119a5527e8a9a7cd47 Mon Sep 17 00:00:00 2001 From: Adam Janikowski <12255597+ajanikow@users.noreply.github.com> Date: Mon, 18 Jul 2022 23:49:57 +0200 Subject: [PATCH] [Bugfix] Prevent deployment removal in case of invalid K8S API response (#1063) --- CHANGELOG.md | 1 + pkg/deployment/deployment.go | 16 ++-------------- pkg/deployment/deployment_inspector.go | 2 +- pkg/operator/operator_deployment.go | 2 +- 4 files changed, 5 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 45b9b7b60..1d85534cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - (Feature) Add 'crd install' subcommand - (Bugfix) Fix `internal` metrics mode - (Bugfix) Create agency dump if auth is disabled +- (Bugfix) Prevent deployment removal in case of invalid K8S API response ## [1.2.14](https://github.com/arangodb/kube-arangodb/tree/1.2.14) (2022-07-14) - (Feature) Add ArangoSync TLS based rotation diff --git a/pkg/deployment/deployment.go b/pkg/deployment/deployment.go index fe8e74aae..bbc2ab5ca 100644 --- a/pkg/deployment/deployment.go +++ b/pkg/deployment/deployment.go @@ -293,9 +293,9 @@ func (d *Deployment) Update(apiObject *api.ArangoDeployment) { }) } -// Delete the deployment. +// Stop the deployment. // Called when the deployment was deleted by the user. -func (d *Deployment) Delete() { +func (d *Deployment) Stop() { d.log.Info("deployment is deleted by user") if atomic.CompareAndSwapInt32(&d.stopped, 0, 1) { close(d.stopCh) @@ -359,18 +359,6 @@ func (d *Deployment) run() { for { select { case <-d.stopCh: - err := d.acs.CurrentClusterCache().Refresh(context.Background()) - if err != nil { - log.Err(err).Error("Unable to get resources") - } - // Remove finalizers from created resources - log.Info("Deployment removed, removing finalizers to prevent orphaned resources") - if _, err := d.removePodFinalizers(context.TODO(), d.GetCachedStatus()); err != nil { - log.Err(err).Warn("Failed to remove Pod finalizers") - } - if _, err := d.removePVCFinalizers(context.TODO(), d.GetCachedStatus()); err != nil { - log.Err(err).Warn("Failed to remove PVC finalizers") - } // We're being stopped. return diff --git a/pkg/deployment/deployment_inspector.go b/pkg/deployment/deployment_inspector.go index 1c1287421..cd93dfddb 100644 --- a/pkg/deployment/deployment_inspector.go +++ b/pkg/deployment/deployment_inspector.go @@ -74,7 +74,7 @@ func (d *Deployment) inspectDeployment(lastInterval util.Interval) util.Interval if k8sutil.IsNotFound(err) { // Deployment is gone d.log.Info("Deployment is gone") - d.Delete() + d.Stop() return nextInterval } else if updated != nil && updated.GetDeletionTimestamp() != nil { // Deployment is marked for deletion diff --git a/pkg/operator/operator_deployment.go b/pkg/operator/operator_deployment.go index dde66fcc5..793184179 100644 --- a/pkg/operator/operator_deployment.go +++ b/pkg/operator/operator_deployment.go @@ -185,7 +185,7 @@ func (o *Operator) handleDeploymentEvent(event *Event) error { if !ok { return errors.WithStack(errors.Newf("unsafe state. deployment (%s) was never created but we received event (%s)", apiObject.Name, event.Type)) } - depl.Delete() + depl.Stop() delete(o.deployments, apiObject.Name) deploymentsDeleted.Inc() deploymentsCurrent.Set(float64(len(o.deployments)))