Skip to content

Commit 828cc9b

Browse files
drivebyercndoit18
authored andcommitted
Add optional filed to keep pvc after cluster been deleted
1 parent e1af942 commit 828cc9b

File tree

5 files changed

+13
-1
lines changed

5 files changed

+13
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
88
## [Unreleased]
99

1010
### Added
11+
* Add `KeepAfterDelete` in `.Spec.VolumeSpec` to keep pvc after mysql cluster been deleted.
12+
1113
### Changed
1214
### Removed
1315
### Fixed

config/crd/bases/mysql.presslabs.org_mysqlclusters.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3827,6 +3827,9 @@ spec:
38273827
required:
38283828
- path
38293829
type: object
3830+
keepAfterDelete:
3831+
description: KeepAfterDelete specifies whether the PVC should be kept after the MysqlCluster is deleted.
3832+
type: boolean
38303833
persistentVolumeClaim:
38313834
description: PersistentVolumeClaim to specify PVC spec for the volume for mysql data. It has the highest level of precedence, followed by HostPath and EmptyDir. And represents the PVC specification.
38323835
properties:

deploy/charts/mysql-operator/crds/mysql.presslabs.org_mysqlclusters.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3828,6 +3828,9 @@ spec:
38283828
required:
38293829
- path
38303830
type: object
3831+
keepAfterDelete:
3832+
description: KeepAfterDelete specifies whether the PVC should be kept after the MysqlCluster is deleted.
3833+
type: boolean
38313834
persistentVolumeClaim:
38323835
description: PersistentVolumeClaim to specify PVC spec for the volume for mysql data. It has the highest level of precedence, followed by HostPath and EmptyDir. And represents the PVC specification.
38333836
properties:

pkg/apis/mysql/v1alpha1/mysqlcluster_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,10 @@ type VolumeSpec struct {
243243
// EmptyDir. And represents the PVC specification.
244244
// +optional
245245
PersistentVolumeClaim *core.PersistentVolumeClaimSpec `json:"persistentVolumeClaim,omitempty"`
246+
247+
// KeepAfterDelete specifies whether the PVC should be kept after the MysqlCluster is deleted.
248+
// +optional
249+
KeepAfterDelete bool `json:"keepAfterDelete,omitempty"`
246250
}
247251

248252
// QueryLimits represents the pt-kill parameters, more info can be found

pkg/controller/mysqlcluster/internal/syncer/statefullset.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ func (s *sfsSyncer) ensureVolumeClaimTemplates(in []core.PersistentVolumeClaim)
581581

582582
data.Name = dataVolumeName
583583

584-
if initPvc {
584+
if initPvc && !s.cluster.Spec.VolumeSpec.KeepAfterDelete {
585585
// This can be set only when creating new PVC. It ensures that PVC can be
586586
// terminated after deleting parent MySQL cluster
587587
trueVar := true

0 commit comments

Comments
 (0)