Skip to content
Open
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
6 changes: 6 additions & 0 deletions api/v1alpha1/dragonfly_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package v1alpha1

import (
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down Expand Up @@ -169,6 +170,11 @@ type DragonflySpec struct {
// +optional
// +kubebuilder:validation:Optional
InitContainers []corev1.Container `json:"initContainers,omitempty"`

// (Optional) StatefulSet PVC Retention Policy
// +optional
// +kubebuilder:validation:Optional
PersistentVolumeClaimRetentionPolicy *appsv1.StatefulSetPersistentVolumeClaimRetentionPolicy `json:"persistentVolumeClaimRetentionPolicy,omitempty"`
}

type ServiceSpec struct {
Expand Down
6 changes: 6 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

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

19 changes: 19 additions & 0 deletions config/crd/bases/dragonflydb.io_dragonflies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6043,6 +6043,25 @@ spec:
type: string
description: (Optional) Dragonfly pod node selector
type: object
persistentVolumeClaimRetentionPolicy:
description: (Optional) StatefulSet PVC Retention Policy
properties:
whenDeleted:
description: |-
WhenDeleted specifies what happens to PVCs created from StatefulSet
VolumeClaimTemplates when the StatefulSet is deleted. The default policy
of `Retain` causes PVCs to not be affected by StatefulSet deletion. The
`Delete` policy causes those PVCs to be deleted.
type: string
whenScaled:
description: |-
WhenScaled specifies what happens to PVCs created from StatefulSet
VolumeClaimTemplates when the StatefulSet is scaled down. The default
policy of `Retain` causes PVCs to not be affected by a scaledown. The
`Delete` policy causes the associated PVCs for any excess pods above
the replica count to be deleted.
type: string
type: object
podSecurityContext:
description: (Optional) Dragonfly pod security context
properties:
Expand Down
37 changes: 37 additions & 0 deletions e2e/dragonfly_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,43 @@ var _ = Describe("Dragonfly Lifecycle tests", Ordered, FlakeAttempts(3), func()
Expect(svc.Labels).To(Equal(newLabels))
})

It("Check for PVC retention policy", func() {
err := k8sClient.Get(ctx, types.NamespacedName{
Name: name,
Namespace: namespace,
}, &df)
Expect(err).To(BeNil())

var ss appsv1.StatefulSet
err = k8sClient.Get(ctx, types.NamespacedName{
Name: name,
Namespace: namespace,
}, &ss)
Expect(err).To(BeNil())

Expect(ss.Spec.PersistentVolumeClaimRetentionPolicy).To(Equal(&appsv1.StatefulSetPersistentVolumeClaimRetentionPolicy{
WhenDeleted: appsv1.RetainPersistentVolumeClaimRetentionPolicyType,
}))

df.Spec.PersistentVolumeClaimRetentionPolicy = &appsv1.StatefulSetPersistentVolumeClaimRetentionPolicy{
WhenDeleted: appsv1.DeletePersistentVolumeClaimRetentionPolicyType,
}

err = k8sClient.Update(ctx, &df)
Expect(err).To(BeNil())

err = waitForStatefulSetReady(ctx, k8sClient, name, namespace, 3*time.Minute)
Expect(err).To(BeNil())

err = k8sClient.Get(ctx, types.NamespacedName{
Name: name,
Namespace: namespace,
}, &ss)
Expect(err).To(BeNil())

Expect(ss.Spec.PersistentVolumeClaimRetentionPolicy).To(Equal(df.Spec.PersistentVolumeClaimRetentionPolicy))
})

It("Should recreate missing statefulset", func() {
var ss appsv1.StatefulSet
err := k8sClient.Get(ctx, types.NamespacedName{
Expand Down
4 changes: 4 additions & 0 deletions internal/resources/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,10 @@ func GenerateDragonflyResources(df *resourcesv1.Dragonfly) ([]client.Object, err
}
}

if df.Spec.PersistentVolumeClaimRetentionPolicy != nil {
statefulset.Spec.PersistentVolumeClaimRetentionPolicy = df.Spec.PersistentVolumeClaimRetentionPolicy
}

statefulset.Spec.Template.Spec.Containers = mergeNamedSlices(
statefulset.Spec.Template.Spec.Containers, df.Spec.AdditionalContainers,
func(c corev1.Container) string { return c.Name })
Expand Down
19 changes: 19 additions & 0 deletions manifests/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6042,6 +6042,25 @@ spec:
type: string
description: (Optional) Dragonfly pod node selector
type: object
persistentVolumeClaimRetentionPolicy:
description: (Optional) StatefulSet PVC Retention Policy
properties:
whenDeleted:
description: |-
WhenDeleted specifies what happens to PVCs created from StatefulSet
VolumeClaimTemplates when the StatefulSet is deleted. The default policy
of `Retain` causes PVCs to not be affected by StatefulSet deletion. The
`Delete` policy causes those PVCs to be deleted.
type: string
whenScaled:
description: |-
WhenScaled specifies what happens to PVCs created from StatefulSet
VolumeClaimTemplates when the StatefulSet is scaled down. The default
policy of `Retain` causes PVCs to not be affected by a scaledown. The
`Delete` policy causes the associated PVCs for any excess pods above
the replica count to be deleted.
type: string
type: object
podSecurityContext:
description: (Optional) Dragonfly pod security context
properties:
Expand Down
19 changes: 19 additions & 0 deletions manifests/dragonfly-operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6055,6 +6055,25 @@ spec:
type: string
description: (Optional) Dragonfly pod node selector
type: object
persistentVolumeClaimRetentionPolicy:
description: (Optional) StatefulSet PVC Retention Policy
properties:
whenDeleted:
description: |-
WhenDeleted specifies what happens to PVCs created from StatefulSet
VolumeClaimTemplates when the StatefulSet is deleted. The default policy
of `Retain` causes PVCs to not be affected by StatefulSet deletion. The
`Delete` policy causes those PVCs to be deleted.
type: string
whenScaled:
description: |-
WhenScaled specifies what happens to PVCs created from StatefulSet
VolumeClaimTemplates when the StatefulSet is scaled down. The default
policy of `Retain` causes PVCs to not be affected by a scaledown. The
`Delete` policy causes the associated PVCs for any excess pods above
the replica count to be deleted.
type: string
type: object
podSecurityContext:
description: (Optional) Dragonfly pod security context
properties:
Expand Down
Loading