Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ Changelog for Cass Operator, new PRs should update the `main / unreleased` secti

## unreleased

* [ENHANCEMENT] [#912](https://github.com/k8ssandra/cass-operator/issues/912) Add new webhook validations for maxUnavailable string format as well as PVC sizes
* [ENHANCEMENT] [#902](https://github.com/k8ssandra/cass-operator/issues/902) If scaling down or scaling up process is still ongoing, the webhook will prevent changing the cluster size.

## v1.30.0

* [CHANGE] [#905](https://github.com/k8ssandra/cass-operator/issues/905) Relax the ServerVersion checks to structure only without separating OSS/DSE/HCD.
Expand Down
3 changes: 3 additions & 0 deletions apis/cassandra/v1beta1/cassandradatacenter_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ const (
// EnableParallelCleanupWithinRackAnnotation speeds up post-scale-out cleanup by processing nodes in parallel within a rack.
EnableParallelCleanupWithinRackAnnotation = "cassandra.datastax.com/enable-parallel-cleanup-within-rack"

// BypassWebhookValidationsAnnotation allows bypassing CassandraDatacenter update webhook validations
BypassWebhookValidationsAnnotation = "cassandra.datastax.com/bypass-webhook-validations"

AllowUpdateAlways AllowUpdateType = "always"
AllowUpdateOnce AllowUpdateType = "once"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ import (
apiequality "k8s.io/apimachinery/pkg/api/equality"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/intstr"
ctrl "sigs.k8s.io/controller-runtime"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"

"github.com/google/go-cmp/cmp"
api "github.com/k8ssandra/cass-operator/apis/cassandra/v1beta1"
corev1 "k8s.io/api/core/v1"
)

// log is for logging in this package.
Expand Down Expand Up @@ -85,6 +87,13 @@ func (v *CassandraDatacenterCustomValidator) ValidateUpdate(ctx context.Context,

log.Info("Validation for CassandraDatacenter upon update", "name", dc.GetName())

if metav1.HasAnnotation(dc.ObjectMeta, api.BypassWebhookValidationsAnnotation) &&
dc.Annotations[api.BypassWebhookValidationsAnnotation] == "true" {
log.Info("Webhook validations bypassed with annotation")

return nil, nil
}

if err := ValidateSingleDatacenter(dc); err != nil {
return nil, err
}
Expand Down Expand Up @@ -134,6 +143,13 @@ func ValidateSingleDatacenter(dc *api.CassandraDatacenter) error {
return attemptedTo("define config dse-yaml with %s", serverStr)
}

if dc.Spec.MaxUnavailable != nil {
maxUnavailable, err := intstr.GetScaledValueFromIntOrPercent(dc.Spec.MaxUnavailable, int(dc.Spec.Size), true)
if err != nil || maxUnavailable < 0 {
return attemptedTo("use invalid maxUnavailable value '%s'", dc.Spec.MaxUnavailable.String())
}
}

// if using multiple nodes per worker, requests and limits should be set for both cpu and memory
if dc.Spec.AllowMultipleNodesPerWorker {
if dc.Spec.Resources.Requests.Cpu().IsZero() ||
Expand Down Expand Up @@ -180,6 +196,15 @@ func ValidateDatacenterFieldChanges(oldDc *api.CassandraDatacenter, newDc *api.C

oldClaimSpec := oldDc.Spec.StorageConfig.CassandraDataVolumeClaimSpec.DeepCopy()
newClaimSpec := newDc.Spec.StorageConfig.CassandraDataVolumeClaimSpec.DeepCopy()
if oldClaimSpec != nil && newClaimSpec != nil {
oldStorageRequest := oldClaimSpec.Resources.Requests[corev1.ResourceStorage]
newStorageRequest := newClaimSpec.Resources.Requests[corev1.ResourceStorage]

if oldStorageRequest.Cmp(newStorageRequest) > 0 {
return attemptedTo(
"shrink storageConfig.CassandraDataVolumeClaimSpec from %s to %s", oldStorageRequest.String(), newStorageRequest.String())
}
}

// CassandraDataVolumeClaimSpec changes are disallowed
if metav1.HasAnnotation(newDc.ObjectMeta, api.AllowStorageChangesAnnotation) && newDc.Annotations[api.AllowStorageChangesAnnotation] == "true" {
Expand All @@ -192,6 +217,17 @@ func ValidateDatacenterFieldChanges(oldDc *api.CassandraDatacenter, newDc *api.C
return attemptedTo("change storageConfig.CassandraDataVolumeClaimSpec, diff: %s", pvcSourceDiff)
}

if oldDc.Spec.Size != newDc.Spec.Size {
if oldDc.GetConditionStatus(api.DatacenterScalingUp) == corev1.ConditionTrue {
return attemptedTo("change size while datacenter is still scaling up")
}

if oldDc.GetConditionStatus(api.DatacenterScalingDown) == corev1.ConditionTrue {
// Here we don't want to allow any changes as scaling down is a lot heavier operation
return attemptedTo("change size while datacenter is still scaling down")
}
}

// Topology changes - Racks
// - Rack Name and Zone changes are disallowed.
// - Removing racks is not supported.
Expand Down
Loading
Loading