Skip to content

Commit 54935e4

Browse files
committed
Add optional delay in BIA plugin for parallel item testing
Signed-off-by: Scott Seago <sseago@redhat.com>
1 parent 1056764 commit 54935e4

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

internal/plugin/backupplugin.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ limitations under the License.
1717
package plugin
1818

1919
import (
20+
"time"
21+
2022
"github.com/sirupsen/logrus"
2123

2224
"k8s.io/apimachinery/pkg/api/meta"
@@ -26,6 +28,14 @@ import (
2628
"github.com/vmware-tanzu/velero/pkg/plugin/velero"
2729
)
2830

31+
const (
32+
// If this annotation is found on the Velero Backup CR, then sleep
33+
// for the specified duration (logging before and after)
34+
// This will facilitate testing of parallel item backup functionality
35+
// This annotation can also be set on the item, which overrides the backup CR value
36+
BIAWaitDurationAnnotation = "velero.io/example-bia-wait-duration"
37+
)
38+
2939
// BackupPlugin is a backup item action plugin for Velero.
3040
type BackupPlugin struct {
3141
log logrus.FieldLogger
@@ -64,5 +74,26 @@ func (p *BackupPlugin) Execute(item runtime.Unstructured, backup *v1.Backup) (ru
6474

6575
metadata.SetAnnotations(annotations)
6676

77+
var duration time.Duration
78+
if durationStr, ok := annotations[BIAWaitDurationAnnotation]; ok && len(durationStr) != 0 {
79+
duration, err = time.ParseDuration(durationStr)
80+
if err != nil {
81+
p.log.Warnf("Error parsing duration on item: %v", err)
82+
}
83+
}
84+
if duration == 0 && backup.Annotations != nil {
85+
if durationStr, ok := backup.Annotations[BIAWaitDurationAnnotation]; ok && len(durationStr) != 0 {
86+
duration, err = time.ParseDuration(durationStr)
87+
if err != nil {
88+
p.log.Warnf("Error parsing duration on Backup: %v", err)
89+
}
90+
}
91+
}
92+
93+
if duration != 0 {
94+
p.log.Infof("BIA for %v, %v/%v, waiting %v", item.GetObjectKind().GroupVersionKind().Kind, metadata.GetNamespace(), metadata.GetName(), duration)
95+
time.Sleep(duration)
96+
p.log.Infof("BIA for %v, %v/%v, done waiting", item.GetObjectKind().GroupVersionKind().Kind, metadata.GetNamespace(), metadata.GetName())
97+
}
6798
return item, nil, nil
6899
}

0 commit comments

Comments
 (0)