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

EVEREST-468 Restrict scaling down to single node cluster #218

Merged
merged 4 commits into from
Oct 9, 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
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
}