Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

Commit

Permalink
EVEREST-468 Restrict scaling down to single node cluster (#218)
Browse files Browse the repository at this point in the history
Co-authored-by: Michal Kralik <[email protected]>
  • Loading branch information
gen1us2k and Michal Kralik authored Oct 9, 2023
1 parent 98dced7 commit e0b87cd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
12 changes: 2 additions & 10 deletions api/database_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,9 @@ func (e *EverestServer) UpdateDatabaseCluster(ctx echo.Context, kubernetesID str
if err != nil {
return errors.Join(err, errors.New("could not get old Database Cluster"))
}
if dbc.Spec.Engine.Version != nil {
// XXX: Right now we do not support upgrading of versions
// because it varies across different engines. Also, we should
// prohibit downgrades. Hence, if versions are not equal we just return an error
if oldDB.Spec.Engine.Version != *dbc.Spec.Engine.Version {
return ctx.JSON(http.StatusBadRequest, Error{
Message: pointer.ToString("Changing version is not allowed"),
})
}
if err := validateDatabaseClusterOnUpdate(dbc, oldDB); err != nil {
return ctx.JSON(http.StatusBadRequest, Error{Message: pointer.ToString(err.Error())})
}

newMonitoringName := monitoringNameFrom(dbc)
newBackupNames := backupStorageNamesFrom(dbc)
err = e.createResources(ctx.Request().Context(), oldDB, kubeClient, newMonitoringName, newBackupNames)
Expand Down
21 changes: 21 additions & 0 deletions api/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,3 +556,24 @@ func validateStorageSize(cluster *DatabaseCluster) error {
}
return nil
}

func validateDatabaseClusterOnUpdate(dbc *DatabaseCluster, oldDB *everestv1alpha1.DatabaseCluster) error {
if dbc.Spec.Engine.Version != nil {
// XXX: Right now we do not support upgrading of versions
// because it varies across different engines. Also, we should
// prohibit downgrades. Hence, if versions are not equal we just return an error
if oldDB.Spec.Engine.Version != *dbc.Spec.Engine.Version {
return errors.New("changing version is not allowed")
}
}
if *dbc.Spec.Engine.Replicas < oldDB.Spec.Engine.Replicas && *dbc.Spec.Engine.Replicas == 1 {
// XXX: We can scale down multiple node clusters to a single node but we need to set
// `allowUnsafeConfigurations` to `true`. Having this configuration is not recommended
// and makes a database cluster unsafe. Once allowUnsafeConfigurations set to true you
// can't set it to false for all operators and psmdb operator does not support it.
//
// Once it is supported by all operators we can revert this.
return fmt.Errorf("cannot scale down %d node cluster to 1. The operation is not supported", oldDB.Spec.Engine.Replicas)
}
return nil
}

0 comments on commit e0b87cd

Please sign in to comment.