-
Notifications
You must be signed in to change notification settings - Fork 30
volume wait interval through settings #872
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -21,6 +21,10 @@ type VjailbreakSettings struct { | |||||||||
| VMActiveWaitIntervalSeconds int | ||||||||||
| // VMActiveWaitRetryLimit is the number of retries to wait for VM to become active | ||||||||||
| VMActiveWaitRetryLimit int | ||||||||||
| // VolumeAvailableWaitIntervalSeconds is the interval to wait for volume to become available | ||||||||||
| VolumeAvailableWaitIntervalSeconds int | ||||||||||
| // VolumeAvailableWaitRetryLimit is the number of retries to wait for volume to become available | ||||||||||
| VolumeAvailableWaitRetryLimit int | ||||||||||
| // DefaultMigrationMethod is the default migration method (hot/cold) | ||||||||||
| DefaultMigrationMethod string | ||||||||||
| // VCenterScanConcurrencyLimit is the max number of vms to scan at the same time | ||||||||||
|
|
@@ -63,37 +67,47 @@ func GetVjailbreakSettings(ctx context.Context, k8sClient client.Client) (*Vjail | |||||||||
| } | ||||||||||
|
|
||||||||||
| if vjailbreakSettingsCM.Data["CHANGED_BLOCKS_COPY_ITERATION_THRESHOLD"] == "" { | ||||||||||
| vjailbreakSettingsCM.Data["CHANGED_BLOCKS_COPY_ITERATION_THRESHOLD"] = "20" | ||||||||||
| vjailbreakSettingsCM.Data["CHANGED_BLOCKS_COPY_ITERATION_THRESHOLD"] = strconv.Itoa(constants.ChangedBlocksCopyIterationThreshold) | ||||||||||
| } | ||||||||||
|
|
||||||||||
| if vjailbreakSettingsCM.Data["VM_ACTIVE_WAIT_INTERVAL_SECONDS"] == "" { | ||||||||||
| vjailbreakSettingsCM.Data["VM_ACTIVE_WAIT_INTERVAL_SECONDS"] = "20" | ||||||||||
| vjailbreakSettingsCM.Data["VM_ACTIVE_WAIT_INTERVAL_SECONDS"] = strconv.Itoa(constants.VMActiveWaitIntervalSeconds) | ||||||||||
| } | ||||||||||
|
|
||||||||||
| if vjailbreakSettingsCM.Data["VM_ACTIVE_WAIT_RETRY_LIMIT"] == "" { | ||||||||||
| vjailbreakSettingsCM.Data["VM_ACTIVE_WAIT_RETRY_LIMIT"] = "15" | ||||||||||
| vjailbreakSettingsCM.Data["VM_ACTIVE_WAIT_RETRY_LIMIT"] = strconv.Itoa(constants.VolumeAvailableWaitRetryLimit) | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Incorrect constant used for VM retry limit
Incorrect constant used for Code suggestionCheck the AI-generated fix before applying
Suggested change
Code Review Run #937f11 Should Bito avoid suggestions like this for future reviews? (Manage Rules)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's an incorrect constant being used here. This should be using
Suggested change
|
||||||||||
| } | ||||||||||
|
|
||||||||||
| if vjailbreakSettingsCM.Data["VOLUME_AVAILABLE_WAIT_INTERVAL_SECONDS"] == "" { | ||||||||||
| vjailbreakSettingsCM.Data["VOLUME_AVAILABLE_WAIT_INTERVAL_SECONDS"] = strconv.Itoa(constants.VolumeAvailableWaitIntervalSeconds) | ||||||||||
| } | ||||||||||
|
|
||||||||||
| if vjailbreakSettingsCM.Data["VOLUME_AVAILABLE_WAIT_RETRY_LIMIT"] == "" { | ||||||||||
| vjailbreakSettingsCM.Data["VOLUME_AVAILABLE_WAIT_RETRY_LIMIT"] = strconv.Itoa(constants.VolumeAvailableWaitRetryLimit) | ||||||||||
| } | ||||||||||
|
|
||||||||||
| if vjailbreakSettingsCM.Data["DEFAULT_MIGRATION_METHOD"] == "" { | ||||||||||
| vjailbreakSettingsCM.Data["DEFAULT_MIGRATION_METHOD"] = "hot" | ||||||||||
| vjailbreakSettingsCM.Data["DEFAULT_MIGRATION_METHOD"] = constants.DefaultMigrationMethod | ||||||||||
| } | ||||||||||
|
|
||||||||||
| if vjailbreakSettingsCM.Data["VCENTER_SCAN_CONCURRENCY_LIMIT"] == "" { | ||||||||||
| vjailbreakSettingsCM.Data["VCENTER_SCAN_CONCURRENCY_LIMIT"] = "10" | ||||||||||
| vjailbreakSettingsCM.Data["VCENTER_SCAN_CONCURRENCY_LIMIT"] = strconv.Itoa(constants.VCenterScanConcurrencyLimit) | ||||||||||
| } | ||||||||||
|
|
||||||||||
| if vjailbreakSettingsCM.Data["CLEANUP_VOLUMES_AFTER_CONVERT_FAILURE"] == "" { | ||||||||||
| vjailbreakSettingsCM.Data["CLEANUP_VOLUMES_AFTER_CONVERT_FAILURE"] = "false" | ||||||||||
| vjailbreakSettingsCM.Data["CLEANUP_VOLUMES_AFTER_CONVERT_FAILURE"] = strconv.FormatBool(constants.CleanupVolumesAfterConvertFailure) | ||||||||||
| } | ||||||||||
|
|
||||||||||
| if vjailbreakSettingsCM.Data["POPULATE_VMWARE_MACHINE_FLAVORS"] == "" { | ||||||||||
| vjailbreakSettingsCM.Data["POPULATE_VMWARE_MACHINE_FLAVORS"] = trueString | ||||||||||
| vjailbreakSettingsCM.Data["POPULATE_VMWARE_MACHINE_FLAVORS"] = strconv.FormatBool(constants.PopulateVMwareMachineFlavors) | ||||||||||
| } | ||||||||||
|
|
||||||||||
| return &VjailbreakSettings{ | ||||||||||
| ChangedBlocksCopyIterationThreshold: atoi(vjailbreakSettingsCM.Data["CHANGED_BLOCKS_COPY_ITERATION_THRESHOLD"]), | ||||||||||
| VMActiveWaitIntervalSeconds: atoi(vjailbreakSettingsCM.Data["VM_ACTIVE_WAIT_INTERVAL_SECONDS"]), | ||||||||||
| VMActiveWaitRetryLimit: atoi(vjailbreakSettingsCM.Data["VM_ACTIVE_WAIT_RETRY_LIMIT"]), | ||||||||||
| VolumeAvailableWaitIntervalSeconds: atoi(vjailbreakSettingsCM.Data["VOLUME_AVAILABLE_WAIT_INTERVAL_SECONDS"]), | ||||||||||
| VolumeAvailableWaitRetryLimit: atoi(vjailbreakSettingsCM.Data["VOLUME_AVAILABLE_WAIT_RETRY_LIMIT"]), | ||||||||||
| DefaultMigrationMethod: vjailbreakSettingsCM.Data["DEFAULT_MIGRATION_METHOD"], | ||||||||||
| VCenterScanConcurrencyLimit: atoi(vjailbreakSettingsCM.Data["VCENTER_SCAN_CONCURRENCY_LIMIT"]), | ||||||||||
| CleanupVolumesAfterConvertFailure: vjailbreakSettingsCM.Data["CLEANUP_VOLUMES_AFTER_CONVERT_FAILURE"] == "true", | ||||||||||
|
|
@@ -104,12 +118,14 @@ func GetVjailbreakSettings(ctx context.Context, k8sClient client.Client) (*Vjail | |||||||||
| // getDefaultSettings returns default vjailbreak settings | ||||||||||
| func getDefaultSettings() *VjailbreakSettings { | ||||||||||
| return &VjailbreakSettings{ | ||||||||||
| ChangedBlocksCopyIterationThreshold: 20, | ||||||||||
| VMActiveWaitIntervalSeconds: 20, | ||||||||||
| VMActiveWaitRetryLimit: 15, | ||||||||||
| DefaultMigrationMethod: "hot", | ||||||||||
| VCenterScanConcurrencyLimit: 10, | ||||||||||
| CleanupVolumesAfterConvertFailure: false, | ||||||||||
| PopulateVMwareMachineFlavors: true, | ||||||||||
| ChangedBlocksCopyIterationThreshold: constants.ChangedBlocksCopyIterationThreshold, | ||||||||||
| VMActiveWaitIntervalSeconds: constants.VMActiveWaitIntervalSeconds, | ||||||||||
| VMActiveWaitRetryLimit: constants.VMActiveWaitRetryLimit, | ||||||||||
| VolumeAvailableWaitIntervalSeconds: constants.VolumeAvailableWaitIntervalSeconds, | ||||||||||
| VolumeAvailableWaitRetryLimit: constants.VolumeAvailableWaitRetryLimit, | ||||||||||
| DefaultMigrationMethod: constants.DefaultMigrationMethod, | ||||||||||
| VCenterScanConcurrencyLimit: constants.VCenterScanConcurrencyLimit, | ||||||||||
| CleanupVolumesAfterConvertFailure: constants.CleanupVolumesAfterConvertFailure, | ||||||||||
| PopulateVMwareMachineFlavors: constants.PopulateVMwareMachineFlavors, | ||||||||||
| } | ||||||||||
| } | ||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,7 +49,6 @@ func main() { | |
| <-ackChan | ||
| } | ||
| utils.PrintLog(msg) | ||
| return | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The removal of the |
||
|
|
||
| client, err := utils.GetInclusterClient() | ||
|
|
@@ -93,6 +92,7 @@ func main() { | |
| if err != nil { | ||
| handleError(fmt.Sprintf("Failed to validate OpenStack connection: %v", err)) | ||
| } | ||
| openstackclients.K8sClient = client | ||
| utils.PrintLog("Connected to OpenStack") | ||
|
|
||
| // Get thumbprint | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| package migrateutils | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "fmt" | ||
| "io" | ||
|
|
@@ -17,6 +18,7 @@ import ( | |
| "github.com/platform9/vjailbreak/v2v-helper/pkg/constants" | ||
| "github.com/platform9/vjailbreak/v2v-helper/pkg/utils" | ||
| "github.com/platform9/vjailbreak/v2v-helper/vm" | ||
| "sigs.k8s.io/controller-runtime/pkg/client" | ||
|
|
||
| "github.com/gophercloud/gophercloud" | ||
| "github.com/gophercloud/gophercloud/openstack" | ||
|
|
@@ -36,6 +38,7 @@ type OpenStackClients struct { | |
| BlockStorageClient *gophercloud.ServiceClient | ||
| ComputeClient *gophercloud.ServiceClient | ||
| NetworkingClient *gophercloud.ServiceClient | ||
| K8sClient client.Client | ||
| } | ||
|
|
||
| type OpenStackMetadata struct { | ||
|
|
@@ -129,7 +132,12 @@ func (osclient *OpenStackClients) DeleteVolume(volumeID string) error { | |
| } | ||
|
|
||
| func (osclient *OpenStackClients) WaitForVolume(volumeID string) error { | ||
| for i := 0; i < constants.MaxIntervalCount; i++ { | ||
| // Get vjailbreak settings | ||
| vjailbreakSettings, err := utils.GetVjailbreakSettings(context.Background(), osclient.K8sClient) | ||
| if err != nil { | ||
| return errors.Wrap(err, "failed to get vjailbreak settings") | ||
| } | ||
| for i := 0; i < vjailbreakSettings.VolumeAvailableWaitRetryLimit; i++ { | ||
| volume, err := volumes.Get(osclient.BlockStorageClient, volumeID).Extract() | ||
| if err != nil { | ||
| return fmt.Errorf("failed to get volume: %s", err) | ||
|
|
@@ -162,7 +170,7 @@ func (osclient *OpenStackClients) WaitForVolume(volumeID string) error { | |
| return nil | ||
| } | ||
| fmt.Printf("Volume %s is still attached to server retrying %d times\n", volumeID, i) | ||
| time.Sleep(5 * time.Second) // Wait for 5 seconds before checking again | ||
| time.Sleep(time.Duration(vjailbreakSettings.VolumeAvailableWaitIntervalSeconds) * time.Second) // Wait for 5 seconds before checking again | ||
| } | ||
| return fmt.Errorf("volume did not become available within %d seconds", constants.MaxIntervalCount*5) | ||
|
OmkarDeshpande7 marked this conversation as resolved.
Outdated
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error message still references
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
| } | ||
|
|
@@ -173,7 +181,11 @@ func (osclient *OpenStackClients) AttachVolumeToVM(volumeID string) error { | |
| return fmt.Errorf("failed to get instance ID: %s", err) | ||
| } | ||
|
|
||
| for i := 0; i < constants.MaxIntervalCount; i++ { | ||
| vjailbreakSettings, err := utils.GetVjailbreakSettings(context.Background(), osclient.K8sClient) | ||
| if err != nil { | ||
| return errors.Wrap(err, "failed to get vjailbreak settings") | ||
| } | ||
| for i := 0; i < vjailbreakSettings.VolumeAvailableWaitRetryLimit; i++ { | ||
| _, err = volumeattach.Create(osclient.ComputeClient, instanceID, volumeattach.CreateOpts{ | ||
| VolumeID: volumeID, | ||
| DeleteOnTermination: false, | ||
|
|
@@ -182,7 +194,7 @@ func (osclient *OpenStackClients) AttachVolumeToVM(volumeID string) error { | |
| err = nil | ||
| break | ||
| } | ||
| time.Sleep(5 * time.Second) // Wait for 5 seconds before checking again | ||
| time.Sleep(time.Duration(vjailbreakSettings.VolumeAvailableWaitIntervalSeconds) * time.Second) // Wait for 5 seconds before checking again | ||
| } | ||
| if err != nil { | ||
| return fmt.Errorf("failed to attach volume to VM: %s", err) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.