Skip to content

Commit

Permalink
add the cluster settings update for the rest of the clusters
Browse files Browse the repository at this point in the history
  • Loading branch information
ribaraka committed Oct 16, 2023
1 parent d55ad15 commit e9cccef
Show file tree
Hide file tree
Showing 23 changed files with 136 additions and 97 deletions.
4 changes: 3 additions & 1 deletion apis/clusters/v1beta1/cadence_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions apis/clusters/v1beta1/kafka_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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),
Expand Down
2 changes: 2 additions & 0 deletions apis/clusters/v1beta1/kafkaconnect_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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(),
Expand Down
2 changes: 2 additions & 0 deletions apis/clusters/v1beta1/opensearch_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down
3 changes: 2 additions & 1 deletion apis/clusters/v1beta1/postgresql_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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),
},
Expand Down
13 changes: 7 additions & 6 deletions apis/clusters/v1beta1/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions apis/clusters/v1beta1/zookeeper_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -154,6 +155,7 @@ func (zs *ZookeeperSpec) ToInstAPI() *models.ZookeeperCluster {
SLATier: zs.SLATier,
TwoFactorDelete: zs.Cluster.TwoFactorDeletesToInstAPI(),
DataCentres: zs.DCsToInstAPI(),
Description: zs.Description,
}
}

Expand Down
36 changes: 12 additions & 24 deletions controllers/clusters/cadence_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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 {
Expand Down
18 changes: 2 additions & 16 deletions controllers/clusters/cassandra_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
16 changes: 16 additions & 0 deletions controllers/clusters/kafka_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
16 changes: 16 additions & 0 deletions controllers/clusters/kafkaconnect_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 16 additions & 0 deletions controllers/clusters/opensearch_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
46 changes: 16 additions & 30 deletions controllers/clusters/postgresql_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
17 changes: 2 additions & 15 deletions controllers/clusters/redis_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Loading

0 comments on commit e9cccef

Please sign in to comment.