mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-09-19 06:26:44 +00:00
Add E2E test cases for repository maintenance job configuration.
Signed-off-by: Xun Jiang <xun.jiang@broadcom.com>
This commit is contained in:
@@ -36,6 +36,7 @@ import (
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
clientset "k8s.io/client-go/kubernetes"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
|
||||
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
|
||||
"github.com/vmware-tanzu/velero/pkg/cmd/cli/install"
|
||||
@@ -56,7 +57,17 @@ type installOptions struct {
|
||||
WorkerOS string
|
||||
}
|
||||
|
||||
func VeleroInstall(ctx context.Context, veleroCfg *test.VeleroConfig, isStandbyCluster bool) error {
|
||||
/*
|
||||
VeleroInstall is used to install Velero for E2E test
|
||||
|
||||
params:
|
||||
|
||||
ctx: The context
|
||||
veleroCfg: Velero E2E case configuration
|
||||
isStandbyCluster: Whether Velero is installed on standby cluster
|
||||
objects: The objects are installed in Velero installed namespace, e.g. the ConfigMaps.
|
||||
*/
|
||||
func VeleroInstall(ctx context.Context, veleroCfg *test.VeleroConfig, isStandbyCluster bool, objects ...client.Object) error {
|
||||
fmt.Printf("Velero install %s\n", time.Now().Format("2006-01-02 15:04:05"))
|
||||
|
||||
// veleroCfg struct including a set of BSL params and a set of additional BSL params,
|
||||
@@ -153,6 +164,14 @@ func VeleroInstall(ctx context.Context, veleroCfg *test.VeleroConfig, isStandbyC
|
||||
)
|
||||
}
|
||||
|
||||
// Install the passed-in objects in Velero installed namespace
|
||||
for _, obj := range objects {
|
||||
if err := veleroCfg.ClientToInstallVelero.Kubebuilder.Create(ctx, obj); err != nil {
|
||||
fmt.Printf("fail to create object %s in namespace %s: %s\n", obj.GetName(), obj.GetNamespace(), err.Error())
|
||||
return fmt.Errorf("fail to create object %s in namespace %s: %w", obj.GetName(), obj.GetNamespace(), err)
|
||||
}
|
||||
}
|
||||
|
||||
// For AWS IRSA credential test, AWS IAM service account is required, so if ServiceAccountName and EKSPolicyARN
|
||||
// are both provided, we assume IRSA test is running, otherwise skip this IAM service account creation part.
|
||||
if veleroCfg.CloudProvider == test.AWS && veleroInstallOptions.ServiceAccountName != "" {
|
||||
@@ -790,7 +809,7 @@ func CheckBSL(ctx context.Context, ns string, bslName string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func PrepareVelero(ctx context.Context, caseName string, veleroCfg test.VeleroConfig) error {
|
||||
func PrepareVelero(ctx context.Context, caseName string, veleroCfg test.VeleroConfig, objects ...client.Object) error {
|
||||
ready, err := IsVeleroReady(context.Background(), &veleroCfg)
|
||||
if err != nil {
|
||||
fmt.Printf("error in checking velero status with %v", err)
|
||||
@@ -804,7 +823,7 @@ func PrepareVelero(ctx context.Context, caseName string, veleroCfg test.VeleroCo
|
||||
return nil
|
||||
}
|
||||
fmt.Printf("need to install velero for case %s \n", caseName)
|
||||
return VeleroInstall(context.Background(), &veleroCfg, false)
|
||||
return VeleroInstall(context.Background(), &veleroCfg, false, objects...)
|
||||
}
|
||||
|
||||
func VeleroUninstall(ctx context.Context, veleroCfg test.VeleroConfig) error {
|
||||
|
||||
@@ -38,6 +38,8 @@ import (
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"golang.org/x/mod/semver"
|
||||
schedulingv1api "k8s.io/api/scheduling/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
ver "k8s.io/apimachinery/pkg/util/version"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
@@ -45,9 +47,11 @@ import (
|
||||
|
||||
"github.com/vmware-tanzu/velero/internal/volume"
|
||||
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
|
||||
"github.com/vmware-tanzu/velero/pkg/builder"
|
||||
cliinstall "github.com/vmware-tanzu/velero/pkg/cmd/cli/install"
|
||||
"github.com/vmware-tanzu/velero/pkg/cmd/util/flag"
|
||||
veleroexec "github.com/vmware-tanzu/velero/pkg/util/exec"
|
||||
"github.com/vmware-tanzu/velero/test"
|
||||
. "github.com/vmware-tanzu/velero/test"
|
||||
common "github.com/vmware-tanzu/velero/test/util/common"
|
||||
. "github.com/vmware-tanzu/velero/test/util/k8s"
|
||||
@@ -274,6 +278,9 @@ func getProviderVeleroInstallOptions(veleroCfg *VeleroConfig,
|
||||
io.ItemBlockWorkerCount = veleroCfg.ItemBlockWorkerCount
|
||||
io.ServerPriorityClassName = veleroCfg.ServerPriorityClassName
|
||||
io.NodeAgentPriorityClassName = veleroCfg.NodeAgentPriorityClassName
|
||||
io.RepoMaintenanceJobConfigMap = veleroCfg.RepoMaintenanceJobConfigMap
|
||||
io.BackupRepoConfigMap = veleroCfg.BackupRepoConfigMap
|
||||
io.NodeAgentConfigMap = veleroCfg.NodeAgentConfigMap
|
||||
|
||||
return io, nil
|
||||
}
|
||||
@@ -1812,3 +1819,43 @@ func KubectlGetAllDeleteBackupRequest(ctx context.Context, backupName, veleroNam
|
||||
|
||||
return common.GetListByCmdPipes(ctx, cmds)
|
||||
}
|
||||
|
||||
func CreatePriorityClasses(ctx context.Context, client kbclient.Client) error {
|
||||
dataMoverPriorityClass := builder.ForPriorityClass(test.PriorityClassNameForDataMover).
|
||||
Value(90000).PreemptionPolicy("Never").Result()
|
||||
if err := client.Create(ctx, dataMoverPriorityClass); err != nil {
|
||||
fmt.Printf("Fail to create PriorityClass %s: %s\n", test.PriorityClassNameForDataMover, err.Error())
|
||||
return fmt.Errorf("fail to create PriorityClass %s: %w", test.PriorityClassNameForDataMover, err)
|
||||
}
|
||||
|
||||
repoMaintenancePriorityClass := builder.ForPriorityClass(test.PriorityClassNameForRepoMaintenance).
|
||||
Value(80000).PreemptionPolicy("Never").Result()
|
||||
if err := client.Create(ctx, repoMaintenancePriorityClass); err != nil {
|
||||
fmt.Printf("Fail to create PriorityClass %s: %s\n", test.PriorityClassNameForRepoMaintenance, err.Error())
|
||||
return fmt.Errorf("fail to create PriorityClass %s: %w", test.PriorityClassNameForRepoMaintenance, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func DeletePriorityClasses(ctx context.Context, client kbclient.Client) error {
|
||||
priorityClassDataMover := &schedulingv1api.PriorityClass{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: test.PriorityClassNameForDataMover,
|
||||
},
|
||||
}
|
||||
if err := client.Delete(ctx, priorityClassDataMover); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
priorityClassRepoMaintenance := &schedulingv1api.PriorityClass{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: test.PriorityClassNameForRepoMaintenance,
|
||||
},
|
||||
}
|
||||
if err := client.Delete(ctx, priorityClassRepoMaintenance); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user