From ee6d5c87af130fb7e8f656fe1c4165fe838e719c Mon Sep 17 00:00:00 2001 From: Bohdan Siryk Date: Fri, 22 Sep 2023 13:36:59 +0300 Subject: [PATCH] issue-572, handling external deletion of clusters was implemented --- controllers/clusters/cadence_controller.go | 60 +++++++------------ controllers/clusters/cassandra_controller.go | 60 +++++++------------ controllers/clusters/helpers.go | 17 +----- controllers/clusters/kafka_controller.go | 48 ++++----------- .../clusters/kafkaconnect_controller.go | 60 +++++++------------ controllers/clusters/opensearch_controller.go | 60 +++++++------------ controllers/clusters/postgresql_controller.go | 60 +++++++------------ controllers/clusters/redis_controller.go | 60 +++++++------------ controllers/clusters/zookeeper_controller.go | 48 ++++----------- pkg/instaclustr/errors.go | 1 + pkg/models/apiv1.go | 1 - pkg/models/apiv2.go | 2 + pkg/models/operator.go | 1 + 13 files changed, 154 insertions(+), 324 deletions(-) diff --git a/controllers/clusters/cadence_controller.go b/controllers/clusters/cadence_controller.go index af59a3668..6c5378a08 100644 --- a/controllers/clusters/cadence_controller.go +++ b/controllers/clusters/cadence_controller.go @@ -790,45 +790,7 @@ func (r *CadenceReconciler) newWatchStatusJob(cadence *v1beta1.Cadence) schedule iData, err := r.API.GetCadence(cadence.Status.ID) if err != nil { if errors.Is(err, instaclustr.NotFound) { - activeClusters, err := r.API.ListClusters() - if err != nil { - l.Error(err, "Cannot list account active clusters") - return err - } - - if !isClusterActive(cadence.Status.ID, activeClusters) { - l.Info("Cluster is not found in Instaclustr. Deleting resource.", - "cluster ID", cadence.Status.ClusterStatus.ID, - "cluster name", cadence.Spec.Name, - ) - - patch := cadence.NewPatch() - cadence.Annotations[models.ClusterDeletionAnnotation] = "" - cadence.Annotations[models.ResourceStateAnnotation] = models.DeletingEvent - err = r.Patch(context.TODO(), cadence, patch) - if err != nil { - l.Error(err, "Cannot patch Cadence cluster resource", - "cluster ID", cadence.Status.ID, - "cluster name", cadence.Spec.Name, - "resource name", cadence.Name, - ) - - return err - } - - err = r.Delete(context.TODO(), cadence) - if err != nil { - l.Error(err, "Cannot delete Cadence cluster resource", - "cluster ID", cadence.Status.ID, - "cluster name", cadence.Spec.Name, - "resource name", cadence.Name, - ) - - return err - } - - return nil - } + return r.handleExternalDelete(context.Background(), cadence) } l.Error(err, "Cannot get Cadence cluster from the Instaclustr API", @@ -1281,3 +1243,23 @@ func (r *CadenceReconciler) reconcileMaintenanceEvents(ctx context.Context, c *v return nil } + +func (r *CadenceReconciler) handleExternalDelete(ctx context.Context, c *v1beta1.Cadence) error { + l := log.FromContext(ctx) + + patch := c.NewPatch() + c.Status.State = models.DeletedStatus + err := r.Status().Patch(ctx, c, patch) + if err != nil { + return err + } + + l.Info(instaclustr.MsgInstaclustrResourceNotFound) + r.EventRecorder.Eventf(c, models.Warning, models.ExternalDeleted, instaclustr.MsgInstaclustrResourceNotFound) + + r.Scheduler.RemoveJob(c.GetJobID(scheduler.BackupsChecker)) + r.Scheduler.RemoveJob(c.GetJobID(scheduler.UserCreator)) + r.Scheduler.RemoveJob(c.GetJobID(scheduler.StatusChecker)) + + return nil +} diff --git a/controllers/clusters/cassandra_controller.go b/controllers/clusters/cassandra_controller.go index 3368b66a6..05302704b 100644 --- a/controllers/clusters/cassandra_controller.go +++ b/controllers/clusters/cassandra_controller.go @@ -885,45 +885,7 @@ func (r *CassandraReconciler) newWatchStatusJob(cassandra *v1beta1.Cassandra) sc iData, err := r.API.GetCassandra(cassandra.Status.ID) if err != nil { if errors.Is(err, instaclustr.NotFound) { - activeClusters, err := r.API.ListClusters() - if err != nil { - l.Error(err, "Cannot list account active clusters") - return err - } - - if !isClusterActive(cassandra.Status.ID, activeClusters) { - l.Info("Cluster is not found in Instaclustr. Deleting resource.", - "cluster ID", cassandra.Status.ClusterStatus.ID, - "cluster name", cassandra.Spec.Name, - ) - - patch := cassandra.NewPatch() - cassandra.Annotations[models.ClusterDeletionAnnotation] = "" - cassandra.Annotations[models.ResourceStateAnnotation] = models.DeletingEvent - err = r.Patch(context.TODO(), cassandra, patch) - if err != nil { - l.Error(err, "Cannot patch Cassandra cluster resource", - "cluster ID", cassandra.Status.ID, - "cluster name", cassandra.Spec.Name, - "resource name", cassandra.Name, - ) - - return err - } - - err = r.Delete(context.TODO(), cassandra) - if err != nil { - l.Error(err, "Cannot delete Cassandra cluster resource", - "cluster ID", cassandra.Status.ID, - "cluster name", cassandra.Spec.Name, - "resource name", cassandra.Name, - ) - - return err - } - - return nil - } + return r.handleExternalDelete(context.Background(), cassandra) } l.Error(err, "Cannot get cluster from the Instaclustr API", @@ -1262,6 +1224,26 @@ func (r *CassandraReconciler) reconcileMaintenanceEvents(ctx context.Context, c return nil } +func (r *CassandraReconciler) handleExternalDelete(ctx context.Context, c *v1beta1.Cassandra) error { + l := log.FromContext(ctx) + + patch := c.NewPatch() + c.Status.State = models.DeletedStatus + err := r.Status().Patch(ctx, c, patch) + if err != nil { + return err + } + + l.Info(instaclustr.MsgInstaclustrResourceNotFound) + r.EventRecorder.Eventf(c, models.Warning, models.ExternalDeleted, instaclustr.MsgInstaclustrResourceNotFound) + + r.Scheduler.RemoveJob(c.GetJobID(scheduler.BackupsChecker)) + r.Scheduler.RemoveJob(c.GetJobID(scheduler.UserCreator)) + r.Scheduler.RemoveJob(c.GetJobID(scheduler.StatusChecker)) + + return nil +} + // SetupWithManager sets up the controller with the Manager. func (r *CassandraReconciler) SetupWithManager(mgr ctrl.Manager) error { return ctrl.NewControllerManagedBy(mgr). diff --git a/controllers/clusters/helpers.go b/controllers/clusters/helpers.go index 806f71dfb..c94c1a247 100644 --- a/controllers/clusters/helpers.go +++ b/controllers/clusters/helpers.go @@ -22,11 +22,10 @@ import ( "sort" "github.com/hashicorp/go-version" - "k8s.io/utils/strings/slices" - "sigs.k8s.io/controller-runtime/pkg/client" - "github.com/instaclustr/operator/apis/clusters/v1beta1" "github.com/instaclustr/operator/pkg/models" + "k8s.io/utils/strings/slices" + "sigs.k8s.io/controller-runtime/pkg/client" ) // confirmDeletion confirms if resource is deleting and set appropriate annotation. @@ -135,18 +134,6 @@ func isDataCentreNodesEqual(a, b []*v1beta1.Node) bool { return true } -func isClusterActive(clusterID string, activeClusters []*models.ActiveClusters) bool { - for _, activeCluster := range activeClusters { - for _, cluster := range activeCluster.Clusters { - if cluster.ID == clusterID { - return true - } - } - } - - return false -} - func getSortedAppVersions(versions []*models.AppVersions, appType string) []*version.Version { for _, apps := range versions { if apps.Application == appType { diff --git a/controllers/clusters/kafka_controller.go b/controllers/clusters/kafka_controller.go index c480ac2e2..1b336aab1 100644 --- a/controllers/clusters/kafka_controller.go +++ b/controllers/clusters/kafka_controller.go @@ -677,6 +677,7 @@ func (r *KafkaReconciler) newWatchStatusJob(kafka *v1beta1.Kafka) scheduler.Job "namespaced name", namespacedName) r.Scheduler.RemoveJob(kafka.GetJobID(scheduler.StatusChecker)) r.Scheduler.RemoveJob(kafka.GetJobID(scheduler.UserCreator)) + r.Scheduler.RemoveJob(kafka.GetJobID(scheduler.BackupsChecker)) return nil } if err != nil { @@ -688,7 +689,7 @@ func (r *KafkaReconciler) newWatchStatusJob(kafka *v1beta1.Kafka) scheduler.Job iData, err := r.API.GetKafka(kafka.Status.ID) if err != nil { if errors.Is(err, instaclustr.NotFound) { - return r.handleDeleteFromInstaclustrUI(kafka, l) + return r.handleExternalDelete(context.Background(), kafka) } l.Error(err, "Cannot get cluster from the Instaclustr", "cluster ID", kafka.Status.ID) @@ -868,47 +869,22 @@ func (r *KafkaReconciler) newUsersCreationJob(kafka *v1beta1.Kafka) scheduler.Jo } } -func (r *KafkaReconciler) handleDeleteFromInstaclustrUI(kafka *v1beta1.Kafka, l logr.Logger) error { - activeClusters, err := r.API.ListClusters() - if err != nil { - l.Error(err, "Cannot list account active clusters") - return err - } - - if isClusterActive(kafka.Status.ID, activeClusters) { - l.Info("Kafka is not found in the Instaclustr but still exist in the Instaclustr list of active cluster", - "cluster ID", kafka.Status.ID, - "cluster name", kafka.Spec.Name, - "resource name", kafka.Name) - - return nil - } - - l.Info("Cluster is not found in Instaclustr. Deleting resource.", - "cluster ID", kafka.Status.ClusterStatus.ID, - "cluster name", kafka.Spec.Name) +func (r *KafkaReconciler) handleExternalDelete(ctx context.Context, kafka *v1beta1.Kafka) error { + l := log.FromContext(ctx) patch := kafka.NewPatch() - - kafka.Annotations[models.ClusterDeletionAnnotation] = "" - kafka.Annotations[models.ResourceStateAnnotation] = models.DeletingEvent - err = r.Patch(context.TODO(), kafka, patch) + kafka.Status.State = models.DeletedStatus + err := r.Status().Patch(ctx, kafka, patch) if err != nil { - l.Error(err, "Cannot patch Kafka cluster resource", - "cluster ID", kafka.Status.ID, - "cluster name", kafka.Spec.Name, - "resource name", kafka.Name) return err } - err = r.Delete(context.TODO(), kafka) - if err != nil { - l.Error(err, "Cannot delete Kafka cluster resource", - "cluster ID", kafka.Status.ID, - "cluster name", kafka.Spec.Name, - "resource name", kafka.Name) - return err - } + l.Info(instaclustr.MsgInstaclustrResourceNotFound) + r.EventRecorder.Eventf(kafka, models.Warning, models.ExternalDeleted, instaclustr.MsgInstaclustrResourceNotFound) + + r.Scheduler.RemoveJob(kafka.GetJobID(scheduler.BackupsChecker)) + r.Scheduler.RemoveJob(kafka.GetJobID(scheduler.UserCreator)) + r.Scheduler.RemoveJob(kafka.GetJobID(scheduler.StatusChecker)) return nil } diff --git a/controllers/clusters/kafkaconnect_controller.go b/controllers/clusters/kafkaconnect_controller.go index c8df36ee2..b62d79a31 100644 --- a/controllers/clusters/kafkaconnect_controller.go +++ b/controllers/clusters/kafkaconnect_controller.go @@ -468,45 +468,7 @@ func (r *KafkaConnectReconciler) newWatchStatusJob(kc *v1beta1.KafkaConnect) sch iData, err := r.API.GetKafkaConnect(kc.Status.ID) if err != nil { if errors.Is(err, instaclustr.NotFound) { - activeClusters, err := r.API.ListClusters() - if err != nil { - l.Error(err, "Cannot list account active clusters") - return err - } - - if !isClusterActive(kc.Status.ID, activeClusters) { - l.Info("Cluster is not found in Instaclustr. Deleting resource.", - "cluster ID", kc.Status.ClusterStatus.ID, - "cluster name", kc.Spec.Name, - ) - - patch := kc.NewPatch() - kc.Annotations[models.ClusterDeletionAnnotation] = "" - kc.Annotations[models.ResourceStateAnnotation] = models.DeletingEvent - err = r.Patch(context.TODO(), kc, patch) - if err != nil { - l.Error(err, "Cannot patch KafkaConnect cluster resource", - "cluster ID", kc.Status.ID, - "cluster name", kc.Spec.Name, - "resource name", kc.Name, - ) - - return err - } - - err = r.Delete(context.TODO(), kc) - if err != nil { - l.Error(err, "Cannot delete KafkaConnect cluster resource", - "cluster ID", kc.Status.ID, - "cluster name", kc.Spec.Name, - "resource name", kc.Name, - ) - - return err - } - - return nil - } + return r.handleExternalDelete(context.Background(), kc) } l.Error(err, "Cannot get Kafka Connect from Instaclustr", @@ -657,3 +619,23 @@ func (r *KafkaConnectReconciler) reconcileMaintenanceEvents(ctx context.Context, return nil } + +func (r *KafkaConnectReconciler) handleExternalDelete(ctx context.Context, kc *v1beta1.KafkaConnect) error { + l := log.FromContext(ctx) + + patch := kc.NewPatch() + kc.Status.State = models.DeletedStatus + err := r.Status().Patch(ctx, kc, patch) + if err != nil { + return err + } + + l.Info(instaclustr.MsgInstaclustrResourceNotFound) + r.EventRecorder.Eventf(kc, models.Warning, models.ExternalDeleted, instaclustr.MsgInstaclustrResourceNotFound) + + r.Scheduler.RemoveJob(kc.GetJobID(scheduler.BackupsChecker)) + r.Scheduler.RemoveJob(kc.GetJobID(scheduler.UserCreator)) + r.Scheduler.RemoveJob(kc.GetJobID(scheduler.StatusChecker)) + + return nil +} diff --git a/controllers/clusters/opensearch_controller.go b/controllers/clusters/opensearch_controller.go index 75ae84c1a..ddd7f032e 100644 --- a/controllers/clusters/opensearch_controller.go +++ b/controllers/clusters/opensearch_controller.go @@ -597,45 +597,7 @@ func (r *OpenSearchReconciler) newWatchStatusJob(o *v1beta1.OpenSearch) schedule iData, err := r.API.GetOpenSearch(o.Status.ID) if err != nil { if errors.Is(err, instaclustr.NotFound) { - activeClusters, err := r.API.ListClusters() - if err != nil { - l.Error(err, "Cannot list account active clusters") - return err - } - - if !isClusterActive(o.Status.ID, activeClusters) { - l.Info("Cluster is not found in Instaclustr. Deleting resource.", - "cluster ID", o.Status.ClusterStatus.ID, - "cluster name", o.Spec.Name, - ) - - patch := o.NewPatch() - o.Annotations[models.ClusterDeletionAnnotation] = "" - o.Annotations[models.ResourceStateAnnotation] = models.DeletingEvent - err = r.Patch(context.TODO(), o, patch) - if err != nil { - l.Error(err, "Cannot patch OpenSearch cluster resource", - "cluster ID", o.Status.ID, - "cluster name", o.Spec.Name, - "resource name", o.Name, - ) - - return err - } - - err = r.Delete(context.TODO(), o) - if err != nil { - l.Error(err, "Cannot delete OpenSearch cluster resource", - "cluster ID", o.Status.ID, - "cluster name", o.Spec.Name, - "resource name", o.Name, - ) - - return err - } - - return nil - } + return r.handleExternalDelete(context.Background(), o) } l.Error(err, "Cannot get OpenSearch cluster from the Instaclustr API", @@ -1248,3 +1210,23 @@ func (r *OpenSearchReconciler) reconcileMaintenanceEvents(ctx context.Context, o return nil } + +func (r *OpenSearchReconciler) handleExternalDelete(ctx context.Context, o *v1beta1.OpenSearch) error { + l := log.FromContext(ctx) + + patch := o.NewPatch() + o.Status.State = models.DeletedStatus + err := r.Status().Patch(ctx, o, patch) + if err != nil { + return err + } + + l.Info(instaclustr.MsgInstaclustrResourceNotFound) + r.EventRecorder.Eventf(o, models.Warning, models.ExternalDeleted, instaclustr.MsgInstaclustrResourceNotFound) + + r.Scheduler.RemoveJob(o.GetJobID(scheduler.BackupsChecker)) + r.Scheduler.RemoveJob(o.GetJobID(scheduler.UserCreator)) + r.Scheduler.RemoveJob(o.GetJobID(scheduler.StatusChecker)) + + return nil +} diff --git a/controllers/clusters/postgresql_controller.go b/controllers/clusters/postgresql_controller.go index 406f69f2d..49571956a 100644 --- a/controllers/clusters/postgresql_controller.go +++ b/controllers/clusters/postgresql_controller.go @@ -964,45 +964,7 @@ func (r *PostgreSQLReconciler) newWatchStatusJob(pg *v1beta1.PostgreSQL) schedul instPGData, err := r.API.GetPostgreSQL(pg.Status.ID) if err != nil { if errors.Is(err, instaclustr.NotFound) { - activeClusters, err := r.API.ListClusters() - if err != nil { - l.Error(err, "Cannot list account active clusters") - return err - } - - if !isClusterActive(pg.Status.ID, activeClusters) { - l.Info("Cluster is not found in Instaclustr. Deleting resource.", - "cluster ID", pg.Status.ClusterStatus.ID, - "cluster name", pg.Spec.Name, - ) - - patch := pg.NewPatch() - pg.Annotations[models.ClusterDeletionAnnotation] = "" - pg.Annotations[models.ResourceStateAnnotation] = models.DeletingEvent - err = r.Patch(context.TODO(), pg, patch) - if err != nil { - l.Error(err, "Cannot patch PostgreSQL cluster resource", - "cluster ID", pg.Status.ID, - "cluster name", pg.Spec.Name, - "resource name", pg.Name, - ) - - return err - } - - err = r.Delete(context.TODO(), pg) - if err != nil { - l.Error(err, "Cannot delete PostgreSQL cluster resource", - "cluster ID", pg.Status.ID, - "cluster name", pg.Spec.Name, - "resource name", pg.Name, - ) - - return err - } - - return nil - } + return r.handleExternalDelete(context.Background(), pg) } l.Error(err, "Cannot get PostgreSQL cluster status", @@ -1637,3 +1599,23 @@ func (r *PostgreSQLReconciler) reconcileMaintenanceEvents(ctx context.Context, p return nil } + +func (r *PostgreSQLReconciler) handleExternalDelete(ctx context.Context, pg *v1beta1.PostgreSQL) error { + l := log.FromContext(ctx) + + patch := pg.NewPatch() + pg.Status.State = models.DeletedStatus + err := r.Status().Patch(ctx, pg, patch) + if err != nil { + return err + } + + l.Info(instaclustr.MsgInstaclustrResourceNotFound) + r.EventRecorder.Eventf(pg, models.Warning, models.ExternalDeleted, instaclustr.MsgInstaclustrResourceNotFound) + + r.Scheduler.RemoveJob(pg.GetJobID(scheduler.BackupsChecker)) + r.Scheduler.RemoveJob(pg.GetJobID(scheduler.UserCreator)) + r.Scheduler.RemoveJob(pg.GetJobID(scheduler.StatusChecker)) + + return nil +} diff --git a/controllers/clusters/redis_controller.go b/controllers/clusters/redis_controller.go index b8101bd3b..696c359d8 100644 --- a/controllers/clusters/redis_controller.go +++ b/controllers/clusters/redis_controller.go @@ -896,45 +896,7 @@ func (r *RedisReconciler) newWatchStatusJob(redis *v1beta1.Redis) scheduler.Job iData, err := r.API.GetRedis(redis.Status.ID) if err != nil { if errors.Is(err, instaclustr.NotFound) { - activeClusters, err := r.API.ListClusters() - if err != nil { - l.Error(err, "Cannot list account active clusters") - return err - } - - if !isClusterActive(redis.Status.ID, activeClusters) { - l.Info("Cluster is not found in Instaclustr. Deleting resource.", - "cluster ID", redis.Status.ClusterStatus.ID, - "cluster name", redis.Spec.Name, - ) - - patch := redis.NewPatch() - redis.Annotations[models.ClusterDeletionAnnotation] = "" - redis.Annotations[models.ResourceStateAnnotation] = models.DeletingEvent - err = r.Patch(context.TODO(), redis, patch) - if err != nil { - l.Error(err, "Cannot patch Redis cluster resource", - "cluster ID", redis.Status.ID, - "cluster name", redis.Spec.Name, - "resource name", redis.Name, - ) - - return err - } - - err = r.Delete(context.TODO(), redis) - if err != nil { - l.Error(err, "Cannot delete Redis cluster resource", - "cluster ID", redis.Status.ID, - "cluster name", redis.Spec.Name, - "resource name", redis.Name, - ) - - return err - } - - return nil - } + return r.handleExternalDelete(context.Background(), redis) } l.Error(err, "Cannot get Redis cluster status from Instaclustr", @@ -1284,3 +1246,23 @@ func (r *RedisReconciler) reconcileMaintenanceEvents(ctx context.Context, redis return nil } + +func (r *RedisReconciler) handleExternalDelete(ctx context.Context, redis *v1beta1.Redis) error { + l := log.FromContext(ctx) + + patch := redis.NewPatch() + redis.Status.State = models.DeletedStatus + err := r.Status().Patch(ctx, redis, patch) + if err != nil { + return err + } + + l.Info(instaclustr.MsgInstaclustrResourceNotFound) + r.EventRecorder.Eventf(redis, models.Warning, models.ExternalDeleted, instaclustr.MsgInstaclustrResourceNotFound) + + r.Scheduler.RemoveJob(redis.GetJobID(scheduler.BackupsChecker)) + r.Scheduler.RemoveJob(redis.GetJobID(scheduler.UserCreator)) + r.Scheduler.RemoveJob(redis.GetJobID(scheduler.StatusChecker)) + + return nil +} diff --git a/controllers/clusters/zookeeper_controller.go b/controllers/clusters/zookeeper_controller.go index b832054ca..a5e84237c 100644 --- a/controllers/clusters/zookeeper_controller.go +++ b/controllers/clusters/zookeeper_controller.go @@ -422,7 +422,7 @@ func (r *ZookeeperReconciler) newWatchStatusJob(zook *v1beta1.Zookeeper) schedul iData, err := r.API.GetZookeeper(zook.Status.ID) if err != nil { if errors.Is(err, instaclustr.NotFound) { - return r.handleDeleteFromInstaclustrUI(zook, l) + return r.handleExternalDelete(context.Background(), zook) } l.Error(err, "Cannot get Zookeeper cluster status from Instaclustr", @@ -507,50 +507,22 @@ func (r *ZookeeperReconciler) newWatchStatusJob(zook *v1beta1.Zookeeper) schedul } } -func (r *ZookeeperReconciler) handleDeleteFromInstaclustrUI(zook *v1beta1.Zookeeper, l logr.Logger) error { - activeClusters, err := r.API.ListClusters() - if err != nil { - l.Error(err, "Cannot list account active clusters") - return err - } - - if isClusterActive(zook.Status.ID, activeClusters) { - l.Info("Zookeeper is not found in the Instaclustr but still exist in the Instaclustr list of active cluster", - "cluster ID", zook.Status.ID, - "cluster name", zook.Spec.Name, - "resource name", zook.Name) - - return nil - } - - l.Info("Cluster is not found in Instaclustr. Deleting resource.", - "cluster ID", zook.Status.ID, - "cluster name", zook.Spec.Name) +func (r *ZookeeperReconciler) handleExternalDelete(ctx context.Context, zook *v1beta1.Zookeeper) error { + l := log.FromContext(ctx) patch := zook.NewPatch() - zook.Annotations[models.ClusterDeletionAnnotation] = "" - zook.Annotations[models.ResourceStateAnnotation] = models.DeletingEvent - err = r.Patch(context.TODO(), zook, patch) + zook.Status.State = models.DeletedStatus + err := r.Status().Patch(ctx, zook, patch) if err != nil { - l.Error(err, "Cannot patch Zookeeper cluster resource", - "cluster ID", zook.Status.ID, - "cluster name", zook.Spec.Name, - "resource name", zook.Name, - ) - return err } - err = r.Delete(context.TODO(), zook) - if err != nil { - l.Error(err, "Cannot delete Zookeeper cluster resource", - "cluster ID", zook.Status.ID, - "cluster name", zook.Spec.Name, - "resource name", zook.Name, - ) + l.Info(instaclustr.MsgInstaclustrResourceNotFound) + r.EventRecorder.Eventf(zook, models.Warning, models.ExternalDeleted, instaclustr.MsgInstaclustrResourceNotFound) - return err - } + r.Scheduler.RemoveJob(zook.GetJobID(scheduler.BackupsChecker)) + r.Scheduler.RemoveJob(zook.GetJobID(scheduler.UserCreator)) + r.Scheduler.RemoveJob(zook.GetJobID(scheduler.StatusChecker)) return nil } diff --git a/pkg/instaclustr/errors.go b/pkg/instaclustr/errors.go index bcb895eda..96d9ffebe 100644 --- a/pkg/instaclustr/errors.go +++ b/pkg/instaclustr/errors.go @@ -25,3 +25,4 @@ var ( ) const MsgDeleteUser = "If you want to delete the user, remove it from the clusters specifications first" +const MsgInstaclustrResourceNotFound = "The resource is not found on Instaclustr, changing its state to deleted" diff --git a/pkg/models/apiv1.go b/pkg/models/apiv1.go index 0e94b3a7a..e5c8fef03 100644 --- a/pkg/models/apiv1.go +++ b/pkg/models/apiv1.go @@ -18,7 +18,6 @@ package models const ( RunningStatus = "RUNNING" - Disabled = "DISABLED" ) type ClusterProviderV1 struct { diff --git a/pkg/models/apiv2.go b/pkg/models/apiv2.go index 548e9b1a6..a2e11dfa1 100644 --- a/pkg/models/apiv2.go +++ b/pkg/models/apiv2.go @@ -20,6 +20,8 @@ const ( NoOperation = "NO_OPERATION" OperationInProgress = "OPERATION_IN_PROGRESS" + DeletedStatus = "DELETED" + DefaultAccountName = "INSTACLUSTR" AWSVPC = "AWS_VPC" diff --git a/pkg/models/operator.go b/pkg/models/operator.go index 6051c62c6..f30df8360 100644 --- a/pkg/models/operator.go +++ b/pkg/models/operator.go @@ -139,6 +139,7 @@ const ( DeletionStarted = "DeletionStarted" DeletionFailed = "DeletionFailed" Deleted = "Deleted" + ExternalDeleted = "ExternalDeleted" ) const (