Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cluster settings update for the rest of the clusters #593

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
46 changes: 16 additions & 30 deletions controllers/clusters/cassandra_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down 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
Loading