Skip to content

Commit ce28404

Browse files
veophimattcary
andauthored
Support StatefulSetAutoDeletePVC feature (#882)
* Add StatefulSetAutoDeletePVC feature gate Signed-off-by: veophi <[email protected]> * statefulset PersistentVolumeClaimDeletePolicy api change Signed-off-by: veophi <[email protected]> * controller change for statefulset auto-delete (implementation) Signed-off-by: veophi <[email protected]> * controller change for statefulset auto-delete (tests) Signed-off-by: veophi <[email protected]> * fix the underlying pollution to informer in statefulset controller Signed-off-by: veophi <[email protected]> Co-authored-by: Matthew Cary <[email protected]>
1 parent 234403c commit ce28404

27 files changed

+2756
-670
lines changed

apis/apps/defaults/v1beta1.go

+14
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ package defaults
1818

1919
import (
2020
"github.com/openkruise/kruise/apis/apps/v1beta1"
21+
"github.com/openkruise/kruise/pkg/features"
22+
utilfeature "github.com/openkruise/kruise/pkg/util/feature"
2123
appsv1 "k8s.io/api/apps/v1"
2224
"k8s.io/apimachinery/pkg/util/intstr"
2325
v1 "k8s.io/kubernetes/pkg/apis/core/v1"
@@ -56,6 +58,18 @@ func SetDefaultsStatefulSet(obj *v1beta1.StatefulSet, injectTemplateDefaults boo
5658
}
5759
}
5860

61+
if utilfeature.DefaultFeatureGate.Enabled(features.StatefulSetAutoDeletePVC) {
62+
if obj.Spec.PersistentVolumeClaimRetentionPolicy == nil {
63+
obj.Spec.PersistentVolumeClaimRetentionPolicy = &v1beta1.StatefulSetPersistentVolumeClaimRetentionPolicy{}
64+
}
65+
if len(obj.Spec.PersistentVolumeClaimRetentionPolicy.WhenDeleted) == 0 {
66+
obj.Spec.PersistentVolumeClaimRetentionPolicy.WhenDeleted = v1beta1.RetainPersistentVolumeClaimRetentionPolicyType
67+
}
68+
if len(obj.Spec.PersistentVolumeClaimRetentionPolicy.WhenScaled) == 0 {
69+
obj.Spec.PersistentVolumeClaimRetentionPolicy.WhenScaled = v1beta1.RetainPersistentVolumeClaimRetentionPolicyType
70+
}
71+
}
72+
5973
if obj.Spec.Replicas == nil {
6074
obj.Spec.Replicas = utilpointer.Int32Ptr(1)
6175
}

apis/apps/v1beta1/statefulset_types.go

+40
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,40 @@ const (
109109
InPlaceOnlyPodUpdateStrategyType PodUpdateStrategyType = "InPlaceOnly"
110110
)
111111

112+
// PersistentVolumeClaimRetentionPolicyType is a string enumeration of the policies that will determine
113+
// when volumes from the VolumeClaimTemplates will be deleted when the controlling StatefulSet is
114+
// deleted or scaled down.
115+
type PersistentVolumeClaimRetentionPolicyType string
116+
117+
const (
118+
// RetainPersistentVolumeClaimRetentionPolicyType is the default
119+
// PersistentVolumeClaimRetentionPolicy and specifies that
120+
// PersistentVolumeClaims associated with StatefulSet VolumeClaimTemplates
121+
// will not be deleted.
122+
RetainPersistentVolumeClaimRetentionPolicyType PersistentVolumeClaimRetentionPolicyType = "Retain"
123+
// DeletePersistentVolumeClaimRetentionPolicyType specifies that
124+
// PersistentVolumeClaims associated with StatefulSet VolumeClaimTemplates
125+
// will be deleted in the scenario specified in
126+
// StatefulSetPersistentVolumeClaimPolicy.
127+
DeletePersistentVolumeClaimRetentionPolicyType PersistentVolumeClaimRetentionPolicyType = "Delete"
128+
)
129+
130+
// StatefulSetPersistentVolumeClaimRetentionPolicy describes the policy used for PVCs
131+
// created from the StatefulSet VolumeClaimTemplates.
132+
type StatefulSetPersistentVolumeClaimRetentionPolicy struct {
133+
// WhenDeleted specifies what happens to PVCs created from StatefulSet
134+
// VolumeClaimTemplates when the StatefulSet is deleted. The default policy
135+
// of `Retain` causes PVCs to not be affected by StatefulSet deletion. The
136+
// `Delete` policy causes those PVCs to be deleted.
137+
WhenDeleted PersistentVolumeClaimRetentionPolicyType `json:"whenDeleted,omitempty"`
138+
// WhenScaled specifies what happens to PVCs created from StatefulSet
139+
// VolumeClaimTemplates when the StatefulSet is scaled down. The default
140+
// policy of `Retain` causes PVCs to not be affected by a scaledown. The
141+
// `Delete` policy causes the associated PVCs for any excess pods above
142+
// the replica count to be deleted.
143+
WhenScaled PersistentVolumeClaimRetentionPolicyType `json:"whenScaled,omitempty"`
144+
}
145+
112146
// StatefulSetSpec defines the desired state of StatefulSet
113147
type StatefulSetSpec struct {
114148
// replicas is the desired number of replicas of the given Template.
@@ -188,6 +222,12 @@ type StatefulSetSpec struct {
188222
// scaleStrategy indicates the StatefulSetScaleStrategy that will be
189223
// employed to scale Pods in the StatefulSet.
190224
ScaleStrategy *StatefulSetScaleStrategy `json:"scaleStrategy,omitempty"`
225+
226+
// PersistentVolumeClaimRetentionPolicy describes the policy used for PVCs created from
227+
// the StatefulSet VolumeClaimTemplates. This requires the
228+
// StatefulSetAutoDeletePVC feature gate to be enabled, which is alpha.
229+
// +optional
230+
PersistentVolumeClaimRetentionPolicy *StatefulSetPersistentVolumeClaimRetentionPolicy `json:"persistentVolumeClaimRetentionPolicy,omitempty"`
191231
}
192232

193233
// StatefulSetScaleStrategy defines strategies for pods scale.

apis/apps/v1beta1/zz_generated.deepcopy.go

+20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/apps.kruise.io_statefulsets.yaml

+21
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,27 @@ spec:
528528
type: object
529529
type: object
530530
type: object
531+
persistentVolumeClaimRetentionPolicy:
532+
description: PersistentVolumeClaimRetentionPolicy describes the policy
533+
used for PVCs created from the StatefulSet VolumeClaimTemplates.
534+
This requires the StatefulSetAutoDeletePVC feature gate to be enabled,
535+
which is alpha.
536+
properties:
537+
whenDeleted:
538+
description: WhenDeleted specifies what happens to PVCs created
539+
from StatefulSet VolumeClaimTemplates when the StatefulSet is
540+
deleted. The default policy of `Retain` causes PVCs to not be
541+
affected by StatefulSet deletion. The `Delete` policy causes
542+
those PVCs to be deleted.
543+
type: string
544+
whenScaled:
545+
description: WhenScaled specifies what happens to PVCs created
546+
from StatefulSet VolumeClaimTemplates when the StatefulSet is
547+
scaled down. The default policy of `Retain` causes PVCs to not
548+
be affected by a scaledown. The `Delete` policy causes the associated
549+
PVCs for any excess pods above the replica count to be deleted.
550+
type: string
551+
type: object
531552
podManagementPolicy:
532553
description: podManagementPolicy controls how pods are created during
533554
initial scale up, when replacing pods on nodes, or when scaling

config/crd/bases/apps.kruise.io_uniteddeployments.yaml

+24
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,30 @@ spec:
160160
type: object
161161
type: object
162162
type: object
163+
persistentVolumeClaimRetentionPolicy:
164+
description: PersistentVolumeClaimRetentionPolicy describes
165+
the policy used for PVCs created from the StatefulSet
166+
VolumeClaimTemplates. This requires the StatefulSetAutoDeletePVC
167+
feature gate to be enabled, which is alpha.
168+
properties:
169+
whenDeleted:
170+
description: WhenDeleted specifies what happens to
171+
PVCs created from StatefulSet VolumeClaimTemplates
172+
when the StatefulSet is deleted. The default policy
173+
of `Retain` causes PVCs to not be affected by StatefulSet
174+
deletion. The `Delete` policy causes those PVCs
175+
to be deleted.
176+
type: string
177+
whenScaled:
178+
description: WhenScaled specifies what happens to
179+
PVCs created from StatefulSet VolumeClaimTemplates
180+
when the StatefulSet is scaled down. The default
181+
policy of `Retain` causes PVCs to not be affected
182+
by a scaledown. The `Delete` policy causes the associated
183+
PVCs for any excess pods above the replica count
184+
to be deleted.
185+
type: string
186+
type: object
163187
podManagementPolicy:
164188
description: podManagementPolicy controls how pods are
165189
created during initial scale up, when replacing pods

go.sum

-2
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,6 @@ golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8U
938938
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
939939
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
940940
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
941-
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
942941
golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
943942
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
944943
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
@@ -1022,7 +1021,6 @@ golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81R
10221021
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
10231022
golang.org/x/net v0.0.0-20201006153459-a7d1128ccaa0/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
10241023
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
1025-
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
10261024
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
10271025
golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
10281026
golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=

0 commit comments

Comments
 (0)