diff --git a/apis/k8ssandra/v1alpha1/k8ssandracluster_types.go b/apis/k8ssandra/v1alpha1/k8ssandracluster_types.go index d237cc19f..ae3e6495b 100644 --- a/apis/k8ssandra/v1alpha1/k8ssandracluster_types.go +++ b/apis/k8ssandra/v1alpha1/k8ssandracluster_types.go @@ -201,6 +201,18 @@ func (in *K8ssandraCluster) GetInitializedDatacenters() []CassandraDatacenterTem return datacenters } +func (in *K8ssandraCluster) GetHealthyDatacenters() []CassandraDatacenterTemplate { + datacenters := make([]CassandraDatacenterTemplate, 0) + if in != nil && in.Spec.Cassandra != nil { + for _, dc := range in.Spec.Cassandra.Datacenters { + if status, found := in.Status.Datacenters[dc.Meta.Name]; found && status.Cassandra.GetConditionStatus(cassdcapi.DatacenterHealthy) == corev1.ConditionTrue { + datacenters = append(datacenters, dc) + } + } + } + return datacenters +} + // SanitizedName returns a sanitized version of the name returned by CassClusterName() func (in *K8ssandraCluster) SanitizedName() string { return cassdcapi.CleanupForKubernetes(in.CassClusterName()) diff --git a/controllers/k8ssandra/schemas.go b/controllers/k8ssandra/schemas.go index 3ef3eeb7e..2901413e7 100644 --- a/controllers/k8ssandra/schemas.go +++ b/controllers/k8ssandra/schemas.go @@ -147,7 +147,7 @@ func (r *K8ssandraClusterReconciler) updateReplicationOfSystemKeyspaces( return recResult } - replication := cassandra.ComputeReplicationFromDatacenters(3, kc.Spec.ExternalDatacenters, kc.GetInitializedDatacenters()...) + replication := cassandra.ComputeReplicationFromDatacenters(3, kc.Spec.ExternalDatacenters, kc.GetHealthyDatacenters()...) logger.Info("Preparing to update replication for system keyspaces", "replication", replication) diff --git a/test/framework/framework.go b/test/framework/framework.go index 1f56cc6a1..b0764341c 100644 --- a/test/framework/framework.go +++ b/test/framework/framework.go @@ -297,6 +297,11 @@ func (f *Framework) SetDatacenterStatusReady(ctx context.Context, key ClusterKey Status: corev1.ConditionTrue, LastTransitionTime: now, }) + dc.Status.SetCondition(cassdcapi.DatacenterCondition{ + Type: cassdcapi.DatacenterHealthy, + Status: corev1.ConditionTrue, + LastTransitionTime: now, + }) dc.Status.ObservedGeneration = dc.Generation dc.Status.NodeStatuses = cassdcapi.CassandraStatusMap{} for i := 0; i < int(dc.Spec.Size); i++ { @@ -373,6 +378,11 @@ func (f *Framework) SetDatacenterStatusStopped(ctx context.Context, key ClusterK Status: corev1.ConditionTrue, LastTransitionTime: now, }) + dc.Status.SetCondition(cassdcapi.DatacenterCondition{ + Type: cassdcapi.DatacenterHealthy, + Status: corev1.ConditionTrue, + LastTransitionTime: now, + }) dc.Status.ObservedGeneration = dc.Generation }) }