diff --git a/apis/clusters/v1beta1/cassandra_types.go b/apis/clusters/v1beta1/cassandra_types.go index 8c9a52a13..466ee58c8 100644 --- a/apis/clusters/v1beta1/cassandra_types.go +++ b/apis/clusters/v1beta1/cassandra_types.go @@ -205,7 +205,7 @@ func (cs *CassandraSpec) validateUpdate(oldSpec CassandraSpec) error { return fmt.Errorf("cannot update immutable fields: old spec: %+v: new spec: %+v", oldImmutableFields, newImmutableFields) } - err := cs.validateImmutableDataCentresFieldsUpdate(oldSpec) + err := cs.validateDataCentresUpdate(oldSpec) if err != nil { return err } @@ -221,12 +221,13 @@ func (cs *CassandraSpec) validateUpdate(oldSpec CassandraSpec) error { return nil } -func (cs *CassandraSpec) validateImmutableDataCentresFieldsUpdate(oldSpec CassandraSpec) error { +func (cs *CassandraSpec) validateDataCentresUpdate(oldSpec CassandraSpec) error { if len(cs.DataCentres) < len(oldSpec.DataCentres) { return models.ErrDecreasedDataCentresNumber } for _, newDC := range cs.DataCentres { + var exists bool for _, oldDC := range oldSpec.DataCentres { if oldDC.Name == newDC.Name { newDCImmutableFields := newDC.newImmutableFields() @@ -254,9 +255,33 @@ func (cs *CassandraSpec) validateImmutableDataCentresFieldsUpdate(oldSpec Cassan return err } + exists = true break } } + + if !exists { + err := newDC.DataCentre.ValidateCreation() + if err != nil { + return err + } + + if !cs.PrivateNetworkCluster && newDC.PrivateIPBroadcastForDiscovery { + return fmt.Errorf("cannot use private ip broadcast for discovery on public network cluster") + } + + err = validateReplicationFactor(models.CassandraReplicationFactors, newDC.ReplicationFactor) + if err != nil { + return err + } + + if ((newDC.NodesNumber*newDC.ReplicationFactor)/newDC.ReplicationFactor)%newDC.ReplicationFactor != 0 { + return fmt.Errorf("number of nodes must be a multiple of replication factor: %v", newDC.ReplicationFactor) + } + + return nil + + } } return nil diff --git a/apis/clusters/v1beta1/opensearch_webhook.go b/apis/clusters/v1beta1/opensearch_webhook.go index 84b8789ce..496e968dd 100644 --- a/apis/clusters/v1beta1/opensearch_webhook.go +++ b/apis/clusters/v1beta1/opensearch_webhook.go @@ -326,8 +326,8 @@ func (oss *OpenSearchSpec) validateUpdate(oldSpec OpenSearchSpec) error { func (oss *OpenSearchSpec) validateImmutableDataCentresUpdate(oldDCs []*OpenSearchDataCentre) error { newDCs := oss.DataCentres - if len(newDCs) < len(oldDCs) { - return models.ErrImmutableDataCentres + if len(newDCs) != len(oldDCs) { + return models.ErrImmutableDataCentresNumber } for _, newDC := range newDCs {