Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: add context parameter to k8sutil pvc #9391

Merged
merged 1 commit into from Dec 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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