Skip to content

Commit 1dcfb32

Browse files
authored
Merge branch 'main' into private/main/cron-for-upgrade
2 parents 43d1a91 + 9341821 commit 1dcfb32

9 files changed

Lines changed: 79 additions & 21 deletions

File tree

k8s/migration/pkg/constants/constants.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,12 @@ const (
186186
// VMActiveWaitRetryLimit is the number of retries to wait for vm to become active
187187
VMActiveWaitRetryLimit = 15
188188

189+
// VolumeAvailableWaitIntervalSeconds is the interval to wait for volume to become available
190+
VolumeAvailableWaitIntervalSeconds = 5
191+
192+
// VolumeAvailableWaitRetryLimit is the number of retries to wait for volume to become available
193+
VolumeAvailableWaitRetryLimit = 15
194+
189195
// DefaultMigrationMethod is the default migration method
190196
DefaultMigrationMethod = "hot"
191197

@@ -195,6 +201,9 @@ const (
195201
// CleanupVolumesAfterConvertFailure is the default value for cleanup volumes after convert failure
196202
CleanupVolumesAfterConvertFailure = true
197203

204+
// PopulateVMwareMachineFlavors is the default value for populate vmware machine flavors
205+
PopulateVMwareMachineFlavors = true
206+
198207
// VjailbreakSettingsConfigMapName is the name of the vjailbreak settings configmap
199208
VjailbreakSettingsConfigMapName = "vjailbreak-settings"
200209
)

k8s/migration/pkg/utils/settings.go

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ type VjailbreakSettings struct {
2121
VMActiveWaitIntervalSeconds int
2222
// VMActiveWaitRetryLimit is the number of retries to wait for VM to become active
2323
VMActiveWaitRetryLimit int
24+
// VolumeAvailableWaitIntervalSeconds is the interval to wait for volume to become available
25+
VolumeAvailableWaitIntervalSeconds int
26+
// VolumeAvailableWaitRetryLimit is the number of retries to wait for volume to become available
27+
VolumeAvailableWaitRetryLimit int
2428
// DefaultMigrationMethod is the default migration method (hot/cold)
2529
DefaultMigrationMethod string
2630
// 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
6367
}
6468

6569
if vjailbreakSettingsCM.Data["CHANGED_BLOCKS_COPY_ITERATION_THRESHOLD"] == "" {
66-
vjailbreakSettingsCM.Data["CHANGED_BLOCKS_COPY_ITERATION_THRESHOLD"] = "20"
70+
vjailbreakSettingsCM.Data["CHANGED_BLOCKS_COPY_ITERATION_THRESHOLD"] = strconv.Itoa(constants.ChangedBlocksCopyIterationThreshold)
6771
}
6872

6973
if vjailbreakSettingsCM.Data["VM_ACTIVE_WAIT_INTERVAL_SECONDS"] == "" {
70-
vjailbreakSettingsCM.Data["VM_ACTIVE_WAIT_INTERVAL_SECONDS"] = "20"
74+
vjailbreakSettingsCM.Data["VM_ACTIVE_WAIT_INTERVAL_SECONDS"] = strconv.Itoa(constants.VMActiveWaitIntervalSeconds)
7175
}
7276

7377
if vjailbreakSettingsCM.Data["VM_ACTIVE_WAIT_RETRY_LIMIT"] == "" {
74-
vjailbreakSettingsCM.Data["VM_ACTIVE_WAIT_RETRY_LIMIT"] = "15"
78+
vjailbreakSettingsCM.Data["VM_ACTIVE_WAIT_RETRY_LIMIT"] = strconv.Itoa(constants.VMActiveWaitRetryLimit)
79+
}
80+
81+
if vjailbreakSettingsCM.Data["VOLUME_AVAILABLE_WAIT_INTERVAL_SECONDS"] == "" {
82+
vjailbreakSettingsCM.Data["VOLUME_AVAILABLE_WAIT_INTERVAL_SECONDS"] = strconv.Itoa(constants.VolumeAvailableWaitIntervalSeconds)
83+
}
84+
85+
if vjailbreakSettingsCM.Data["VOLUME_AVAILABLE_WAIT_RETRY_LIMIT"] == "" {
86+
vjailbreakSettingsCM.Data["VOLUME_AVAILABLE_WAIT_RETRY_LIMIT"] = strconv.Itoa(constants.VolumeAvailableWaitRetryLimit)
7587
}
7688

7789
if vjailbreakSettingsCM.Data["DEFAULT_MIGRATION_METHOD"] == "" {
78-
vjailbreakSettingsCM.Data["DEFAULT_MIGRATION_METHOD"] = "hot"
90+
vjailbreakSettingsCM.Data["DEFAULT_MIGRATION_METHOD"] = constants.DefaultMigrationMethod
7991
}
8092

8193
if vjailbreakSettingsCM.Data["VCENTER_SCAN_CONCURRENCY_LIMIT"] == "" {
82-
vjailbreakSettingsCM.Data["VCENTER_SCAN_CONCURRENCY_LIMIT"] = "10"
94+
vjailbreakSettingsCM.Data["VCENTER_SCAN_CONCURRENCY_LIMIT"] = strconv.Itoa(constants.VCenterScanConcurrencyLimit)
8395
}
8496

8597
if vjailbreakSettingsCM.Data["CLEANUP_VOLUMES_AFTER_CONVERT_FAILURE"] == "" {
86-
vjailbreakSettingsCM.Data["CLEANUP_VOLUMES_AFTER_CONVERT_FAILURE"] = "false"
98+
vjailbreakSettingsCM.Data["CLEANUP_VOLUMES_AFTER_CONVERT_FAILURE"] = strconv.FormatBool(constants.CleanupVolumesAfterConvertFailure)
8799
}
88100

89101
if vjailbreakSettingsCM.Data["POPULATE_VMWARE_MACHINE_FLAVORS"] == "" {
90-
vjailbreakSettingsCM.Data["POPULATE_VMWARE_MACHINE_FLAVORS"] = trueString
102+
vjailbreakSettingsCM.Data["POPULATE_VMWARE_MACHINE_FLAVORS"] = strconv.FormatBool(constants.PopulateVMwareMachineFlavors)
91103
}
92104

93105
return &VjailbreakSettings{
94106
ChangedBlocksCopyIterationThreshold: atoi(vjailbreakSettingsCM.Data["CHANGED_BLOCKS_COPY_ITERATION_THRESHOLD"]),
95107
VMActiveWaitIntervalSeconds: atoi(vjailbreakSettingsCM.Data["VM_ACTIVE_WAIT_INTERVAL_SECONDS"]),
96108
VMActiveWaitRetryLimit: atoi(vjailbreakSettingsCM.Data["VM_ACTIVE_WAIT_RETRY_LIMIT"]),
109+
VolumeAvailableWaitIntervalSeconds: atoi(vjailbreakSettingsCM.Data["VOLUME_AVAILABLE_WAIT_INTERVAL_SECONDS"]),
110+
VolumeAvailableWaitRetryLimit: atoi(vjailbreakSettingsCM.Data["VOLUME_AVAILABLE_WAIT_RETRY_LIMIT"]),
97111
DefaultMigrationMethod: vjailbreakSettingsCM.Data["DEFAULT_MIGRATION_METHOD"],
98112
VCenterScanConcurrencyLimit: atoi(vjailbreakSettingsCM.Data["VCENTER_SCAN_CONCURRENCY_LIMIT"]),
99113
CleanupVolumesAfterConvertFailure: vjailbreakSettingsCM.Data["CLEANUP_VOLUMES_AFTER_CONVERT_FAILURE"] == "true",
@@ -104,12 +118,14 @@ func GetVjailbreakSettings(ctx context.Context, k8sClient client.Client) (*Vjail
104118
// getDefaultSettings returns default vjailbreak settings
105119
func getDefaultSettings() *VjailbreakSettings {
106120
return &VjailbreakSettings{
107-
ChangedBlocksCopyIterationThreshold: 20,
108-
VMActiveWaitIntervalSeconds: 20,
109-
VMActiveWaitRetryLimit: 15,
110-
DefaultMigrationMethod: "hot",
111-
VCenterScanConcurrencyLimit: 10,
112-
CleanupVolumesAfterConvertFailure: false,
113-
PopulateVMwareMachineFlavors: true,
121+
ChangedBlocksCopyIterationThreshold: constants.ChangedBlocksCopyIterationThreshold,
122+
VMActiveWaitIntervalSeconds: constants.VMActiveWaitIntervalSeconds,
123+
VMActiveWaitRetryLimit: constants.VMActiveWaitRetryLimit,
124+
VolumeAvailableWaitIntervalSeconds: constants.VolumeAvailableWaitIntervalSeconds,
125+
VolumeAvailableWaitRetryLimit: constants.VolumeAvailableWaitRetryLimit,
126+
DefaultMigrationMethod: constants.DefaultMigrationMethod,
127+
VCenterScanConcurrencyLimit: constants.VCenterScanConcurrencyLimit,
128+
CleanupVolumesAfterConvertFailure: constants.CleanupVolumesAfterConvertFailure,
129+
PopulateVMwareMachineFlavors: constants.PopulateVMwareMachineFlavors,
114130
}
115131
}

v2v-helper/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/gophercloud/gophercloud v1.14.1
88
github.com/hashicorp/go-retryablehttp v0.7.7
99
github.com/pkg/errors v0.9.1
10-
github.com/platform9/vjailbreak/k8s/migration v0.0.0-20250718102048-de8740c10909
10+
github.com/platform9/vjailbreak/k8s/migration v0.0.0-20250904115639-c2134e9ef3b9
1111
github.com/prometheus-community/pro-bing v0.4.1
1212
github.com/stretchr/testify v1.10.0
1313
github.com/vmware/govmomi v0.51.0

v2v-helper/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ func main() {
4949
<-ackChan
5050
}
5151
utils.PrintLog(msg)
52-
return
5352
}
5453

5554
client, err := utils.GetInclusterClient()
@@ -93,6 +92,7 @@ func main() {
9392
if err != nil {
9493
handleError(fmt.Sprintf("Failed to validate OpenStack connection: %v", err))
9594
}
95+
openstackclients.K8sClient = client
9696
utils.PrintLog("Connected to OpenStack")
9797

9898
// Get thumbprint

v2v-helper/openstack/openstackops.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ func validateOpenStack(insecure bool) (*migrateutils.OpenStackClients, error) {
138138
BlockStorageClient: blockStorageClient,
139139
ComputeClient: computeClient,
140140
NetworkingClient: networkingClient,
141+
K8sClient: nil,
141142
}, nil
142143
}
143144

v2v-helper/pkg/constants/constants.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ echo "$(date '+%Y-%m-%d %H:%M:%S') - Network fix script completed" >> "$LOG_FILE
113113
// VMActiveWaitRetryLimit is the number of retries to wait for vm to become active
114114
VMActiveWaitRetryLimit = 15
115115

116+
// VolumeAvailableWaitIntervalSeconds is the interval to wait for volume to become available
117+
VolumeAvailableWaitIntervalSeconds = 5
118+
119+
// VolumeAvailableWaitRetryLimit is the number of retries to wait for volume to become available
120+
VolumeAvailableWaitRetryLimit = 15
121+
116122
// DefaultMigrationMethod is the default migration method
117123
DefaultMigrationMethod = "hot"
118124

v2v-helper/pkg/utils/migrateutils/openstackopsutils.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package migrateutils
22

33
import (
4+
"context"
45
"encoding/json"
56
"fmt"
67
"io"
@@ -17,6 +18,7 @@ import (
1718
"github.com/platform9/vjailbreak/v2v-helper/pkg/constants"
1819
"github.com/platform9/vjailbreak/v2v-helper/pkg/utils"
1920
"github.com/platform9/vjailbreak/v2v-helper/vm"
21+
"sigs.k8s.io/controller-runtime/pkg/client"
2022

2123
"github.com/gophercloud/gophercloud"
2224
"github.com/gophercloud/gophercloud/openstack"
@@ -36,6 +38,7 @@ type OpenStackClients struct {
3638
BlockStorageClient *gophercloud.ServiceClient
3739
ComputeClient *gophercloud.ServiceClient
3840
NetworkingClient *gophercloud.ServiceClient
41+
K8sClient client.Client
3942
}
4043

4144
type OpenStackMetadata struct {
@@ -129,7 +132,12 @@ func (osclient *OpenStackClients) DeleteVolume(volumeID string) error {
129132
}
130133

131134
func (osclient *OpenStackClients) WaitForVolume(volumeID string) error {
132-
for i := 0; i < constants.MaxIntervalCount; i++ {
135+
// Get vjailbreak settings
136+
vjailbreakSettings, err := utils.GetVjailbreakSettings(context.Background(), osclient.K8sClient)
137+
if err != nil {
138+
return errors.Wrap(err, "failed to get vjailbreak settings")
139+
}
140+
for i := 0; i < vjailbreakSettings.VolumeAvailableWaitRetryLimit; i++ {
133141
volume, err := volumes.Get(osclient.BlockStorageClient, volumeID).Extract()
134142
if err != nil {
135143
return fmt.Errorf("failed to get volume: %s", err)
@@ -162,9 +170,9 @@ func (osclient *OpenStackClients) WaitForVolume(volumeID string) error {
162170
return nil
163171
}
164172
fmt.Printf("Volume %s is still attached to server retrying %d times\n", volumeID, i)
165-
time.Sleep(5 * time.Second) // Wait for 5 seconds before checking again
173+
time.Sleep(time.Duration(vjailbreakSettings.VolumeAvailableWaitIntervalSeconds) * time.Second) // Wait for 5 seconds before checking again
166174
}
167-
return fmt.Errorf("volume did not become available within %d seconds", constants.MaxIntervalCount*5)
175+
return fmt.Errorf("volume did not become available within %d seconds", vjailbreakSettings.VolumeAvailableWaitRetryLimit*vjailbreakSettings.VolumeAvailableWaitIntervalSeconds)
168176
}
169177

170178
func (osclient *OpenStackClients) AttachVolumeToVM(volumeID string) error {
@@ -173,7 +181,11 @@ func (osclient *OpenStackClients) AttachVolumeToVM(volumeID string) error {
173181
return fmt.Errorf("failed to get instance ID: %s", err)
174182
}
175183

176-
for i := 0; i < constants.MaxIntervalCount; i++ {
184+
vjailbreakSettings, err := utils.GetVjailbreakSettings(context.Background(), osclient.K8sClient)
185+
if err != nil {
186+
return errors.Wrap(err, "failed to get vjailbreak settings")
187+
}
188+
for i := 0; i < vjailbreakSettings.VolumeAvailableWaitRetryLimit; i++ {
177189
_, err = volumeattach.Create(osclient.ComputeClient, instanceID, volumeattach.CreateOpts{
178190
VolumeID: volumeID,
179191
DeleteOnTermination: false,
@@ -182,7 +194,7 @@ func (osclient *OpenStackClients) AttachVolumeToVM(volumeID string) error {
182194
err = nil
183195
break
184196
}
185-
time.Sleep(5 * time.Second) // Wait for 5 seconds before checking again
197+
time.Sleep(time.Duration(vjailbreakSettings.VolumeAvailableWaitIntervalSeconds) * time.Second) // Wait for 5 seconds before checking again
186198
}
187199
if err != nil {
188200
return fmt.Errorf("failed to attach volume to VM: %s", err)

v2v-helper/pkg/utils/types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ type VjailbreakSettings struct {
88
VCenterScanConcurrencyLimit int
99
CleanupVolumesAfterConvertFailure bool
1010
PopulateVMwareMachineFlavors bool
11+
VolumeAvailableWaitIntervalSeconds int
12+
VolumeAvailableWaitRetryLimit int
1113
}

v2v-helper/pkg/utils/utils.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ func GetVjailbreakSettings(ctx context.Context, k8sClient client.Client) (*Vjail
131131
VCenterScanConcurrencyLimit: constants.VCenterScanConcurrencyLimit,
132132
CleanupVolumesAfterConvertFailure: constants.CleanupVolumesAfterConvertFailure,
133133
PopulateVMwareMachineFlavors: constants.PopulateVMwareMachineFlavors,
134+
VolumeAvailableWaitIntervalSeconds: constants.VolumeAvailableWaitIntervalSeconds,
135+
VolumeAvailableWaitRetryLimit: constants.VolumeAvailableWaitRetryLimit,
134136
}, nil
135137
}
136138

@@ -146,6 +148,14 @@ func GetVjailbreakSettings(ctx context.Context, k8sClient client.Client) (*Vjail
146148
vjailbreakSettingsCM.Data["VM_ACTIVE_WAIT_RETRY_LIMIT"] = strconv.Itoa(constants.VMActiveWaitRetryLimit)
147149
}
148150

151+
if vjailbreakSettingsCM.Data["VOLUME_AVAILABLE_WAIT_INTERVAL_SECONDS"] == "" {
152+
vjailbreakSettingsCM.Data["VOLUME_AVAILABLE_WAIT_INTERVAL_SECONDS"] = strconv.Itoa(constants.VolumeAvailableWaitIntervalSeconds)
153+
}
154+
155+
if vjailbreakSettingsCM.Data["VOLUME_AVAILABLE_WAIT_RETRY_LIMIT"] == "" {
156+
vjailbreakSettingsCM.Data["VOLUME_AVAILABLE_WAIT_RETRY_LIMIT"] = strconv.Itoa(constants.VolumeAvailableWaitRetryLimit)
157+
}
158+
149159
if vjailbreakSettingsCM.Data["DEFAULT_MIGRATION_METHOD"] == "" {
150160
vjailbreakSettingsCM.Data["DEFAULT_MIGRATION_METHOD"] = constants.DefaultMigrationMethod
151161
}
@@ -166,6 +176,8 @@ func GetVjailbreakSettings(ctx context.Context, k8sClient client.Client) (*Vjail
166176
ChangedBlocksCopyIterationThreshold: atoi(vjailbreakSettingsCM.Data["CHANGED_BLOCKS_COPY_ITERATION_THRESHOLD"]),
167177
VMActiveWaitIntervalSeconds: atoi(vjailbreakSettingsCM.Data["VM_ACTIVE_WAIT_INTERVAL_SECONDS"]),
168178
VMActiveWaitRetryLimit: atoi(vjailbreakSettingsCM.Data["VM_ACTIVE_WAIT_RETRY_LIMIT"]),
179+
VolumeAvailableWaitIntervalSeconds: atoi(vjailbreakSettingsCM.Data["VOLUME_AVAILABLE_WAIT_INTERVAL_SECONDS"]),
180+
VolumeAvailableWaitRetryLimit: atoi(vjailbreakSettingsCM.Data["VOLUME_AVAILABLE_WAIT_RETRY_LIMIT"]),
169181
DefaultMigrationMethod: vjailbreakSettingsCM.Data["DEFAULT_MIGRATION_METHOD"],
170182
VCenterScanConcurrencyLimit: atoi(vjailbreakSettingsCM.Data["VCENTER_SCAN_CONCURRENCY_LIMIT"]),
171183
CleanupVolumesAfterConvertFailure: vjailbreakSettingsCM.Data["CLEANUP_VOLUMES_AFTER_CONVERT_FAILURE"] == "true",

0 commit comments

Comments
 (0)