Skip to content

Added support for additionalVolumes in VPCMachines #2275

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

Merged

Conversation

anshuman-agarwala
Copy link
Contributor

What this PR does / why we need it:
Adds AdditionalVolume support for VPC Machines

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #1920

Special notes for your reviewer:

/area provider/ibmcloud

  1. Please confirm that if this PR changes any image versions, then that's the sole change this PR makes.

Release note:

Added AdditionalVolume support for VPC Machines

@k8s-ci-robot k8s-ci-robot added area/provider/ibmcloud Issues or PRs related to ibmcloud provider cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Mar 27, 2025
@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Mar 27, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @anshuman-agarwala. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Mar 27, 2025
Copy link

netlify bot commented Mar 27, 2025

Deploy Preview for kubernetes-sigs-cluster-api-ibmcloud ready!

Name Link
🔨 Latest commit dcb4bae
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-sigs-cluster-api-ibmcloud/deploys/6807194f40394c0008a57a6c
😎 Deploy Preview https://deploy-preview-2275.cluster-api-ibmcloud.sigs.k8s.io
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@mkumatag
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Mar 27, 2025
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 8, 2025
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 8, 2025
@Prajyot-Parab
Copy link
Contributor

/cc @Karthik-K-N @Amulyam24

}
result, _, err := m.IBMVPCClient.GetVolumeAttachments(&options)
if err != nil {
return nil, err
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return nil, err
return nil, fmt.Errorf("error getting volume attachements: %w, err)

In general wrap and return any child errors. Log error only if we are not returning error back.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines +1173 to +1196
volumeOptions := vpcv1.CreateVolumeOptions{}
// TODO: EncryptionKeyCRN is not supported for now, the field is omitted from the manifest
if vpcVolume.Profile != "custom" {
volumeOptions.VolumePrototype = &vpcv1.VolumePrototype{
Profile: &vpcv1.VolumeProfileIdentityByName{
Name: &vpcVolume.Profile,
},
Zone: &vpcv1.ZoneIdentity{
Name: &m.IBMVPCMachine.Spec.Zone,
},
Capacity: &vpcVolume.SizeGiB,
}
} else {
volumeOptions.VolumePrototype = &vpcv1.VolumePrototype{
Iops: &vpcVolume.Iops,
Profile: &vpcv1.VolumeProfileIdentityByName{
Name: &vpcVolume.Profile,
},
Zone: &vpcv1.ZoneIdentity{
Name: &m.IBMVPCMachine.Spec.Zone,
},
Capacity: &vpcVolume.SizeGiB,
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
volumeOptions := vpcv1.CreateVolumeOptions{}
// TODO: EncryptionKeyCRN is not supported for now, the field is omitted from the manifest
if vpcVolume.Profile != "custom" {
volumeOptions.VolumePrototype = &vpcv1.VolumePrototype{
Profile: &vpcv1.VolumeProfileIdentityByName{
Name: &vpcVolume.Profile,
},
Zone: &vpcv1.ZoneIdentity{
Name: &m.IBMVPCMachine.Spec.Zone,
},
Capacity: &vpcVolume.SizeGiB,
}
} else {
volumeOptions.VolumePrototype = &vpcv1.VolumePrototype{
Iops: &vpcVolume.Iops,
Profile: &vpcv1.VolumeProfileIdentityByName{
Name: &vpcVolume.Profile,
},
Zone: &vpcv1.ZoneIdentity{
Name: &m.IBMVPCMachine.Spec.Zone,
},
Capacity: &vpcVolume.SizeGiB,
}
}
volumeOptions := vpcv1.CreateVolumeOptions{
VolumePrototype: vpcv1.VolumePrototype{
Profile: &vpcv1.VolumeProfileIdentityByName{
Name: &vpcVolume.Profile,
},
Zone: &vpcv1.ZoneIdentity{
Name: &m.IBMVPCMachine.Spec.Zone,
},
Capacity: &vpcVolume.SizeGiB,
},
}
if vpcVolume.Profile == "custom" {
volumeOptions.VolumePrototype.Iops = &vpcVolume.Iops,
}

will this work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried that initially, was getting this error: volumeOptions.VolumePrototype.Iops undefined (type vpcv1.VolumePrototypeIntf has no field or method Iops)

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure whats missing then!


volumeResult, _, err := m.IBMVPCClient.CreateVolume(&volumeOptions)
if err != nil {
return err
Copy link
Contributor

Choose a reason for hiding this comment

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

lets wrap the error and return here and everywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

attachmentOptions := vpcv1.CreateInstanceVolumeAttachmentOptions{
InstanceID: &m.IBMVPCMachine.Status.InstanceID,
Volume: &vpcv1.VolumeAttachmentPrototypeVolume{
ID: volumeResult.ID,
Copy link
Contributor

Choose a reason for hiding this comment

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

is it sure that err and volumeResult wont be nil at the same time?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, according to the API docs: https://cloud.ibm.com/apidocs/vpc/latest#create-volume volume id will always be returned.


dummyVolumeAttachments := vpcv1.VolumeAttachmentCollection{
VolumeAttachments: []vpcv1.VolumeAttachment{{
Name: new(string),
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can use some good name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactored the name

Copy link
Contributor

Choose a reason for hiding this comment

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

Still I see this

Name: new(string),

Did I miss anything?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I think I misunderstood what you meant the first time, fixed it now.

ID: &volumeID,
}

volumeCreationError := errors.New("Error while creating volume")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
volumeCreationError := errors.New("Error while creating volume")
volumeCreationError := errors.New("error while creating volume")

Lets not capitalize the errors

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

// Handle Additional Volumes
err = r.reconcileAdditionalVolumes(machineScope)
if err != nil {
return ctrl.Result{}, err
Copy link
Contributor

Choose a reason for hiding this comment

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

lets wrap and return error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@anshuman-agarwala anshuman-agarwala force-pushed the additional-disk branch 2 times, most recently from 6d1fb3b to b55955a Compare April 8, 2025 17:26
@@ -78,6 +78,14 @@ type IBMVPCMachineSpec struct {
// SSHKeys is the SSH pub keys that will be used to access VM.
// ID will take higher precedence over Name if both specified.
SSHKeys []*IBMVPCResourceReference `json:"sshKeys,omitempty"`

// AdditionalVolumes is the list of additional volumes attached to the instance
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// AdditionalVolumes is the list of additional volumes attached to the instance
// additionalVolumes is the list of additional volumes attached to the instance

We are supposed to use the user facing name in comment so user will find it easy when we use go doc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

if err != nil {
return nil, fmt.Errorf("error while getting volume attachments: %w", err)
}
return result.VolumeAttachments, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it sure that result wont be nil?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it will return an empty slice if there are no attachments.

Comment on lines +1173 to +1196
volumeOptions := vpcv1.CreateVolumeOptions{}
// TODO: EncryptionKeyCRN is not supported for now, the field is omitted from the manifest
if vpcVolume.Profile != "custom" {
volumeOptions.VolumePrototype = &vpcv1.VolumePrototype{
Profile: &vpcv1.VolumeProfileIdentityByName{
Name: &vpcVolume.Profile,
},
Zone: &vpcv1.ZoneIdentity{
Name: &m.IBMVPCMachine.Spec.Zone,
},
Capacity: &vpcVolume.SizeGiB,
}
} else {
volumeOptions.VolumePrototype = &vpcv1.VolumePrototype{
Iops: &vpcVolume.Iops,
Profile: &vpcv1.VolumeProfileIdentityByName{
Name: &vpcVolume.Profile,
},
Zone: &vpcv1.ZoneIdentity{
Name: &m.IBMVPCMachine.Spec.Zone,
},
Capacity: &vpcVolume.SizeGiB,
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure whats missing then!


dummyVolumeAttachments := vpcv1.VolumeAttachmentCollection{
VolumeAttachments: []vpcv1.VolumeAttachment{{
Name: new(string),
Copy link
Contributor

Choose a reason for hiding this comment

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

Still I see this

Name: new(string),

Did I miss anything?

}
createdVolumeList, err := machineScope.GetVolumeAttachments()
if err != nil {
return err
Copy link
Contributor

Choose a reason for hiding this comment

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

Lets wrap the error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The error is already wrapped when it's getting returned from GetVolumeAttachments, shall I wrap it again here?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that would be better to understand the flow and follow the pattern

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's already following the pattern, we're returning error directly in other places in the code when the error is already wrapped by the called method.

Copy link
Contributor

@Karthik-K-N Karthik-K-N left a comment

Choose a reason for hiding this comment

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

LGTM

@Prajyot-Parab Please take look.

@@ -402,6 +402,14 @@ spec:
spec:
bootVolume:
sizeGiB: ${IBMVPC_WORKER_BOOT_VOLUME_SIZEGIB:=20}
additionalVolumes:
Copy link
Contributor

@Amulyam24 Amulyam24 Apr 10, 2025

Choose a reason for hiding this comment

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

This template is generated via generate-e2e-templates target

generate-e2e-templates: $(KUSTOMIZE) ## Generate E2E cluster templates
and will get overriden if changes are made here.

Are we planning to test provisioning additional volumes by default in e2e cluster creation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added it because I thought it would help validate my changes. If adding it to the default e2e test is not needed then shall I remove this?

Copy link
Contributor

Choose a reason for hiding this comment

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

@anshuman-agarwala you have validated the changes already right? also we can add it to default, but it has to be in sync with generate-e2e-templates target so that it wont get overriden as @Amulyam24 said.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes have validated the changes manually.
I've added the the additional volumes to the template.

Copy link
Contributor

Choose a reason for hiding this comment

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

@anshuman-agarwala, the changes should not directly be made to the template as they are generated via generate-templates. Please check the templates dir and add wherever applicable in either cluster-template or bases/vpc dir.

Copy link
Contributor

Choose a reason for hiding this comment

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

You need to update in appropriate places as @Amulyam24 said then run make generate and make generate-e2e-templates targets to get updated templates and add them to this PR.

@anshuman-agarwala anshuman-agarwala force-pushed the additional-disk branch 3 times, most recently from 334f1b7 to 86d7fab Compare April 10, 2025 07:01
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 10, 2025
if len(machineVolumes) == 0 {
return nil
}
createdVolumeList, err := machineScope.GetVolumeAttachments()
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
createdVolumeList, err := machineScope.GetVolumeAttachments()
volumeAttachmentList, err := machineScope.GetVolumeAttachments()

Copy link
Contributor

Choose a reason for hiding this comment

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

update accordingly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

if err != nil {
return err
}
createdVolumeNames := sets.New[string]()
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
createdVolumeNames := sets.New[string]()
volumeAttachmentNames := sets.New[string]()

Copy link
Contributor

Choose a reason for hiding this comment

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

update accordingly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@anshuman-agarwala anshuman-agarwala force-pushed the additional-disk branch 2 times, most recently from 5e9cca6 to e97e31a Compare April 10, 2025 08:58
Copy link
Contributor

@Amulyam24 Amulyam24 left a comment

Choose a reason for hiding this comment

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

@anshuman-agarwala, do you plan to add UT for controller?

@@ -1155,3 +1155,63 @@ func (m *MachineScope) APIServerPort() int32 {
}
return infrav1beta2.DefaultAPIServerPort
}

// GetVolumeAttachments returns the volumeattachments for the instance.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// GetVolumeAttachments returns the volumeattachments for the instance.
// GetVolumeAttachments returns the volume attachments for the instance.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@anshuman-agarwala
Copy link
Contributor Author

@anshuman-agarwala, do you plan to add UT for controller?

Yes, I missed those, thanks for the catch!

@anshuman-agarwala
Copy link
Contributor Author

@anshuman-agarwala, do you plan to add UT for controller?

Yes, I missed those, thanks for the catch!

Looking at the existing UTs, I don't think there's anything I can add to the controller UT for my changes.

@anshuman-agarwala anshuman-agarwala force-pushed the additional-disk branch 2 times, most recently from 98a84a5 to b5d1f7f Compare April 11, 2025 12:50
@Amulyam24
Copy link
Contributor

@anshuman-agarwala, do you plan to add UT for controller?

Yes, I missed those, thanks for the catch!

Looking at the existing UTs, I don't think there's anything I can add to the controller UT for my changes.

I was wondering if UT could be added for reconcileAdditionalVolumes?

@Amulyam24
Copy link
Contributor

I was wondering if UT could be added for reconcileAdditionalVolumes?

@anshuman-agarwala, did you get a chance to look into this?

@anshuman-agarwala
Copy link
Contributor Author

I was wondering if UT could be added for reconcileAdditionalVolumes?

@anshuman-agarwala, did you get a chance to look into this?

Added UTs for reconcileAdditionalVolumes,
Sorry about the delay!

@Amulyam24
Copy link
Contributor

Thanks @anshuman-agarwala!

/lgtm

cc @Prajyot-Parab

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 22, 2025
Copy link
Contributor

@Prajyot-Parab Prajyot-Parab left a comment

Choose a reason for hiding this comment

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

/lgtm

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: anshuman-agarwala, Prajyot-Parab

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 22, 2025
@k8s-ci-robot k8s-ci-robot merged commit ae6fd3f into kubernetes-sigs:main Apr 22, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/provider/ibmcloud Issues or PRs related to ibmcloud provider cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide a way to attach additional disks to node.
6 participants