feat(migrate): making timeout configurable

This commit is contained in:
Dario Tranchitella
2022-12-06 16:16:45 +01:00
parent e25f95d7eb
commit 5e78b6392a

View File

@@ -6,6 +6,7 @@ package resources
import (
"context"
"fmt"
"time"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
@@ -113,6 +114,16 @@ func (d *DatastoreMigrate) CreateOrUpdate(ctx context.Context, tenantControlPlan
fmt.Sprintf("--tenant-control-plane=%s/%s", tenantControlPlane.GetNamespace(), tenantControlPlane.GetName()),
fmt.Sprintf("--target-datastore=%s", tenantControlPlane.Spec.DataStore),
}
// Allowing custom migrate timeout by reading TCP annotation
annotations := tenantControlPlane.GetAnnotations()
if v, ok := annotations["migrate.kamaji.clastix.io/timeout"]; ok {
timeout, parseErr := time.ParseDuration(v)
if parseErr != nil {
log.FromContext(ctx).Error(parseErr, "cannot override default migrate timeout")
} else {
d.job.Spec.Template.Spec.Containers[0].Args = append(d.job.Spec.Template.Spec.Containers[0].Args, fmt.Sprintf("--timeout=%s", timeout))
}
}
return nil
})