Skip to content

Commit

Permalink
Merge pull request #9391 from y1r/add-context-k8sutil-pvc
Browse files Browse the repository at this point in the history
core: add context parameter to k8sutil pvc
  • Loading branch information
leseb committed Dec 13, 2021
2 parents 9d345ca + 5352cf5 commit 97b41ea
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pkg/operator/ceph/cluster/mon/mon.go
Expand Up @@ -1161,7 +1161,7 @@ func (c *Cluster) updateMon(m *monConfig, d *apps.Deployment) error {
if err != nil {
return errors.Wrapf(err, "failed to fetch pvc for mon %q", m.ResourceName)
}
k8sutil.ExpandPVCIfRequired(c.context.Client, desiredPvc, existingPvc)
k8sutil.ExpandPVCIfRequired(c.ClusterInfo.Context, c.context.Client, desiredPvc, existingPvc)
}

logger.Infof("deployment for mon %s already exists. updating if needed",
Expand Down
2 changes: 1 addition & 1 deletion pkg/operator/ceph/cluster/osd/deviceSet.go
Expand Up @@ -209,7 +209,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
k8sutil.ExpandPVCIfRequired(c.context.Client, pvc, existingPVC)
k8sutil.ExpandPVCIfRequired(c.clusterInfo.Context, c.context.Client, pvc, existingPVC)
return existingPVC, nil
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/operator/k8sutil/pvc.go
Expand Up @@ -26,7 +26,7 @@ import (
)

// ExpandPVCIfRequired will expand the PVC if requested size is greater than the actual size of existing PVC
func ExpandPVCIfRequired(client client.Client, desiredPVC *v1.PersistentVolumeClaim, currentPVC *v1.PersistentVolumeClaim) {
func ExpandPVCIfRequired(ctx context.Context, client client.Client, desiredPVC *v1.PersistentVolumeClaim, currentPVC *v1.PersistentVolumeClaim) {
desiredSize, desiredOK := desiredPVC.Spec.Resources.Requests[v1.ResourceStorage]
currentSize, currentOK := currentPVC.Spec.Resources.Requests[v1.ResourceStorage]
if !desiredOK || !currentOK {
Expand All @@ -43,7 +43,7 @@ func ExpandPVCIfRequired(client client.Client, desiredPVC *v1.PersistentVolumeCl

// get StorageClass
storageClass := &storagev1.StorageClass{}
err := client.Get(context.TODO(), types.NamespacedName{Name: *(currentPVC.Spec.StorageClassName)}, storageClass)
err := client.Get(ctx, types.NamespacedName{Name: *(currentPVC.Spec.StorageClassName)}, storageClass)
if err != nil {
logger.Errorf("failed to get storageClass %q. %v", *(currentPVC.Spec.StorageClassName), err)
return
Expand All @@ -56,7 +56,7 @@ func ExpandPVCIfRequired(client client.Client, desiredPVC *v1.PersistentVolumeCl

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 = client.Update(context.TODO(), currentPVC); err != nil {
if err = client.Update(ctx, currentPVC); err != nil {
// log the error, but don't fail the reconcile
logger.Errorf("failed to update PVC size. %v", err)
return
Expand Down
2 changes: 1 addition & 1 deletion pkg/operator/k8sutil/pvc_test.go
Expand Up @@ -108,7 +108,7 @@ func TestExpandPVCIfRequired(t *testing.T) {

desiredPVC.Spec.Resources.Requests[v1.ResourceStorage] = apiresource.MustParse(tc.desiredPVCSize)

ExpandPVCIfRequired(cl, desiredPVC, existingPVC)
ExpandPVCIfRequired(context.TODO(), cl, desiredPVC, existingPVC)

// get existing PVC
err = cl.Get(context.TODO(), client.ObjectKey{Name: "test", Namespace: "rook-ceph"}, existingPVC)
Expand Down

0 comments on commit 97b41ea

Please sign in to comment.