Skip to content

Commit

Permalink
test for cluster webhooks were implemented & cluster webhooks were re…
Browse files Browse the repository at this point in the history
…factored
  • Loading branch information
tengu-alt committed Mar 5, 2024
1 parent 5d2261a commit fd6cdfb
Show file tree
Hide file tree
Showing 26 changed files with 4,713 additions and 680 deletions.
1,018 changes: 978 additions & 40 deletions .secrets.baseline

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions apis/clusters/v1beta1/cadence_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,7 @@ func (cv *cadenceValidator) ValidateUpdate(ctx context.Context, old runtime.Obje
}
}

// ensuring if the cluster is ready for the spec updating
if (c.Status.CurrentClusterOperationStatus != models.NoOperation || c.Status.State != models.RunningStatus) && c.Generation != oldCluster.Generation {
if IsClusterNotReadyForSpecUpdate(c.Status.CurrentClusterOperationStatus, c.Status.State, c.Generation, oldCluster.Generation) {
return models.ErrClusterIsNotReadyToUpdate
}

Expand Down
2 changes: 1 addition & 1 deletion apis/clusters/v1beta1/cassandra_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type CassandraSpec struct {
GenericClusterSpec `json:",inline"`

RestoreFrom *CassandraRestoreFrom `json:"restoreFrom,omitempty" dcomparisonSkip:"true"`
DataCentres []*CassandraDataCentre `json:"dataCentres,omitempty"`
DataCentres []*CassandraDataCentre `json:"dataCentres"`
LuceneEnabled bool `json:"luceneEnabled,omitempty"`
PasswordAndUserAuth bool `json:"passwordAndUserAuth,omitempty"`
BundledUseOnly bool `json:"bundledUseOnly,omitempty"`
Expand Down
15 changes: 3 additions & 12 deletions apis/clusters/v1beta1/cassandra_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,7 @@ func (cv *cassandraValidator) ValidateCreate(ctx context.Context, obj runtime.Ob
}

if c.Spec.RestoreFrom != nil {
if c.Spec.RestoreFrom.ClusterID == "" {
return fmt.Errorf("restore clusterID field is empty")
} else {
return nil
}
return nil
}

err = c.Spec.GenericClusterSpec.ValidateCreation()
Expand All @@ -107,10 +103,6 @@ func (cv *cassandraValidator) ValidateCreate(ctx context.Context, obj runtime.Ob
return err
}

if len(c.Spec.DataCentres) == 0 {
return fmt.Errorf("data centres field is empty")
}

for _, dc := range c.Spec.DataCentres {
//TODO: add support of multiple DCs for OnPrem clusters
if len(c.Spec.DataCentres) > 1 && dc.CloudProvider == models.ONPREMISES {
Expand Down Expand Up @@ -184,11 +176,9 @@ func (cv *cassandraValidator) ValidateUpdate(ctx context.Context, old runtime.Ob
return fmt.Errorf("cannot update immutable fields: %v", err)
}

// ensuring if the cluster is ready for the spec updating
if (c.Status.CurrentClusterOperationStatus != models.NoOperation || c.Status.State != models.RunningStatus) && c.Generation != oldCluster.Generation {
if IsClusterNotReadyForSpecUpdate(c.Status.CurrentClusterOperationStatus, c.Status.State, c.Generation, oldCluster.Generation) {
return models.ErrClusterIsNotReadyToUpdate
}

return nil
}

Expand Down Expand Up @@ -301,6 +291,7 @@ func (cs *CassandraSpec) validateDataCentresUpdate(oldSpec CassandraSpec) error
return fmt.Errorf("number of nodes must be a multiple of replication factor: %v", newDC.ReplicationFactor)
}

continue
}

newDCImmutableFields := newDC.newImmutableFields()
Expand Down
Loading

0 comments on commit fd6cdfb

Please sign in to comment.