Skip to content

Commit

Permalink
Add new events to indicate when Datacenter was set to Valid: False
Browse files Browse the repository at this point in the history
  • Loading branch information
burmanm committed Jul 11, 2024
1 parent 89f1a58 commit a6ef1a2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
3 changes: 3 additions & 0 deletions pkg/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const (
LabeledPodAsSeed string = "LabeledPodAsSeed"
LabeledPodAsDecommissioning string = "LabeledPodAsDecommissioning"
DeletedPvc string = "DeletedPvc"
ResizingPVC string = "ResizingPVC"
UnlabeledPodAsSeed string = "UnlabeledPodAsSeed"
LabeledRackResource string = "LabeledRackResource"
ScalingUpRack string = "ScalingUpRack"
Expand All @@ -32,6 +33,8 @@ const (
DecommissionDatacenter string = "DecommissionDatacenter"
DecommissioningNode string = "DecommissioningNode"
UnhealthyDatacenter string = "UnhealthyDatacenter"
RecreatingStatefulSet string = "RecreatingStatefulSet"
InvalidDatacenterSpec string = "InvalidDatacenterSpec"
)

type LoggingEventRecorder struct {
Expand Down
1 change: 1 addition & 0 deletions pkg/reconciliation/decommission_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ func (rc *ReconciliationContext) EnsurePodsCanAbsorbDecommData(decommPod *corev1
pod.Name, free, int64(spaceUsedByDecommPod),
)
rc.ReqLogger.Error(fmt.Errorf(msg), msg)
rc.Recorder.Eventf(rc.Datacenter, corev1.EventTypeWarning, events.InvalidDatacenterSpec, msg)

dcPatch := client.MergeFrom(rc.Datacenter.DeepCopy())
updated := rc.setCondition(
Expand Down
12 changes: 10 additions & 2 deletions pkg/reconciliation/reconcile_racks.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,24 +239,29 @@ func (rc *ReconciliationContext) CheckVolumeClaimSizes(statefulSet, desiredSts *
return result.Error(err)
}
}
rc.Recorder.Eventf(rc.Datacenter, corev1.EventTypeWarning, events.InvalidDatacenterSpec, "Shrinking CassandraDatacenter PVCs is not supported")
return result.Error(fmt.Errorf("shrinking PVC %s is not supported", claim.Name))
}

if currentSize.Cmp(createdSize) < 0 {
rc.ReqLogger.Info("PVC resize request detected", "pvc", claim.Name, "currentSize", currentSize.String(), "createdSize", createdSize.String())
if !metav1.HasAnnotation(rc.Datacenter.ObjectMeta, api.AllowStorageChangesAnnotation) || rc.Datacenter.Annotations[api.AllowStorageChangesAnnotation] != "true" {
return result.Error(fmt.Errorf("PVC resize requested, but AllowStorageChangesAnnotation is not set to 'true'"))
msg := fmt.Sprintf("PVC resize requested, but %s annotation is not set to 'true'", api.AllowStorageChangesAnnotation)
rc.Recorder.Eventf(rc.Datacenter, corev1.EventTypeWarning, events.InvalidDatacenterSpec, msg)
return result.Error(fmt.Errorf(msg))
}

if !supportsExpansion {
msg := fmt.Sprintf("PVC resize requested, but StorageClass %s does not support expansion", *claim.Spec.StorageClassName)
rc.Recorder.Eventf(rc.Datacenter, corev1.EventTypeWarning, events.InvalidDatacenterSpec, msg)
dcPatch := client.MergeFrom(rc.Datacenter.DeepCopy())
if updated := rc.setCondition(api.NewDatacenterCondition(api.DatacenterValid, corev1.ConditionFalse)); updated {
if err := rc.Client.Status().Patch(rc.Ctx, rc.Datacenter, dcPatch); err != nil {
rc.ReqLogger.Error(err, "error patching datacenter status for updating")
return result.Error(err)
}
}
return result.Error(fmt.Errorf("PVC resize requested, but StorageClass does not support expansion"))
return result.Error(fmt.Errorf(msg))
}

dcPatch := client.MergeFrom(rc.Datacenter.DeepCopy())
Expand All @@ -267,6 +272,8 @@ func (rc *ReconciliationContext) CheckVolumeClaimSizes(statefulSet, desiredSts *
}
}

rc.Recorder.Eventf(rc.Datacenter, corev1.EventTypeNormal, events.ResizingPVC, "Resizing PVCs for %s", statefulSet.Name)

claims, err := rc.listPVCs(claim.Labels)
if err != nil {
return result.Error(err)
Expand Down Expand Up @@ -427,6 +434,7 @@ func (rc *ReconciliationContext) CheckRackPodTemplate() result.ReconcileResult {
statefulSet.SetResourceVersion(resVersion)
if err := rc.Client.Update(rc.Ctx, statefulSet); err != nil {
if errors.IsInvalid(err) {
rc.Recorder.Eventf(rc.Datacenter, corev1.EventTypeNormal, events.RecreatingStatefulSet, "Recreating statefulset %s", statefulSet.Name)
if err = rc.deleteStatefulSet(statefulSet); err != nil {
return result.Error(err)
}
Expand Down

0 comments on commit a6ef1a2

Please sign in to comment.