Skip to content

Commit

Permalink
openstack: add config for retry attempts
Browse files Browse the repository at this point in the history
Signed-off-by: Benny Zlotnik <[email protected]>
  • Loading branch information
bennyz committed Dec 25, 2023
1 parent aa6c884 commit b52a528
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 5 deletions.
2 changes: 2 additions & 0 deletions operator/config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ spec:
value: ${SNAPSHOT_REMOVAL_TIMEOUT}
- name: SNAPSHOT_STATUS_CHECK_RATE
value: ${SNAPSHOT_STATUS_CHECK_RATE}
- name: CLEANUP_RETRIES
value: ${CLEANUP_RETRIES}
- name: CDI_EXPORT_TOKEN_TTL
value: ${CDI_EXPORT_TOKEN_TTL}
- name: FILESYSTEM_OVERHEAD
Expand Down
1 change: 1 addition & 0 deletions operator/roles/forkliftcontroller/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ controller_log_level: 3
controller_precopy_interval: 60
controller_snapshot_removal_timeout_minuts: 120
controller_snapshot_status_check_rate_seconds: 10
controller_cleanup_retries: 10
controller_vsphere_incremental_backup: true
controller_ovirt_warm_migration: true
controller_max_vm_inflight: 20
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ spec:
- name: SNAPSHOT_STATUS_CHECK_RATE_SECONDS
value: "{{ controller_snapshot_status_check_rate_seconds }}"
{% endif %}
{% if controller_cleanup_retries is number %}
- name: CLEANUP_RETRIES
value: "{{ controller_cleanup_retries }}"
{% endif %}
{% if controller_max_vm_inflight is number %}
- name: MAX_VM_INFLIGHT
value: "{{ controller_max_vm_inflight }}"
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/plan/adapter/openstack/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ go_library(
"//pkg/lib/client/openstack",
"//pkg/lib/error",
"//pkg/lib/itinerary",
"//pkg/settings",
"//vendor/k8s.io/api/core/v1:core",
"//vendor/k8s.io/apimachinery/pkg/api/errors",
"//vendor/k8s.io/apimachinery/pkg/api/resource",
Expand Down
9 changes: 4 additions & 5 deletions pkg/controller/plan/adapter/openstack/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
model "github.com/konveyor/forklift-controller/pkg/controller/provider/web/openstack"
libclient "github.com/konveyor/forklift-controller/pkg/lib/client/openstack"
liberr "github.com/konveyor/forklift-controller/pkg/lib/error"
"github.com/konveyor/forklift-controller/pkg/settings"
"k8s.io/apimachinery/pkg/util/wait"
cdi "kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1"
)
Expand Down Expand Up @@ -555,7 +556,7 @@ func (r *Client) cleanup(vm *libclient.VM, originalVolumeID string) (err error)
volume, err := r.getVolumeFromSnapshot(vm, snapshot.ID)
if err != nil {
if errors.Is(err, ResourceNotFoundError) {
r.Log.Info("volume not found, we are done")
r.Log.Info("volume doesn't exist, assuming we are done")
done = true
err = nil
return
Expand All @@ -578,19 +579,17 @@ func (r *Client) cleanup(vm *libclient.VM, originalVolumeID string) (err error)
return
}

// TODO add config
backoff := wait.Backoff{
Duration: 3 * time.Second,
Factor: 1.1,
Steps: 100,
Factor: 1.5,
Steps: settings.Settings.CleanupRetries,
}

err = wait.ExponentialBackoff(backoff, condition)
if err != nil {
err = liberr.Wrap(err)
r.Log.Error(err, "waiting for the volume to be removed",
"vm", vm.Name, "snapshotID", snapshot.ID)
err = nil
return
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/settings/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const (
CDIExportTokenTTL = "CDI_EXPORT_TOKEN_TTL"
FileSystemOverhead = "FILESYSTEM_OVERHEAD"
BlockOverhead = "BLOCK_OVERHEAD"
CleanupRetries = "CLEANUP_RETRIES"
)

// Migration settings
Expand Down Expand Up @@ -49,6 +50,8 @@ type Migration struct {
FileSystemOverhead int
// Block fixed overhead size
BlockOverhead int64
// Cleanup retries
CleanupRetries int
}

// Load settings.
Expand All @@ -71,6 +74,9 @@ func (r *Migration) Load() (err error) {
if r.SnapshotStatusCheckRate, err = getPositiveEnvLimit(SnapshotStatusCheckRate, 10); err != nil {
return liberr.Wrap(err)
}
if r.CleanupRetries, err = getPositiveEnvLimit(CleanupRetries, 10); err != nil {
return liberr.Wrap(err)
}
if virtV2vImage, ok := os.LookupEnv(VirtV2vImage); ok {
if cold, warm, found := strings.Cut(virtV2vImage, "|"); found {
r.VirtV2vImageCold = cold
Expand Down

0 comments on commit b52a528

Please sign in to comment.