Skip to content

Commit

Permalink
shrinking is not supported
Browse files Browse the repository at this point in the history
  • Loading branch information
cofyc committed Aug 13, 2020
1 parent d10d479 commit 2deccfc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
5 changes: 4 additions & 1 deletion pkg/manager/member/pvc_resizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import (
// - If the feature `ExpandInUsePersistentVolumes` is not enabled or the volume
// plugin does not support, the pod referencing the volume must be deleted and
// recreted after the `FileSystemResizePending` condition becomes true.
// - Shrinking volumes is not supported.
//
type PVCResizerInterface interface {
Resize(*v1alpha1.TidbCluster) error
Expand Down Expand Up @@ -169,12 +170,14 @@ func (p *pvcResizer) patchPVCs(ns string, selector labels.Selector, storageReque
klog.Warningf("Storage Class %q used by PVC %s/%s does not support volume expansion, skipped", *pvc.Spec.StorageClassName, pvc.Namespace, pvc.Name)
continue
}
if currentRequest, ok := pvc.Spec.Resources.Requests[corev1.ResourceStorage]; !ok || currentRequest != storageRequest {
if currentRequest, ok := pvc.Spec.Resources.Requests[corev1.ResourceStorage]; !ok || storageRequest.Cmp(currentRequest) > 0 {
_, err = p.kubeCli.CoreV1().PersistentVolumeClaims(pvc.Namespace).Patch(pvc.Name, types.MergePatchType, mergePatch)
if err != nil {
return err
}
klog.V(2).Infof("PVC %s/%s storage request is updated from %s to %s", pvc.Namespace, pvc.Name, currentRequest.String(), storageRequest.String())
} else if storageRequest.Cmp(currentRequest) < 0 {
klog.Warningf("PVC %s/%s/ storage request cannot be shrinked (%s to %s), skipped", pvc.Namespace, pvc.Name, currentRequest.String(), storageRequest.String())
} else {
klog.V(4).Infof("PVC %s/%s storage request is already %s, skipped", pvc.Namespace, pvc.Name, storageRequest.String())
}
Expand Down
31 changes: 26 additions & 5 deletions pkg/manager/member/pvc_resizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,9 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes/fake"
"k8s.io/klog"
"k8s.io/utils/pointer"
)

func init() {
klog.InitFlags(nil)
}

func newPVCWithStorage(name string, component string, storaegClass, storageRequest string) *v1.PersistentVolumeClaim {
return &v1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -257,6 +252,32 @@ func TestPVCResizer(t *testing.T) {
},
wantErr: nil,
},
{
name: "shrinking is not supported",
tc: &v1alpha1.TidbCluster{
ObjectMeta: metav1.ObjectMeta{
Namespace: v1.NamespaceDefault,
Name: "tc",
},
Spec: v1alpha1.TidbClusterSpec{
PD: &v1alpha1.PDSpec{
ResourceRequirements: v1.ResourceRequirements{
Requests: v1.ResourceList{
v1.ResourceStorage: resource.MustParse("1Gi"),
},
},
},
},
},
sc: newStorageClass("sc", false),
pvcs: []*v1.PersistentVolumeClaim{
newPVCWithStorage("pd-0", label.PDLabelVal, "sc", "2Gi"),
},
wantPVCs: []*v1.PersistentVolumeClaim{
newPVCWithStorage("pd-0", label.PDLabelVal, "sc", "2Gi"),
},
wantErr: nil,
},
}

for _, tt := range tests {
Expand Down

0 comments on commit 2deccfc

Please sign in to comment.