Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions k8s/migration/internal/controller/migrationplan_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1396,11 +1396,12 @@ func resolveVirtioDriverURL(migrationtemplate *vjailbreakv1alpha1.MigrationTempl
}

func getCurrentInstanceID(openstackcreds *vjailbreakv1alpha1.OpenstackCreds) (string, error) {
if openstackcreds.Spec.VJBInstanceID != "" {
return openstackcreds.Spec.VJBInstanceID, nil
}
currentInstanceID, err := v2vutils.GetCurrentInstanceUUID()
if err != nil {
// if metadata fails then only get from spec
if openstackcreds.Spec.VJBInstanceID != "" {
return openstackcreds.Spec.VJBInstanceID, nil
}
return "", errors.Wrap(err, "failed to get current instance uuid")
}
return currentInstanceID, nil
Expand Down
12 changes: 5 additions & 7 deletions v2v-helper/pkg/utils/openstackopsutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,6 @@ func GetCurrentInstanceUUID() (string, error) {
// Step 1. Path with a read lock
// First Check if the data is already cached. This read lock allows multiple
// Goroutines to read the cached data concurrently.
currentInstanceUUID := os.Getenv("CURRENT_INSTANCE_ID")
if currentInstanceUUID == "" {
PrintLog("CURRENT_INSTANCE_ID environment variable is not set")
} else {
return currentInstanceUUID, nil
}

metadataMutex.RLock()
if cachedMetadata != nil {
// If cached, return it immediately.
Expand Down Expand Up @@ -110,6 +103,11 @@ func GetCurrentInstanceUUID() (string, error) {

resp, err := client.Do(req)
if err != nil {
currentInstanceUUID := os.Getenv("CURRENT_INSTANCE_ID")
if currentInstanceUUID != "" {
PrintLog("CURRENT_INSTANCE_ID environment variable is set to: " + currentInstanceUUID)
return currentInstanceUUID, nil
}
return "", fmt.Errorf("failed to get response: %s", err)
}
defer resp.Body.Close()
Expand Down
Loading