From a3db1ab0713c76b839e49a49f6a1567c8d98de79 Mon Sep 17 00:00:00 2001 From: Bychkov Date: Wed, 11 Oct 2023 12:09:48 +0300 Subject: [PATCH] add the cluster settings update for the rest of the clusters --- apis/clusters/v1beta1/cadence_types.go | 4 +- apis/clusters/v1beta1/kafka_types.go | 2 + apis/clusters/v1beta1/kafkaconnect_types.go | 2 + apis/clusters/v1beta1/opensearch_types.go | 2 + apis/clusters/v1beta1/postgresql_types.go | 3 +- apis/clusters/v1beta1/structs.go | 13 +++--- apis/clusters/v1beta1/zookeeper_types.go | 2 + controllers/clusters/cadence_controller.go | 36 +++++---------- controllers/clusters/cassandra_controller.go | 46 +++++++------------ controllers/clusters/kafka_controller.go | 16 +++++++ .../clusters/kafkaconnect_controller.go | 16 +++++++ controllers/clusters/opensearch_controller.go | 16 +++++++ controllers/clusters/postgresql_controller.go | 46 +++++++------------ controllers/clusters/redis_controller.go | 17 +------ controllers/clusters/zookeeper_controller.go | 30 +++++++++++- pkg/models/cadence_apiv2.go | 1 + pkg/models/cassandra_apiv2.go | 2 +- pkg/models/kafka_apiv2.go | 1 + pkg/models/kafka_connect_apiv2.go | 1 + pkg/models/opensearch_apiv2.go | 1 + pkg/models/postgresql_apiv2.go | 1 + pkg/models/redis_apiv2.go | 2 +- pkg/models/zookeeper_apiv2.go | 1 + 23 files changed, 150 insertions(+), 111 deletions(-) diff --git a/apis/clusters/v1beta1/cadence_types.go b/apis/clusters/v1beta1/cadence_types.go index 82547e511..f3b394f27 100644 --- a/apis/clusters/v1beta1/cadence_types.go +++ b/apis/clusters/v1beta1/cadence_types.go @@ -66,7 +66,6 @@ type CadenceSpec struct { //+kubebuilder:validation:MinItems:=1 //+kubebuilder:validation:MaxItems:=1 DataCentres []*CadenceDataCentre `json:"dataCentres"` - Description string `json:"description,omitempty"` UseCadenceWebAuth bool `json:"useCadenceWebAuth"` AWSArchival []*AWSArchival `json:"awsArchival,omitempty"` StandardProvisioning []*StandardProvisioning `json:"standardProvisioning,omitempty"` @@ -192,6 +191,7 @@ func (cs *CadenceSpec) ToInstAPI(ctx context.Context, k8sClient client.Client) ( PrivateNetworkCluster: cs.PrivateNetworkCluster, SLATier: cs.SLATier, AWSArchival: awsArchival, + Description: cs.Description, SharedProvisioning: sharedProvisioning, StandardProvisioning: standardProvisioning, TargetPrimaryCadence: cs.TargetCadenceToInstAPI(), @@ -359,6 +359,8 @@ func (c *Cadence) FromInstAPI(iData []byte) (*Cadence, error) { func (cs *CadenceSpec) FromInstAPI(iCad *models.CadenceCluster) (spec CadenceSpec) { spec.DataCentres = cs.DCsFromInstAPI(iCad.DataCentres) spec.ResizeSettings = resizeSettingsFromInstAPI(iCad.ResizeSettings) + spec.TwoFactorDelete = cs.Cluster.TwoFactorDeleteFromInstAPI(iCad.TwoFactorDelete) + spec.Description = iCad.Description return } diff --git a/apis/clusters/v1beta1/kafka_types.go b/apis/clusters/v1beta1/kafka_types.go index dab2d1e2d..2c6900c26 100644 --- a/apis/clusters/v1beta1/kafka_types.go +++ b/apis/clusters/v1beta1/kafka_types.go @@ -159,6 +159,7 @@ func (k *KafkaSpec) ToInstAPI() *models.KafkaCluster { DedicatedZookeeper: k.dedicatedZookeeperToInstAPI(), PrivateNetworkCluster: k.PrivateNetworkCluster, Name: k.Name, + Description: k.Description, SLATier: k.SLATier, KafkaVersion: k.Version, DataCentres: k.dcToInstAPI(), @@ -298,6 +299,7 @@ func (ks *KafkaSpec) FromInstAPI(iKafka *models.KafkaCluster) KafkaSpec { PCICompliance: iKafka.PCIComplianceMode, PrivateNetworkCluster: iKafka.PrivateNetworkCluster, SLATier: iKafka.SLATier, + Description: iKafka.Description, TwoFactorDelete: ks.Cluster.TwoFactorDeleteFromInstAPI(iKafka.TwoFactorDelete), }, SchemaRegistry: ks.SchemaRegistryFromInstAPI(iKafka.SchemaRegistry), diff --git a/apis/clusters/v1beta1/kafkaconnect_types.go b/apis/clusters/v1beta1/kafkaconnect_types.go index ad7bd097c..a101ee454 100644 --- a/apis/clusters/v1beta1/kafkaconnect_types.go +++ b/apis/clusters/v1beta1/kafkaconnect_types.go @@ -314,6 +314,7 @@ func (ks *KafkaConnectSpec) FromInstAPI(iKC *models.KafkaConnectCluster) KafkaCo Cluster: Cluster{ Name: iKC.Name, Version: iKC.KafkaConnectVersion, + Description: iKC.Description, PrivateNetworkCluster: iKC.PrivateNetworkCluster, SLATier: iKC.SLATier, TwoFactorDelete: ks.Cluster.TwoFactorDeleteFromInstAPI(iKC.TwoFactorDelete), @@ -584,6 +585,7 @@ func (ks *KafkaConnectSpec) ToInstAPI() models.KafkaConnectCluster { Name: ks.Name, KafkaConnectVersion: ks.Version, PrivateNetworkCluster: ks.PrivateNetworkCluster, + Description: ks.Description, SLATier: ks.SLATier, TwoFactorDelete: ks.TwoFactorDeletesToInstAPI(), CustomConnectors: ks.CustomConnectorsToInstAPI(), diff --git a/apis/clusters/v1beta1/opensearch_types.go b/apis/clusters/v1beta1/opensearch_types.go index 84b9accad..8856b2d98 100644 --- a/apis/clusters/v1beta1/opensearch_types.go +++ b/apis/clusters/v1beta1/opensearch_types.go @@ -100,6 +100,7 @@ func (oss *OpenSearchSpec) ToInstAPI() *models.OpenSearchCluster { OpenSearchDashboards: oss.dashboardsToInstAPI(), ReportingPlugin: oss.ReportingPlugin, SQLPlugin: oss.SQLPlugin, + Description: oss.Description, NotificationsPlugin: oss.NotificationsPlugin, DataCentres: oss.dcsToInstAPI(), AnomalyDetectionPlugin: oss.AnomalyDetectionPlugin, @@ -231,6 +232,7 @@ func (oss *OpenSearchSpec) FromInstAPI(iOpenSearch *models.OpenSearchCluster) Op Name: iOpenSearch.Name, Version: iOpenSearch.OpenSearchVersion, PCICompliance: iOpenSearch.PCIComplianceMode, + Description: iOpenSearch.Description, PrivateNetworkCluster: iOpenSearch.PrivateNetworkCluster, SLATier: iOpenSearch.SLATier, TwoFactorDelete: oss.Cluster.TwoFactorDeleteFromInstAPI(iOpenSearch.TwoFactorDelete), diff --git a/apis/clusters/v1beta1/postgresql_types.go b/apis/clusters/v1beta1/postgresql_types.go index a4b062809..91924f5d7 100644 --- a/apis/clusters/v1beta1/postgresql_types.go +++ b/apis/clusters/v1beta1/postgresql_types.go @@ -77,7 +77,6 @@ type PgSpec struct { Cluster `json:",inline"` DataCentres []*PgDataCentre `json:"dataCentres,omitempty"` ClusterConfigurations map[string]string `json:"clusterConfigurations,omitempty"` - Description string `json:"description,omitempty"` SynchronousModeStrict bool `json:"synchronousModeStrict,omitempty"` UserRefs []*UserReference `json:"userRefs,omitempty"` //+kubebuilder:validate:MaxItems:=1 @@ -196,6 +195,7 @@ func (pgs *PgSpec) ToInstAPI() *models.PGCluster { PostgreSQLVersion: pgs.Version, DataCentres: pgs.DCsToInstAPI(), SynchronousModeStrict: pgs.SynchronousModeStrict, + Description: pgs.Description, PrivateNetworkCluster: pgs.PrivateNetworkCluster, SLATier: pgs.SLATier, TwoFactorDelete: pgs.TwoFactorDeletesToInstAPI(), @@ -555,6 +555,7 @@ func (pgs *PgSpec) FromInstAPI(iPg *models.PGCluster) PgSpec { Version: iPg.PostgreSQLVersion, PCICompliance: iPg.PCIComplianceMode, PrivateNetworkCluster: iPg.PrivateNetworkCluster, + Description: iPg.Description, SLATier: iPg.SLATier, TwoFactorDelete: pgs.Cluster.TwoFactorDeleteFromInstAPI(iPg.TwoFactorDelete), }, diff --git a/apis/clusters/v1beta1/structs.go b/apis/clusters/v1beta1/structs.go index bffb39329..1ee503af5 100644 --- a/apis/clusters/v1beta1/structs.go +++ b/apis/clusters/v1beta1/structs.go @@ -319,11 +319,7 @@ func (c *Cluster) TwoFactorDeletesToInstAPI() (TFDs []*models.TwoFactorDelete) { return } -func (c *Cluster) ClusterSettingsUpdateToInstAPI() (*models.ClusterSettings, error) { - if len(c.TwoFactorDelete) > 1 { - return nil, models.ErrOnlyOneEntityTwoFactorDelete - } - +func (c *Cluster) ClusterSettingsUpdateToInstAPI() *models.ClusterSettings { settingsToAPI := &models.ClusterSettings{} if c.TwoFactorDelete != nil { iTFD := &models.TwoFactorDelete{} @@ -334,7 +330,7 @@ func (c *Cluster) ClusterSettingsUpdateToInstAPI() (*models.ClusterSettings, err } settingsToAPI.Description = c.Description - return settingsToAPI, nil + return settingsToAPI } func (c *Cluster) TwoFactorDeleteToInstAPIv1() *models.TwoFactorDeleteV1 { @@ -599,6 +595,11 @@ func (c *Cluster) TagsFromInstAPI(iTags []*models.Tag) map[string]string { return newTags } +func (c *Cluster) ClusterSettingsNeedUpdate(iCluster Cluster) bool { + return len(c.TwoFactorDelete) != 0 && len(iCluster.TwoFactorDelete) == 0 || + c.Description != iCluster.Description +} + func (c *Cluster) CloudProviderSettingsFromInstAPI(iDC models.DataCentre) (settings []*CloudProviderSettings) { if isCloudProviderSettingsEmpty(iDC) { return nil diff --git a/apis/clusters/v1beta1/zookeeper_types.go b/apis/clusters/v1beta1/zookeeper_types.go index 1cf35010e..11576f109 100644 --- a/apis/clusters/v1beta1/zookeeper_types.go +++ b/apis/clusters/v1beta1/zookeeper_types.go @@ -107,6 +107,7 @@ func (zs *ZookeeperSpec) FromInstAPI(iZook *models.ZookeeperCluster) ZookeeperSp Cluster: Cluster{ Name: iZook.Name, Version: iZook.ZookeeperVersion, + Description: zs.Description, PrivateNetworkCluster: iZook.PrivateNetworkCluster, SLATier: iZook.SLATier, TwoFactorDelete: zs.Cluster.TwoFactorDeleteFromInstAPI(iZook.TwoFactorDelete), @@ -154,6 +155,7 @@ func (zs *ZookeeperSpec) ToInstAPI() *models.ZookeeperCluster { SLATier: zs.SLATier, TwoFactorDelete: zs.Cluster.TwoFactorDeletesToInstAPI(), DataCentres: zs.DCsToInstAPI(), + Description: zs.Description, } } diff --git a/controllers/clusters/cadence_controller.go b/controllers/clusters/cadence_controller.go index 5945367ec..35026415c 100644 --- a/controllers/clusters/cadence_controller.go +++ b/controllers/clusters/cadence_controller.go @@ -304,18 +304,20 @@ func (r *CadenceReconciler) HandleUpdateCluster( return r.handleExternalChanges(cadence, iCadence, logger) } - err = r.updateDescriptionAndTwoFactorDelete(cadence) - if err != nil { - logger.Error(err, "Cannot update Cadence cluster description and TwoFactorDelete", - "cluster ID", cadence.Status.ID, - "description", cadence.Spec.Description, - "two factor delete", cadence.Spec.TwoFactorDelete, - ) + if cadence.Spec.ClusterSettingsNeedUpdate(iCadence.Spec.Cluster) { + logger.Info("Updating cluster settings", + "instaclustr description", iCadence.Spec.Description, + "instaclustr two factor delete", iCadence.Spec.TwoFactorDelete) - r.EventRecorder.Eventf(cadence, models.Warning, models.UpdateFailed, - "Cluster description and TwoFactoDelete update is failed. Reason: %v", err) + err = r.API.UpdateClusterSettings(cadence.Status.ID, cadence.Spec.ClusterSettingsUpdateToInstAPI()) + if err != nil { + logger.Error(err, "Cannot update cluster settings", + "cluster ID", cadence.Status.ID, "cluster spec", cadence.Spec) + r.EventRecorder.Eventf(cadence, models.Warning, models.UpdateFailed, + "Cannot update cluster settings. Reason: %v", err) - return models.ReconcileRequeue + return models.ReconcileRequeue + } } logger.Info("Update request to Instaclustr API has been sent", @@ -1146,20 +1148,6 @@ func (r *CadenceReconciler) deletePackagedResources( return nil } -func (r *CadenceReconciler) updateDescriptionAndTwoFactorDelete(cadence *v1beta1.Cadence) error { - var twoFactorDelete *v1beta1.TwoFactorDelete - if len(cadence.Spec.TwoFactorDelete) != 0 { - twoFactorDelete = cadence.Spec.TwoFactorDelete[0] - } - - err := r.API.UpdateDescriptionAndTwoFactorDelete(instaclustr.ClustersEndpointV1, cadence.Status.ID, cadence.Spec.Description, twoFactorDelete) - if err != nil { - return err - } - - return nil -} - func areSecondaryCadenceTargetsEqual(k8sTargets, iTargets []*v1beta1.TargetCadence) bool { for _, iTarget := range iTargets { for _, k8sTarget := range k8sTargets { diff --git a/controllers/clusters/cassandra_controller.go b/controllers/clusters/cassandra_controller.go index 02de8700c..04db4671b 100644 --- a/controllers/clusters/cassandra_controller.go +++ b/controllers/clusters/cassandra_controller.go @@ -229,13 +229,13 @@ func (r *CassandraReconciler) handleCreateCluster( l.Error(err, "Cannot start cluster status job", "cassandra cluster ID", cassandra.Status.ID) - r.EventRecorder.Eventf( - cassandra, models.Warning, models.CreationFailed, - "Cluster status check job is failed. Reason: %v", - err, - ) - return reconcile.Result{}, err - } + r.EventRecorder.Eventf( + cassandra, models.Warning, models.CreationFailed, + "Cluster status check job is failed. Reason: %v", + err, + ) + return reconcile.Result{}, err + } r.EventRecorder.Eventf( cassandra, models.Normal, models.Created, @@ -248,13 +248,13 @@ func (r *CassandraReconciler) handleCreateCluster( "cluster ID", cassandra.Status.ID, ) - r.EventRecorder.Eventf( - cassandra, models.Warning, models.CreationFailed, - "Cluster backups check job is failed. Reason: %v", - err, - ) - return reconcile.Result{}, err - } + r.EventRecorder.Eventf( + cassandra, models.Warning, models.CreationFailed, + "Cluster backups check job is failed. Reason: %v", + err, + ) + return reconcile.Result{}, err + } r.EventRecorder.Eventf( cassandra, models.Normal, models.Created, @@ -322,29 +322,15 @@ func (r *CassandraReconciler) handleUpdateCluster( patch := cassandra.NewPatch() - if len(cassandra.Spec.TwoFactorDelete) != 0 && len(iCassandra.Spec.TwoFactorDelete) == 0 || - cassandra.Spec.Description != iCassandra.Spec.Description { + if cassandra.Spec.ClusterSettingsNeedUpdate(iCassandra.Spec.Cluster) { l.Info("Updating cluster settings", "instaclustr description", iCassandra.Spec.Description, "instaclustr two factor delete", iCassandra.Spec.TwoFactorDelete) - settingsToInstAPI, err := cassandra.Spec.ClusterSettingsUpdateToInstAPI() - if err != nil { - l.Error(err, "Cannot convert cluster settings to Instaclustr API", - "cluster ID", cassandra.Status.ID, - "cluster spec", cassandra.Spec) - - r.EventRecorder.Eventf(cassandra, models.Warning, models.UpdateFailed, - "Cannot update cluster settings. Reason: %v", err) - - return reconcile.Result{}, err - } - - err = r.API.UpdateClusterSettings(cassandra.Status.ID, settingsToInstAPI) + err = r.API.UpdateClusterSettings(cassandra.Status.ID, cassandra.Spec.ClusterSettingsUpdateToInstAPI()) if err != nil { l.Error(err, "Cannot update cluster settings", "cluster ID", cassandra.Status.ID, "cluster spec", cassandra.Spec) - r.EventRecorder.Eventf(cassandra, models.Warning, models.UpdateFailed, "Cannot update cluster settings. Reason: %v", err) diff --git a/controllers/clusters/kafka_controller.go b/controllers/clusters/kafka_controller.go index e1eca1ce2..f257df0ae 100644 --- a/controllers/clusters/kafka_controller.go +++ b/controllers/clusters/kafka_controller.go @@ -239,6 +239,22 @@ func (r *KafkaReconciler) handleUpdateCluster( return r.handleExternalChanges(k, iKafka, l) } + if k.Spec.ClusterSettingsNeedUpdate(iKafka.Spec.Cluster) { + l.Info("Updating cluster settings", + "instaclustr description", iKafka.Spec.Description, + "instaclustr two factor delete", iKafka.Spec.TwoFactorDelete) + + err = r.API.UpdateClusterSettings(k.Status.ID, k.Spec.ClusterSettingsUpdateToInstAPI()) + if err != nil { + l.Error(err, "Cannot update cluster settings", + "cluster ID", k.Status.ID, "cluster spec", k.Spec) + r.EventRecorder.Eventf(k, models.Warning, models.UpdateFailed, + "Cannot update cluster settings. Reason: %v", err) + + return models.ReconcileRequeue + } + } + if k.Spec.IsEqual(iKafka.Spec) { return models.ExitReconcile } diff --git a/controllers/clusters/kafkaconnect_controller.go b/controllers/clusters/kafkaconnect_controller.go index 3d29f2fcd..a70a441bd 100644 --- a/controllers/clusters/kafkaconnect_controller.go +++ b/controllers/clusters/kafkaconnect_controller.go @@ -211,6 +211,22 @@ func (r *KafkaConnectReconciler) handleUpdateCluster(ctx context.Context, kc *v1 return r.handleExternalChanges(kc, iKC, l) } + if kc.Spec.ClusterSettingsNeedUpdate(iKC.Spec.Cluster) { + l.Info("Updating cluster settings", + "instaclustr description", iKC.Spec.Description, + "instaclustr two factor delete", iKC.Spec.TwoFactorDelete) + + err = r.API.UpdateClusterSettings(kc.Status.ID, kc.Spec.ClusterSettingsUpdateToInstAPI()) + if err != nil { + l.Error(err, "Cannot update cluster settings", + "cluster ID", kc.Status.ID, "cluster spec", kc.Spec) + r.EventRecorder.Eventf(kc, models.Warning, models.UpdateFailed, + "Cannot update cluster settings. Reason: %v", err) + + return models.ReconcileRequeue + } + } + if !kc.Spec.IsEqual(iKC.Spec) { l.Info("Update request to Instaclustr API has been sent", "spec data centres", kc.Spec.DataCentres, diff --git a/controllers/clusters/opensearch_controller.go b/controllers/clusters/opensearch_controller.go index 6c9448f12..76c685380 100644 --- a/controllers/clusters/opensearch_controller.go +++ b/controllers/clusters/opensearch_controller.go @@ -309,6 +309,22 @@ func (r *OpenSearchReconciler) HandleUpdateCluster( return r.handleExternalChanges(o, iOpenSearch, logger) } + if o.Spec.ClusterSettingsNeedUpdate(iOpenSearch.Spec.Cluster) { + logger.Info("Updating cluster settings", + "instaclustr description", iOpenSearch.Spec.Description, + "instaclustr two factor delete", iOpenSearch.Spec.TwoFactorDelete) + + err = r.API.UpdateClusterSettings(o.Status.ID, o.Spec.ClusterSettingsUpdateToInstAPI()) + if err != nil { + logger.Error(err, "Cannot update cluster settings", + "cluster ID", o.Status.ID, "cluster spec", o.Spec) + r.EventRecorder.Eventf(o, models.Warning, models.UpdateFailed, + "Cannot update cluster settings. Reason: %v", err) + + return models.ReconcileRequeue + } + } + if !o.Spec.IsEqual(iOpenSearch.Spec) { logger.Info("Update request to Instaclustr API has been sent", "spec data centres", o.Spec.DataCentres, diff --git a/controllers/clusters/postgresql_controller.go b/controllers/clusters/postgresql_controller.go index fe443c5cb..d90296410 100644 --- a/controllers/clusters/postgresql_controller.go +++ b/controllers/clusters/postgresql_controller.go @@ -365,6 +365,22 @@ func (r *PostgreSQLReconciler) handleUpdateCluster( return r.handleExternalChanges(pg, iPg, logger) } + if pg.Spec.ClusterSettingsNeedUpdate(iPg.Spec.Cluster) { + logger.Info("Updating cluster settings", + "instaclustr description", iPg.Spec.Description, + "instaclustr two factor delete", iPg.Spec.TwoFactorDelete) + + err = r.API.UpdateClusterSettings(pg.Status.ID, pg.Spec.ClusterSettingsUpdateToInstAPI()) + if err != nil { + logger.Error(err, "Cannot update cluster settings", + "cluster ID", pg.Status.ID, "cluster spec", pg.Spec) + r.EventRecorder.Eventf(pg, models.Warning, models.UpdateFailed, + "Cannot update cluster settings. Reason: %v", err) + + return models.ReconcileRequeue + } + } + if !pg.Spec.AreDCsEqual(iPg.Spec.DataCentres) { logger.Info("Update request to Instaclustr API has been sent", "spec data centres", pg.Spec.DataCentres, @@ -451,22 +467,6 @@ func (r *PostgreSQLReconciler) handleUpdateCluster( ) } - err = r.updateDescriptionAndTwoFactorDelete(pg) - if err != nil { - logger.Error(err, "Cannot update description and twoFactorDelete", - "cluster name", pg.Spec.Name, - "two factor delete", pg.Spec.TwoFactorDelete, - "description", pg.Spec.Description, - ) - - r.EventRecorder.Eventf( - pg, models.Warning, models.UpdateFailed, - "Cluster description and TwoFactoDelete update is failed. Reason: %v", - err, - ) - return models.ReconcileRequeue - } - pg.Annotations[models.ResourceStateAnnotation] = models.UpdatedEvent pg.Annotations[models.UpdateQueuedAnnotation] = "" err = r.patchClusterMetadata(ctx, pg, logger) @@ -1610,20 +1610,6 @@ func (r *PostgreSQLReconciler) patchClusterMetadata( return nil } -func (r *PostgreSQLReconciler) updateDescriptionAndTwoFactorDelete(pgCluster *v1beta1.PostgreSQL) error { - var twoFactorDelete *v1beta1.TwoFactorDelete - if len(pgCluster.Spec.TwoFactorDelete) != 0 { - twoFactorDelete = pgCluster.Spec.TwoFactorDelete[0] - } - - err := r.API.UpdateDescriptionAndTwoFactorDelete(instaclustr.ClustersEndpointV1, pgCluster.Status.ID, pgCluster.Spec.Description, twoFactorDelete) - if err != nil { - return err - } - - return nil -} - func (r *PostgreSQLReconciler) findSecretObject(secret client.Object) []reconcile.Request { s := secret.(*k8sCore.Secret) diff --git a/controllers/clusters/redis_controller.go b/controllers/clusters/redis_controller.go index 18d6b923d..0ee7b3eda 100644 --- a/controllers/clusters/redis_controller.go +++ b/controllers/clusters/redis_controller.go @@ -329,28 +329,15 @@ func (r *RedisReconciler) handleUpdateCluster( return r.handleExternalChanges(redis, iRedis, logger) } - if len(redis.Spec.TwoFactorDelete) != 0 && len(iRedis.Spec.TwoFactorDelete) == 0 || - redis.Spec.Description != iRedis.Spec.Description { + if redis.Spec.ClusterSettingsNeedUpdate(iRedis.Spec.Cluster) { logger.Info("Updating cluster settings", "instaclustr description", iRedis.Spec.Description, "instaclustr two factor delete", iRedis.Spec.TwoFactorDelete) - settingsToInstAPI, err := redis.Spec.ClusterSettingsUpdateToInstAPI() - if err != nil { - logger.Error(err, "Cannot convert cluster settings to Instaclustr API", - "cluster ID", redis.Status.ID, - "cluster spec", redis.Spec) - r.EventRecorder.Eventf(redis, models.Warning, models.UpdateFailed, - "Cannot update cluster settings. Reason: %v", err) - - return models.ReconcileRequeue - } - - err = r.API.UpdateClusterSettings(redis.Status.ID, settingsToInstAPI) + err = r.API.UpdateClusterSettings(redis.Status.ID, redis.Spec.ClusterSettingsUpdateToInstAPI()) if err != nil { logger.Error(err, "Cannot update cluster settings", "cluster ID", redis.Status.ID, "cluster spec", redis.Spec) - r.EventRecorder.Eventf(redis, models.Warning, models.UpdateFailed, "Cannot update cluster settings. Reason: %v", err) diff --git a/controllers/clusters/zookeeper_controller.go b/controllers/clusters/zookeeper_controller.go index 16c002009..d2252ce7b 100644 --- a/controllers/clusters/zookeeper_controller.go +++ b/controllers/clusters/zookeeper_controller.go @@ -231,8 +231,34 @@ func (r *ZookeeperReconciler) handleUpdateCluster( if zook.Annotations[models.ExternalChangesAnnotation] == models.True { r.handleExternalChanges(zook, l) - } else { - l.Info("Cluster update is not implemented yet") + } + + iData, err := r.API.GetZookeeper(zook.Status.ID) + if err != nil { + l.Error(err, "Cannot get cluster from the Instaclustr", "cluster ID", zook.Status.ID) + return models.ReconcileRequeue + } + + iZook, err := zook.FromInstAPI(iData) + if err != nil { + l.Error(err, "Cannot convert cluster from the Instaclustr API", "cluster ID", zook.Status.ID) + return models.ReconcileRequeue + } + + if zook.Spec.ClusterSettingsNeedUpdate(iZook.Spec.Cluster) { + l.Info("Updating cluster settings", + "instaclustr description", iZook.Spec.Description, + "instaclustr two factor delete", iZook.Spec.TwoFactorDelete) + + err = r.API.UpdateClusterSettings(zook.Status.ID, zook.Spec.ClusterSettingsUpdateToInstAPI()) + if err != nil { + l.Error(err, "Cannot update cluster settings", + "cluster ID", zook.Status.ID, "cluster spec", zook.Spec) + r.EventRecorder.Eventf(zook, models.Warning, models.UpdateFailed, + "Cannot update cluster settings. Reason: %v", err) + + return models.ReconcileRequeue + } } return models.ExitReconcile diff --git a/pkg/models/cadence_apiv2.go b/pkg/models/cadence_apiv2.go index b12315dc3..024721642 100644 --- a/pkg/models/cadence_apiv2.go +++ b/pkg/models/cadence_apiv2.go @@ -41,6 +41,7 @@ type CadenceCluster struct { TargetPrimaryCadence []*TargetCadence `json:"targetPrimaryCadence,omitempty"` TargetSecondaryCadence []*TargetCadence `json:"targetSecondaryCadence,omitempty"` ResizeSettings []*ResizeSettings `json:"resizeSettings,omitempty"` + Description string `json:"description,omitempty"` } type CadenceDataCentre struct { diff --git a/pkg/models/cassandra_apiv2.go b/pkg/models/cassandra_apiv2.go index 7a7f09502..7edc6de30 100644 --- a/pkg/models/cassandra_apiv2.go +++ b/pkg/models/cassandra_apiv2.go @@ -30,7 +30,7 @@ type CassandraCluster struct { TwoFactorDelete []*TwoFactorDelete `json:"twoFactorDelete,omitempty"` BundledUseOnly bool `json:"bundledUseOnly,omitempty"` ResizeSettings []*ResizeSettings `json:"resizeSettings"` - Description string `json:"description"` + Description string `json:"description,omitempty"` } type CassandraDataCentre struct { diff --git a/pkg/models/kafka_apiv2.go b/pkg/models/kafka_apiv2.go index ffe39a220..b01138a9e 100644 --- a/pkg/models/kafka_apiv2.go +++ b/pkg/models/kafka_apiv2.go @@ -39,6 +39,7 @@ type KafkaCluster struct { RestProxy []*RestProxy `json:"restProxy"` SchemaRegistry []*SchemaRegistry `json:"schemaRegistry"` ResizeSettings []*ResizeSettings `json:"resizeSettings,omitempty"` + Description string `json:"description,omitempty"` } type KafkaDataCentre struct { diff --git a/pkg/models/kafka_connect_apiv2.go b/pkg/models/kafka_connect_apiv2.go index 841aafc64..2785bf06d 100644 --- a/pkg/models/kafka_connect_apiv2.go +++ b/pkg/models/kafka_connect_apiv2.go @@ -27,6 +27,7 @@ type KafkaConnectCluster struct { TargetCluster []*TargetCluster `json:"targetCluster,omitempty"` DataCentres []*KafkaConnectDataCentre `json:"dataCentres,omitempty"` ResizeSettings []*ResizeSettings `json:"resizeSettings,omitempty"` + Description string `json:"description,omitempty"` } type ManagedCluster struct { diff --git a/pkg/models/opensearch_apiv2.go b/pkg/models/opensearch_apiv2.go index ac776aaed..51abc7776 100644 --- a/pkg/models/opensearch_apiv2.go +++ b/pkg/models/opensearch_apiv2.go @@ -40,6 +40,7 @@ type OpenSearchCluster struct { SLATier string `json:"slaTier,omitempty"` AlertingPlugin bool `json:"alertingPlugin"` ResizeSettings []*ResizeSettings `json:"resizeSettings,omitempty"` + Description string `json:"description,omitempty"` } type OpenSearchDataNodes struct { diff --git a/pkg/models/postgresql_apiv2.go b/pkg/models/postgresql_apiv2.go index b31bd8123..bcdfefff1 100644 --- a/pkg/models/postgresql_apiv2.go +++ b/pkg/models/postgresql_apiv2.go @@ -28,6 +28,7 @@ type PGCluster struct { PCIComplianceMode bool `json:"pciComplianceMode,omitempty"` CurrentClusterOperationStatus string `json:"currentClusterOperationStatus,omitempty"` Status string `json:"status,omitempty"` + Description string `json:"description,omitempty"` } type PGBouncer struct { diff --git a/pkg/models/redis_apiv2.go b/pkg/models/redis_apiv2.go index 1664024ec..a52155d59 100644 --- a/pkg/models/redis_apiv2.go +++ b/pkg/models/redis_apiv2.go @@ -27,7 +27,7 @@ type RedisCluster struct { PasswordAndUserAuth bool `json:"passwordAndUserAuth"` TwoFactorDelete []*TwoFactorDelete `json:"twoFactorDelete,omitempty"` SLATier string `json:"slaTier"` - Description string `json:"description"` + Description string `json:"description,omitempty"` } type RedisDataCentre struct { diff --git a/pkg/models/zookeeper_apiv2.go b/pkg/models/zookeeper_apiv2.go index c42dd5711..1645b6184 100644 --- a/pkg/models/zookeeper_apiv2.go +++ b/pkg/models/zookeeper_apiv2.go @@ -26,6 +26,7 @@ type ZookeeperCluster struct { SLATier string `json:"slaTier"` TwoFactorDelete []*TwoFactorDelete `json:"twoFactorDelete,omitempty"` DataCentres []*ZookeeperDataCentre `json:"dataCentres"` + Description string `json:"description,omitempty"` } type ZookeeperDataCentre struct {