Skip to content

Commit

Permalink
AdditionalVolumes to allow VolumeSource (#487)
Browse files Browse the repository at this point in the history
* Allow AdditionalVolumes to be sourced from a VolumeSource and not just PVCSpec. Also, change PVCSpec to a pointer in the AdditionalVolume

* Fix webhook_test

* Add the actual implementation
  • Loading branch information
burmanm authored Jan 30, 2023
1 parent 1d21f8f commit 43d6635
Show file tree
Hide file tree
Showing 9 changed files with 1,866 additions and 22 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ Changelog for Cass Operator, new PRs should update the `main / unreleased` secti
* [CHANGE] [#448](https://github.com/k8ssandra/cass-operator/issues/448) Update to operator-sdk 1.25.1, update to go 1.19, update to Kubernetes 1.25, remove amd64 restriction on local builds (cass-operator and system-logger will be built for aarch64 also)
* [CHANGE] [#442](https://github.com/k8ssandra/cass-operator/issues/442) Deprecate old internode-encryption storage mounts and cert generation. If old path /etc/encryption/node.jks is no longer present, then the storage mount is no longer created. For certificates with internode-encryption, we recommend using cert-manager.
* [CHANGE] [#329](https://github.com/k8ssandra/cass-operator/issues/329) Thrift port is no longer open for Cassandra 4.x installations
* [CHANGE] [#487](https://github.com/k8ssandra/cass-operator/pull/487) The AdditionalVolumes.PVCSpec is now a pointer. Also, webhook will allow modifying AdditionalVolumes.
* [FEATURE] [#441](https://github.com/k8ssandra/cass-operator/issues/441) Implement a CassandraTask for moving single-token nodes
* [ENHANCEMENT] [#486](https://github.com/k8ssandra/cass-operator/issues/486) AdditionalVolumes accepts VolumeSource as the data also, allowing ConfigMap/Secret/etc to be mounted to cassandra container.
* [ENHANCEMENT] [#467](https://github.com/k8ssandra/cass-operator/issues/467) Add new metrics endpoint port (9000) to Cassandra container. This is used by the new mgmt-api /metrics endpoint.
* [ENHANCEMENT] [#457](https://github.com/k8ssandra/cass-operator/issues/362) Allow overriding the datacenter name
* [ENHANCEMENT] [#476](https://github.com/k8ssandra/cass-operator/issues/476) Enable CDC for DSE deployments.
Expand Down
11 changes: 8 additions & 3 deletions apis/cassandra/v1beta1/cassandradatacenter_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,16 @@ type DseWorkloads struct {
type AdditionalVolumes struct {
// Mount path into cassandra container
MountPath string `json:"mountPath"`
// Name of the pvc

// Name of the pvc / volume
// +kubebuilder:validation:Pattern=[a-z0-9]([-a-z0-9]*[a-z0-9])?
Name string `json:"name"`
// Persistent volume claim spec
PVCSpec corev1.PersistentVolumeClaimSpec `json:"pvcSpec"`

// PVCSpec is a persistent volume claim spec. Either this or VolumeSource is required.
PVCSpec *corev1.PersistentVolumeClaimSpec `json:"pvcSpec,omitempty"`

// VolumeSource to mount the volume from (such as ConfigMap / Secret). This or PVCSpec is required.
VolumeSource *corev1.VolumeSource `json:"volumeSource,omitempty"`
}

type AdditionalVolumesSlice []AdditionalVolumes
Expand Down
31 changes: 28 additions & 3 deletions apis/cassandra/v1beta1/cassandradatacenter_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ func ValidateSingleDatacenter(dc CassandraDatacenter) error {
return err
}

if err := ValidateAdditionalVolumes(dc); err != nil {
return err
}

return ValidateFQLConfig(dc)
}

Expand Down Expand Up @@ -150,9 +154,16 @@ func ValidateDatacenterFieldChanges(oldDc CassandraDatacenter, newDc CassandraDa
return attemptedTo("change serviceAccount")
}

// StorageConfig changes are disallowed
if !reflect.DeepEqual(oldDc.Spec.StorageConfig, newDc.Spec.StorageConfig) {
return attemptedTo("change storageConfig")
// CassandraDataVolumeClaimSpec changes are disallowed

if !reflect.DeepEqual(oldDc.Spec.StorageConfig.CassandraDataVolumeClaimSpec, newDc.Spec.StorageConfig.CassandraDataVolumeClaimSpec) {
return attemptedTo("change storageConfig.CassandraDataVolumeClaimSpec")
}

if oldDc.Spec.StorageConfig.CassandraDataVolumeClaimSpec != nil {
if !reflect.DeepEqual(*oldDc.Spec.StorageConfig.CassandraDataVolumeClaimSpec, *newDc.Spec.StorageConfig.CassandraDataVolumeClaimSpec) {
return attemptedTo("change storageConfig.CassandraDataVolumeClaimSpec")
}
}

// Topology changes - Racks
Expand Down Expand Up @@ -218,6 +229,20 @@ func ValidateDeprecatedFieldUsage(dc CassandraDatacenter) error {
return nil
}

func ValidateAdditionalVolumes(dc CassandraDatacenter) error {
for _, volume := range dc.Spec.StorageConfig.AdditionalVolumes {
if volume.PVCSpec != nil && volume.VolumeSource != nil {
return attemptedTo("create a volume with both PVCSpec and VolumeSource")
}

if volume.PVCSpec == nil && volume.VolumeSource == nil {
return attemptedTo("create AdditionalVolume without PVCSpec or VolumeSource")
}
}

return nil
}

// +kubebuilder:webhook:path=/validate-cassandra-datastax-com-v1beta1-cassandradatacenter,mutating=false,failurePolicy=ignore,sideEffects=None,groups=cassandra.datastax.com,resources=cassandradatacenters,verbs=create;update,versions=v1beta1,name=vcassandradatacenter.kb.io,admissionReviewVersions={v1,v1beta1}
// +kubebuilder:webhook:path=/validate-cassandradatacenter,mutating=false,failurePolicy=ignore,groups=cassandra.datastax.com,resources=cassandradatacenters,verbs=create;update,versions=v1beta1,name=validate-cassandradatacenter-webhook
var _ webhook.Validator = &CassandraDatacenter{}
Expand Down
2 changes: 1 addition & 1 deletion apis/cassandra/v1beta1/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ func Test_ValidateDatacenterFieldChanges(t *testing.T) {
},
},
},
errString: "change storageConfig",
errString: "change storageConfig.CassandraDataVolumeClaimSpec",
},
{
name: "Removing a rack",
Expand Down
11 changes: 10 additions & 1 deletion apis/cassandra/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 43d6635

Please sign in to comment.