forked from rook/rook
ceph: stop using updatePVCIfChanged and start using ExpandPVCIfRequired
delete updatePVCIfChanged method on "Cluster" from osd package and use the common one ExpandPVCIfRequired from k8sutil pkg Signed-off-by: Nitin Goyal <nigoyal@redhat.com>
This commit is contained in:
@@ -27,6 +27,7 @@ import (
|
||||
rookv1 "github.com/rook/rook/pkg/apis/rook.io/v1"
|
||||
"github.com/rook/rook/pkg/clusterd"
|
||||
"github.com/rook/rook/pkg/operator/ceph/controller"
|
||||
"github.com/rook/rook/pkg/operator/k8sutil"
|
||||
"github.com/rook/rook/pkg/util"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
@@ -175,7 +176,7 @@ func (c *Cluster) createDeviceSetPVC(existingPVCs map[string]*v1.PersistentVolum
|
||||
logger.Infof("OSD PVC %q already exists", existingPVC.Name)
|
||||
|
||||
// Update the PVC in case the size changed
|
||||
c.updatePVCIfChanged(pvc, existingPVC)
|
||||
k8sutil.ExpandPVCIfRequired(c.context.Client, pvc, existingPVC)
|
||||
return existingPVC, nil
|
||||
}
|
||||
|
||||
@@ -189,28 +190,6 @@ func (c *Cluster) createDeviceSetPVC(existingPVCs map[string]*v1.PersistentVolum
|
||||
return deployedPVC, nil
|
||||
}
|
||||
|
||||
func (c *Cluster) updatePVCIfChanged(desiredPVC *v1.PersistentVolumeClaim, currentPVC *v1.PersistentVolumeClaim) {
|
||||
ctx := context.TODO()
|
||||
desiredSize, desiredOK := desiredPVC.Spec.Resources.Requests[v1.ResourceStorage]
|
||||
currentSize, currentOK := currentPVC.Spec.Resources.Requests[v1.ResourceStorage]
|
||||
if !desiredOK || !currentOK {
|
||||
logger.Debugf("desired or current size are not specified for PVC %q", currentPVC.Name)
|
||||
return
|
||||
}
|
||||
if desiredSize.Value() > currentSize.Value() {
|
||||
currentPVC.Spec.Resources.Requests[v1.ResourceStorage] = desiredSize
|
||||
logger.Infof("updating PVC %q size from %s to %s", currentPVC.Name, currentSize.String(), desiredSize.String())
|
||||
if _, err := c.context.Clientset.CoreV1().PersistentVolumeClaims(c.clusterInfo.Namespace).Update(ctx, currentPVC, metav1.UpdateOptions{}); err != nil {
|
||||
// log the error, but don't fail the reconcile
|
||||
logger.Errorf("failed to update PVC size. %v", err)
|
||||
return
|
||||
}
|
||||
logger.Infof("successfully updated PVC %q size", currentPVC.Name)
|
||||
} else if desiredSize.Value() < currentSize.Value() {
|
||||
logger.Warningf("ignoring request to shrink osd PVC %q size from %s to %s, only expansion is allowed", currentPVC.Name, currentSize.String(), desiredSize.String())
|
||||
}
|
||||
}
|
||||
|
||||
func makeDeviceSetPVC(deviceSetName, pvcID string, setIndex int, pvcTemplate v1.PersistentVolumeClaim, namespace string) *v1.PersistentVolumeClaim {
|
||||
pvcLabels := makeStorageClassDeviceSetPVCLabel(deviceSetName, pvcID, setIndex)
|
||||
|
||||
|
||||
@@ -27,7 +27,6 @@ import (
|
||||
testexec "github.com/rook/rook/pkg/operator/test"
|
||||
"github.com/stretchr/testify/assert"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
@@ -234,42 +233,6 @@ func testVolumeClaim(name string) corev1.PersistentVolumeClaim {
|
||||
return claim
|
||||
}
|
||||
|
||||
func TestUpdatePVCSize(t *testing.T) {
|
||||
clientset := testexec.New(t, 1)
|
||||
context := &clusterd.Context{
|
||||
Clientset: clientset,
|
||||
}
|
||||
cluster := &Cluster{
|
||||
context: context,
|
||||
clusterInfo: client.AdminClusterInfo("testns"),
|
||||
}
|
||||
current := &corev1.PersistentVolumeClaim{}
|
||||
desired := &corev1.PersistentVolumeClaim{}
|
||||
current.Spec.Resources.Requests = corev1.ResourceList{}
|
||||
desired.Spec.Resources.Requests = corev1.ResourceList{}
|
||||
current.Spec.Resources.Requests[corev1.ResourceStorage] = resource.MustParse("5Gi")
|
||||
|
||||
// Nothing happens if no size is set on the new PVC
|
||||
cluster.updatePVCIfChanged(desired, current)
|
||||
result, ok := current.Spec.Resources.Requests[corev1.ResourceStorage]
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, "5Gi", result.String())
|
||||
|
||||
// Nothing happens if the size shrinks
|
||||
desired.Spec.Resources.Requests[corev1.ResourceStorage] = resource.MustParse("4Gi")
|
||||
cluster.updatePVCIfChanged(desired, current)
|
||||
result, ok = current.Spec.Resources.Requests[corev1.ResourceStorage]
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, "5Gi", result.String())
|
||||
|
||||
// The size is updated when it increases
|
||||
desired.Spec.Resources.Requests[corev1.ResourceStorage] = resource.MustParse("6Gi")
|
||||
cluster.updatePVCIfChanged(desired, current)
|
||||
result, ok = current.Spec.Resources.Requests[corev1.ResourceStorage]
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, "6Gi", result.String())
|
||||
}
|
||||
|
||||
func TestPrepareDeviceSetsWithCrushParams(t *testing.T) {
|
||||
ctx := context.TODO()
|
||||
clientset := testexec.New(t, 1)
|
||||
|
||||
Reference in New Issue
Block a user