Skip to content

Commit 2543e60

Browse files
author
Deng Liu
committed
update
1 parent 8ae7f43 commit 2543e60

File tree

4 files changed

+28
-270
lines changed

4 files changed

+28
-270
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ kustomize: ## Download kustomize locally if necessary.
153153
ENVTEST = $(GOBIN)/setup-envtest
154154
.PHONY: envtest
155155
envtest: ## Download envtest-setup locally if necessary.
156-
$(call go-get-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)
156+
$(call go-get-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@v0.0.0-20240320141353-395cfc7486e6)
157157

158158
.PHONY: gen-api
159159
gen-api:

pkg/k8sutils/pvc_expansion.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type PVCExpansionResult struct {
2525
NeedsExpansion bool
2626
NeedsStatefulSetRecreation bool
2727
RequiresDetachment bool
28-
OnlyPVCSizeChanged bool // True if only PVC sizes changed, no other StatefulSet changes
28+
OnlyPVCSizeChanged bool // True if only PVC sizes changed, no other StatefulSet changes
2929
PVCsToExpand []PVCExpansionInfo
3030
ValidationErrors []string
3131
}
@@ -40,11 +40,11 @@ type PVCExpansionInfo struct {
4040
}
4141

4242
// DetectPVCExpansion analyzes if PVC expansion is needed for a StatefulSet
43-
func DetectPVCExpansion(ctx context.Context, k8sClient client.Client,
43+
func DetectPVCExpansion(ctx context.Context, k8sClient client.Client,
4444
namespace, statefulSetName string, newStorageVolumes []v1.StorageVolume) (*PVCExpansionResult, error) {
45-
45+
4646
logger := log.FromContext(ctx).WithName("pvc-expansion")
47-
47+
4848
result := &PVCExpansionResult{
4949
PVCsToExpand: []PVCExpansionInfo{},
5050
ValidationErrors: []string{},
@@ -75,7 +75,7 @@ func DetectPVCExpansion(ctx context.Context, k8sClient client.Client,
7575
if isSpecialStorageClass(sv) || strings.HasPrefix(sv.StorageSize, "0") {
7676
continue
7777
}
78-
78+
7979
pvc := corev1.PersistentVolumeClaim{
8080
ObjectMeta: metav1.ObjectMeta{Name: sv.Name},
8181
Spec: corev1.PersistentVolumeClaimSpec{
@@ -173,7 +173,7 @@ func DetectPVCExpansion(ctx context.Context, k8sClient client.Client,
173173
// ExpandPVCs performs the actual PVC expansion
174174
func ExpandPVCs(ctx context.Context, k8sClient client.Client, expansionInfos []PVCExpansionInfo) error {
175175
logger := log.FromContext(ctx).WithName("pvc-expansion")
176-
176+
177177
for _, info := range expansionInfos {
178178
logger.Info("Expanding PVC", "pvc", info.PVCName, "namespace", info.Namespace,
179179
"currentSize", info.CurrentSize.String(), "newSize", info.NewSize.String())
@@ -189,7 +189,7 @@ func ExpandPVCs(ctx context.Context, k8sClient client.Client, expansionInfos []P
189189

190190
// Update the PVC size
191191
pvc.Spec.Resources.Requests[corev1.ResourceStorage] = info.NewSize
192-
192+
193193
err = k8sClient.Update(ctx, &pvc)
194194
if err != nil {
195195
return fmt.Errorf("failed to update PVC %s: %w", info.PVCName, err)
@@ -278,9 +278,9 @@ func ExpandPVCsWithDetachment(ctx context.Context, k8sClient client.Client, expe
278278
}
279279

280280
// getStatefulSetPVCs returns all PVCs for a specific volume in a StatefulSet
281-
func getStatefulSetPVCs(ctx context.Context, k8sClient client.Client,
281+
func getStatefulSetPVCs(ctx context.Context, k8sClient client.Client,
282282
namespace, statefulSetName, volumeName string) ([]corev1.PersistentVolumeClaim, error) {
283-
283+
284284
var pvcList corev1.PersistentVolumeClaimList
285285
err := k8sClient.List(ctx, &pvcList, client.InNamespace(namespace))
286286
if err != nil {
@@ -514,11 +514,11 @@ func requiresDetachmentForExpansion(sc *storagev1.StorageClass) bool {
514514
// Known provisioners that support online expansion (safe to expand without detachment)
515515
onlineExpansionSupportedProvisioners := map[string]bool{
516516
// Google Cloud Persistent Disk
517-
"kubernetes.io/gce-pd": true,
517+
"kubernetes.io/gce-pd": true,
518518
"pd.csi.storage.gke.io": true,
519519
// AWS EBS
520520
"kubernetes.io/aws-ebs": true,
521-
"ebs.csi.aws.com": true,
521+
"ebs.csi.aws.com": true,
522522
// DigitalOcean Block Storage
523523
"dobs.csi.digitalocean.com": true,
524524
// Linode Block Storage

pkg/k8sutils/pvc_expansion_test.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ func TestDetectPVCExpansion(t *testing.T) {
2323
_ = storagev1.AddToScheme(scheme)
2424

2525
tests := []struct {
26-
name string
27-
existingStatefulSet *appv1.StatefulSet
28-
existingPVCs []corev1.PersistentVolumeClaim
29-
newStorageVolumes []v1.StorageVolume
26+
name string
27+
existingStatefulSet *appv1.StatefulSet
28+
existingPVCs []corev1.PersistentVolumeClaim
29+
newStorageVolumes []v1.StorageVolume
3030
expectedNeedsExpansion bool
3131
expectedNeedsRecreation bool
3232
expectedOnlyPVCSizeChanged bool
@@ -117,7 +117,7 @@ func TestDetectPVCExpansion(t *testing.T) {
117117
},
118118
expectedNeedsExpansion: true,
119119
expectedNeedsRecreation: false,
120-
expectedOnlyPVCSizeChanged: true, // Only PVC size changed
120+
expectedOnlyPVCSizeChanged: true, // Only PVC size changed
121121
expectedPVCCount: 1,
122122
expectedValidationErrors: 0,
123123
},
@@ -245,15 +245,15 @@ func TestDetectPVCExpansion(t *testing.T) {
245245

246246
// Add storage classes for testing
247247
objects = append(objects, &storagev1.StorageClass{
248-
ObjectMeta: metav1.ObjectMeta{Name: "standard"},
248+
ObjectMeta: metav1.ObjectMeta{Name: "standard"},
249249
AllowVolumeExpansion: boolPtr(true),
250250
})
251251
objects = append(objects, &storagev1.StorageClass{
252-
ObjectMeta: metav1.ObjectMeta{Name: "premium"},
252+
ObjectMeta: metav1.ObjectMeta{Name: "premium"},
253253
AllowVolumeExpansion: boolPtr(true),
254254
})
255255
objects = append(objects, &storagev1.StorageClass{
256-
ObjectMeta: metav1.ObjectMeta{Name: "no-expansion"},
256+
ObjectMeta: metav1.ObjectMeta{Name: "no-expansion"},
257257
AllowVolumeExpansion: boolPtr(false),
258258
})
259259

@@ -472,11 +472,11 @@ func TestCheckStorageClassRequiresDetachment(t *testing.T) {
472472
_ = storagev1.AddToScheme(scheme)
473473

474474
tests := []struct {
475-
name string
476-
storageClassName *string
477-
storageClasses []storagev1.StorageClass
478-
expectedDetachment bool
479-
expectError bool
475+
name string
476+
storageClassName *string
477+
storageClasses []storagev1.StorageClass
478+
expectedDetachment bool
479+
expectError bool
480480
}{
481481
{
482482
name: "Unknown provisioner requires detachment (conservative default)",
@@ -563,9 +563,9 @@ func TestCheckStorageClassRequiresDetachment(t *testing.T) {
563563
expectError: false,
564564
},
565565
{
566-
name: "emptyDir storage class (special case)",
567-
storageClassName: stringPtr("emptyDir"),
568-
storageClasses: []storagev1.StorageClass{},
566+
name: "emptyDir storage class (special case)",
567+
storageClassName: stringPtr("emptyDir"),
568+
storageClasses: []storagev1.StorageClass{},
569569
expectedDetachment: false,
570570
expectError: false,
571571
},

0 commit comments

Comments
 (0)