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

rbd: add additional space for encrypted volumes #4582

Open
wants to merge 2 commits into
base: devel
Choose a base branch
from

Conversation

iPraveenParihar
Copy link
Contributor

Describe what this PR does

rbd: add additional space for encrypted volumes

issue: when a block-mode pvc is created with encryption enabled
there is some space reserved for the encryption metadata.
Which doesn't allows users to write extact amount of data that
they have requested for.

solution: create pvc with extra space needed for the encryption
metadata. GetLuksHeaderSize() function returns the luks2
encryption metadata(header size).

Related issues

Fixes: #issue_number

Checklist:

  • Commit Message Formatting: Commit titles and messages follow guidelines in the developer guide.
  • Reviewed the developer guide on Submitting a Pull Request
  • Pending release notes updated with breaking and/or notable changes for the next major release.
  • Documentation has been updated, if necessary.
  • Unit tests have been added, if necessary.
  • Integration tests have been added, if necessary.

Show available bot commands

These commands are normally not required, but in case of issues, leave any of
the following bot commands in an otherwise empty comment in this PR:

  • /retest ci/centos/<job-name>: retest the <job-name> after unrelated
    failure (please report the failure too!)

@iPraveenParihar
Copy link
Contributor Author

minikube testing,

Created a 1GiB block-mode pvc, and then expanded to 2GiB

[pm@dhcp53-176 ceph-csi]$ k get pvc
NAME            STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
raw-block-pvc   Bound    pvc-5d6e808b-5f9c-474b-94a7-ce0f20725048   1Gi        RWO            rbd-sc         7m33s
[pm@dhcp53-176 ceph-csi]$ k exec rook-direct-mount-6b8f99f786-q5qfm -- rbd info replicapool/csi-vol-7c440f1f-35f0-4708-84b5-1d4055c0cc32 --format json | jq
{
  "name": "csi-vol-6feb9874-b24d-4bb7-9b4b-f51732e79708",
  "id": "bceddf10f522a",
  "size": 1090519040,   // --> 1GiB + 16MiB
  "objects": 260,
  "order": 22,
  "object_size": 4194304,
  "snapshot_count": 0,
  "block_name_prefix": "rbd_data.bceddf10f522a",
  "format": 2,
  "features": [
    "layering"
  ],
  "op_features": [],
  "flags": [],
  "create_timestamp": "Wed Apr 24 07:01:43 2024",
  "access_timestamp": "Wed Apr 24 07:01:43 2024",
  "modify_timestamp": "Wed Apr 24 07:01:43 2024"
}



[pm@dhcp53-176 examples]$ k get pvc
NAME            STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
raw-block-pvc   Bound    pvc-5d6e808b-5f9c-474b-94a7-ce0f20725048   2Gi        RWO            rbd-sc         15m
[pm@dhcp53-176 examples]$ k exec rook-direct-mount-6b8f99f786-q5qfm -- rbd info replicapool/csi-vol-7c440f1f-35f0-4708-84b5-1d4055c0cc32 --format json | jq
{
  "name": "csi-vol-7c440f1f-35f0-4708-84b5-1d4055c0cc32",
  "id": "bcedd5fa1dd89",
  "size": 2164260864,   // --> 2GiB + 16MiB
  "objects": 516,
  "order": 22,
  "object_size": 4194304,
  "snapshot_count": 0,
  "block_name_prefix": "rbd_data.bcedd5fa1dd89",
  "format": 2,
  "features": [
    "layering"
  ],
  "op_features": [],
  "flags": [],
  "create_timestamp": "Wed Apr 24 07:23:07 2024",
  "access_timestamp": "Wed Apr 24 07:23:07 2024",
  "modify_timestamp": "Wed Apr 24 07:23:07 2024"
}

Copy link
Collaborator

@Madhu-1 Madhu-1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add E2E checks new size.

@mergify mergify bot added the component/rbd Issues related to RBD label Apr 24, 2024
@iPraveenParihar
Copy link
Contributor Author

/test ci/centos/mini-e2e-helm/k8s-1.28

@iPraveenParihar
Copy link
Contributor Author

/test ci/centos/mini-e2e-helm/k8s-1.28

@iPraveenParihar iPraveenParihar force-pushed the rbd/configure-encrpted-vol-size branch 4 times, most recently from 29e4f91 to 4f0f3fc Compare April 25, 2024 11:12
@iPraveenParihar
Copy link
Contributor Author

/test ci/centos/mini-e2e-helm/k8s-1.28

@nixpanic
Copy link
Member

@Mergifyio rebase

This causes a run of the GitHub CI jobs. Logs for ci/centos/mini-e2e-helm/k8s-1.28 show that e2e passed earlier.

@nixpanic nixpanic force-pushed the rbd/configure-encrpted-vol-size branch from 4f0f3fc to 69aeda7 Compare April 25, 2024 15:41
Copy link
Contributor

mergify bot commented Apr 25, 2024

rebase

✅ Branch has been successfully rebased

@iPraveenParihar iPraveenParihar force-pushed the rbd/configure-encrpted-vol-size branch 2 times, most recently from 227bcf0 to a4eabb3 Compare April 29, 2024 06:38
@iPraveenParihar
Copy link
Contributor Author

/test ci/centos/mini-e2e/k8s-1.28

@iPraveenParihar iPraveenParihar force-pushed the rbd/configure-encrpted-vol-size branch 5 times, most recently from 7b79d41 to ca95618 Compare April 29, 2024 16:54
@iPraveenParihar
Copy link
Contributor Author

/test ci/centos/mini-e2e/k8s-1.29/test_type-rbd

@iPraveenParihar
Copy link
Contributor Author

/test ci/centos/mini-e2e/k8s-1.29

@iPraveenParihar
Copy link
Contributor Author

/test ci/centos/mini-e2e/k8s-1.29/test_type-rbd

@karthik-us, is this the correct command to run rbd tests?
its not working for me with above command.

@iPraveenParihar
Copy link
Contributor Author

/test ci/centos/mini-e2e/k8s-1.29

@iPraveenParihar iPraveenParihar force-pushed the rbd/configure-encrpted-vol-size branch from ca95618 to 72252c7 Compare May 2, 2024 04:56
@iPraveenParihar
Copy link
Contributor Author

/test ci/centos/mini-e2e/k8s-1.29

@iPraveenParihar iPraveenParihar force-pushed the rbd/configure-encrpted-vol-size branch from 72252c7 to 9d52790 Compare May 6, 2024 06:01
@iPraveenParihar
Copy link
Contributor Author

/test ci/centos/mini-e2e/k8s-1.29

@iPraveenParihar iPraveenParihar marked this pull request as ready for review May 6, 2024 07:16
@iPraveenParihar
Copy link
Contributor Author

/test ci/centos/mini-e2e/k8s-1.29

e2e/rbd.go Outdated

//nolint:goconst // The string "1Gi" is used multiple times in rbd.go, so it's not a const value.
pvcSize := "1Gi"
imageSize := 1*helpers.GiB + util.GetLuksHeaderSize()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check if helper is having any menthods to parse string and convert it to in that avoid bugs or else we need to remember that we need to change size in two places.

e2e/rbd.go Outdated
}
})

By("resize a encrypted block pvc and verify the image size", func() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add the resize to above test case, lets not create the PVC and pod again

}

if imgInfo.Size != imageSize {
return fmt.Errorf("size %d does not match expected %d", imgInfo.Size, imageSize)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return pvc name /image name which helps in debugging

luks2KeySlotsSize = 32 << 8 // 8192 KiB
)

func GetLuksHeaderSize() int64 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return uint64 from here, we dont need to convert int64 to uint64 in multiple places

@Madhu-1 Madhu-1 requested review from a team May 6, 2024 12:13
@iPraveenParihar iPraveenParihar force-pushed the rbd/configure-encrpted-vol-size branch from 9d52790 to b8c9e50 Compare May 6, 2024 14:53
@iPraveenParihar
Copy link
Contributor Author

/test ci/centos/mini-e2e/k8s-1.29

e2e/rbd.go Outdated
resizeImageSize uint64
)
pvcSize := "1Gi"
if s, err := helpers.RoundUpToB(resource.MustParse(pvcSize)); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should be err==nil not the other way isn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😀yea, missed it
Thanks!

Comment on lines +36 to +40
func GetLuksHeaderSize() uint64 {
size := uint64((((2 * luks2MetadataSize) + luks2KeySlotsSize) * helpers.KiB))

return size
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add unit testing for this helper?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add unit test for it.

issue: when a block-mode pvc is created with encryption enabled
there is some space reserved for the encryption metadata.
Which doesn't allows users to write extact amount of data that
they have requested for.

solution: create pvc with extra space needed for the encryption
metadata. `GetLuksHeaderSize()` function returns the luks2
encryption metadata(header size).

Signed-off-by: Praveen M <m.praveen@ibm.com>
@iPraveenParihar iPraveenParihar force-pushed the rbd/configure-encrpted-vol-size branch 2 times, most recently from 5479252 to 624153c Compare May 6, 2024 18:42
Signed-off-by: Praveen M <m.praveen@ibm.com>
@iPraveenParihar iPraveenParihar force-pushed the rbd/configure-encrpted-vol-size branch from 624153c to d756a9d Compare May 7, 2024 04:46
@iPraveenParihar
Copy link
Contributor Author

/test ci/centos/mini-e2e/k8s-1.29

@@ -1984,6 +1986,115 @@ var _ = Describe("RBD", func() {
}
})

By("create a encrypted block pvc and verify the image size", func() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check snapshot process and size of created snapshot too in the same flow since we had a problem with restore?

if err != nil {
framework.Failf("failed to load application: %v", err)
}
app.Labels = map[string]string{"app": "rbd-pod-block-encrypted"}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

labelKey:="app"
labelVal:= "rbd-pod-block-encrypted"
app.Labels = map[string]string{labelKey:labelVal}

opt := metav1.ListOptions{
	LabelSelector: fmt.Sprintf("%s=%s",labelKey,labelVal)
}

using like above is less error prone, if we check it in one place we don't need to change it in other place

Comment on lines +2084 to +2087
err = deletePVCAndApp("", f, pvc, app)
if err != nil {
framework.Failf("failed to delete pvc and app: %v", err)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add E2E for PVC-PVC clone and snapshot restore as well

@@ -1067,6 +1067,7 @@ type imageInfo struct {
StripeUnit int `json:"stripe_unit"`
StripeCount int `json:"stripe_count"`
ObjectSize int `json:"object_size"`
Size int64 `json:"size"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use uint64 here?

Comment on lines +36 to +40
func GetLuksHeaderSize() uint64 {
size := uint64((((2 * luks2MetadataSize) + luks2KeySlotsSize) * helpers.KiB))

return size
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add unit test for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/rbd Issues related to RBD
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants