Skip to content

Commit

Permalink
issue-423, datacentres update validation was improved
Browse files Browse the repository at this point in the history
  • Loading branch information
worryg0d authored and taaraora committed Jul 31, 2023
1 parent e1f5a2c commit 8b60344
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
29 changes: 27 additions & 2 deletions apis/clusters/v1beta1/cassandra_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions apis/clusters/v1beta1/opensearch_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,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 {
Expand Down

0 comments on commit 8b60344

Please sign in to comment.