-
Notifications
You must be signed in to change notification settings - Fork 89
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
Added support for additionalVolumes in VPCMachines #2275
Conversation
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 Once the patch is verified, the new status will be reflected by the 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. |
✅ Deploy Preview for kubernetes-sigs-cluster-api-ibmcloud ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
/ok-to-test |
bbb9c56
to
1f3ceed
Compare
1f3ceed
to
b58a096
Compare
cloud/scope/machine.go
Outdated
} | ||
result, _, err := m.IBMVPCClient.GetVolumeAttachments(&options) | ||
if err != nil { | ||
return nil, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
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, | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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!
cloud/scope/machine.go
Outdated
|
||
volumeResult, _, err := m.IBMVPCClient.CreateVolume(&volumeOptions) | ||
if err != nil { | ||
return err |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
cloud/scope/machine_test.go
Outdated
|
||
dummyVolumeAttachments := vpcv1.VolumeAttachmentCollection{ | ||
VolumeAttachments: []vpcv1.VolumeAttachment{{ | ||
Name: new(string), |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored the name
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
cloud/scope/machine_test.go
Outdated
ID: &volumeID, | ||
} | ||
|
||
volumeCreationError := errors.New("Error while creating volume") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
volumeCreationError := errors.New("Error while creating volume") | |
volumeCreationError := errors.New("error while creating volume") |
Lets not capitalize the errors
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
6d1fb3b
to
b55955a
Compare
api/v1beta2/ibmvpcmachine_types.go
Outdated
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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, | ||
} | ||
} |
There was a problem hiding this comment.
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!
cloud/scope/machine_test.go
Outdated
|
||
dummyVolumeAttachments := vpcv1.VolumeAttachmentCollection{ | ||
VolumeAttachments: []vpcv1.VolumeAttachment{{ | ||
Name: new(string), |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets wrap the error.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
b55955a
to
75e4915
Compare
There was a problem hiding this 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: |
There was a problem hiding this comment.
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
cluster-api-provider-ibmcloud/Makefile
Line 189 in 982d67e
generate-e2e-templates: $(KUSTOMIZE) ## Generate E2E cluster templates |
Are we planning to test provisioning additional volumes by default in e2e cluster creation?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
334f1b7
to
86d7fab
Compare
if len(machineVolumes) == 0 { | ||
return nil | ||
} | ||
createdVolumeList, err := machineScope.GetVolumeAttachments() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
createdVolumeList, err := machineScope.GetVolumeAttachments() | |
volumeAttachmentList, err := machineScope.GetVolumeAttachments() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update accordingly.
There was a problem hiding this comment.
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]() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
createdVolumeNames := sets.New[string]() | |
volumeAttachmentNames := sets.New[string]() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update accordingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
5e9cca6
to
e97e31a
Compare
There was a problem hiding this 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?
cloud/scope/machine.go
Outdated
@@ -1155,3 +1155,63 @@ func (m *MachineScope) APIServerPort() int32 { | |||
} | |||
return infrav1beta2.DefaultAPIServerPort | |||
} | |||
|
|||
// GetVolumeAttachments returns the volumeattachments for the instance. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// GetVolumeAttachments returns the volumeattachments for the instance. | |
// GetVolumeAttachments returns the volume attachments for the instance. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
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. |
98a84a5
to
b5d1f7f
Compare
I was wondering if UT could be added for reconcileAdditionalVolumes? |
@anshuman-agarwala, did you get a chance to look into this? |
b5d1f7f
to
dcb4bae
Compare
Added UTs for reconcileAdditionalVolumes, |
Thanks @anshuman-agarwala! /lgtm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
[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 |
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
Release note: