Update upgrade test for 1.10

Signed-off-by: danfengl <danfengl@vmware.com>
pull/5524/head
danfengl 2022-10-29 07:54:47 +00:00
parent a411130256
commit 78dae45c52
12 changed files with 255 additions and 213 deletions

View File

@ -209,7 +209,7 @@ endif
--build-arg=RESTIC_VERSION=$(RESTIC_VERSION) \
-f $(VELERO_DOCKERFILE) .
@echo "container: $(IMAGE):$(VERSION)"
ifeq ($(BUILDX_OUTPUT_TYPE), "registry")
ifeq ($(BUILDX_OUTPUT_TYPE), registry)
@docker pull $(IMAGE):$(VERSION)
@docker save $(IMAGE):$(VERSION) -o $(BIN)-$(VERSION).tar
@gzip $(BIN)-$(VERSION).tar

View File

@ -49,6 +49,6 @@ func RunCommand(cmd *exec.Cmd) (string, string, error) {
} else {
stderr = string(res)
}
cmd.Process.Kill()
return stdout, stderr, runErr
}

View File

@ -86,7 +86,7 @@ func backup_deletion_test(useVolumeSnapshots bool) {
}
// runUpgradeTests runs upgrade test on the provider by kibishii.
func runBackupDeletionTests(client TestClient, veleroCfg VerleroConfig, backupName, backupLocation string,
func runBackupDeletionTests(client TestClient, veleroCfg VeleroConfig, backupName, backupLocation string,
useVolumeSnapshots bool, kibishiiDirectory string) error {
oneHourTimeout, _ := context.WithTimeout(context.Background(), time.Minute*60)
veleroCLI := VeleroCfg.VeleroCLI

View File

@ -27,8 +27,8 @@ const POD_COUNT, VOLUME_COUNT_PER_POD = 2, 3
const OPT_IN_ANN, OPT_OUT_ANN = "backup.velero.io/backup-volumes", "backup.velero.io/backup-volumes-excludes"
const FILE_NAME = "test-data.txt"
var OptInPVBackupTest func() = TestFunc(&PVBackupFiltering{annotation: OPT_IN_ANN, id: "debug-opt-in"})
var OptOutPVBackupTest func() = TestFunc(&PVBackupFiltering{annotation: OPT_OUT_ANN, id: "debug-opt-out"})
var OptInPVBackupTest func() = TestFunc(&PVBackupFiltering{annotation: OPT_IN_ANN, id: "opt-in"})
var OptOutPVBackupTest func() = TestFunc(&PVBackupFiltering{annotation: OPT_OUT_ANN, id: "opt-out"})
func (p *PVBackupFiltering) Init() error {
p.Ctx, _ = context.WithTimeout(context.Background(), 60*time.Minute)

View File

@ -20,7 +20,6 @@ import (
"context"
"flag"
"fmt"
"strings"
"time"
. "github.com/onsi/ginkgo"
@ -178,45 +177,10 @@ func (t *TestCase) Restore() error {
}
By("Start to restore ......", func() {
quitCh := make(chan struct{})
if strings.Contains(t.RestoreName, "-opt-") {
for _, ns := range *t.NSIncluded {
go func() {
for {
select {
case <-quitCh:
return
default:
}
fmt.Printf("start to get log for namespace %s ......", ns)
arg0 := []string{"-u"}
KubectlGetInfo("date", arg0)
arg := []string{"get", "all", "-n", ns}
KubectlGetInfo("kubectl", arg)
time.Sleep(5 * time.Second)
arg1 := []string{"get", "pvc", "-n", ns}
KubectlGetInfo("kubectl", arg1)
time.Sleep(5 * time.Second)
arg2 := []string{"get", "pv"}
KubectlGetInfo("kubectl", arg2)
time.Sleep(5 * time.Second)
arg3 := []string{"get", "events", "-o", "custom-columns=FirstSeen:.firstTimestamp,Count:.count,From:.source.component,Type:.type,Reason:.reason,Message:.message", "--all-namespaces"}
KubectlGetInfo("kubectl", arg3)
time.Sleep(20 * time.Second)
}
}()
}
}
var err error
if err = VeleroRestoreExec(t.Ctx, VeleroCfg.VeleroCLI, VeleroCfg.VeleroNamespace, t.RestoreName, t.RestoreArgs); err != nil {
Expect(VeleroRestoreExec(t.Ctx, VeleroCfg.VeleroCLI, VeleroCfg.VeleroNamespace, t.RestoreName, t.RestoreArgs)).To(Succeed(), func() string {
RunDebug(context.Background(), VeleroCfg.VeleroCLI, VeleroCfg.VeleroNamespace, "", t.RestoreName)
}
close(quitCh)
Expect(err).To(BeNil())
// Expect(VeleroRestoreExec(t.Ctx, VeleroCfg.VeleroCLI, VeleroCfg.VeleroNamespace, t.RestoreName, t.RestoreArgs)).To(Succeed(), func() string {
// RunDebug(context.Background(), VeleroCfg.VeleroCLI, VeleroCfg.VeleroNamespace, "", t.RestoreName)
// return "Fail to restore workload"
// })
return "Fail to restore workload"
})
})
return nil
}

View File

@ -26,9 +26,9 @@ import (
var UUIDgen uuid.UUID
var VeleroCfg VerleroConfig
var VeleroCfg VeleroConfig
type VerleroConfig struct {
type VeleroConfig struct {
VeleroCLI string
VeleroImage string
VeleroVersion string

View File

@ -29,6 +29,7 @@ import (
. "github.com/vmware-tanzu/velero/test/e2e"
. "github.com/vmware-tanzu/velero/test/e2e/util/k8s"
. "github.com/vmware-tanzu/velero/test/e2e/util/kibishii"
. "github.com/vmware-tanzu/velero/test/e2e/util/providers"
. "github.com/vmware-tanzu/velero/test/e2e/util/velero"
)
@ -91,7 +92,6 @@ func BackupUpgradeRestoreTest(useVolumeSnapshots bool, veleroCLI2Version VeleroC
UUIDgen, err = uuid.NewRandom()
Expect(err).To(Succeed())
oneHourTimeout, _ := context.WithTimeout(context.Background(), time.Minute*60)
fmt.Println(veleroCLI2Version.VeleroCLI)
if veleroCLI2Version.VeleroCLI == "" {
//Assume tag of velero server image is identical to velero CLI version
//Download velero CLI if it's empty according to velero CLI version
@ -121,7 +121,7 @@ func BackupUpgradeRestoreTest(useVolumeSnapshots bool, veleroCLI2Version VeleroC
Expect(CheckVeleroVersion(context.Background(), tmpCfgForOldVeleroInstall.VeleroCLI,
tmpCfgForOldVeleroInstall.UpgradeFromVeleroVersion)).To(Succeed())
})
time.Sleep(100000 * time.Minute)
backupName = "backup-" + UUIDgen.String()
restoreName = "restore-" + UUIDgen.String()
tmpCfg := VeleroCfg
@ -201,16 +201,7 @@ func BackupUpgradeRestoreTest(useVolumeSnapshots bool, veleroCLI2Version VeleroC
tmpCfg.UseNodeAgent = !useVolumeSnapshots
tmpCfg.UseRestic = false
tmpCfg.UploaderType = "restic"
tmpCfg.VeleroVersion = "main"
fmt.Println("tmpCfg.VeleroVersion")
fmt.Println(tmpCfg.VeleroVersion)
fmt.Println("tmpCfg.UploaderType")
fmt.Println(tmpCfg.UploaderType)
output, err := VeleroUpgrade(context.Background(), tmpCfg.VeleroCLI,
tmpCfg.VeleroNamespace, tmpCfg.VeleroVersion, tmpCfg.UploaderType)
fmt.Println(output)
time.Sleep(100000 * time.Minute)
Expect(err).To(Succeed())
Expect(VeleroUpgrade(context.Background(), tmpCfg)).To(Succeed())
Expect(CheckVeleroVersion(context.Background(), tmpCfg.VeleroCLI,
tmpCfg.VeleroVersion)).To(Succeed())
})

View File

@ -13,98 +13,36 @@ type OsCommandLine struct {
Args []string
}
func GetListBy2Pipes(ctx context.Context, cmdline1, cmdline2, cmdline3 OsCommandLine) ([]string, error) {
var b2 bytes.Buffer
var errVelero, errAwk error
c1 := exec.CommandContext(ctx, cmdline1.Cmd, cmdline1.Args...)
c2 := exec.Command(cmdline2.Cmd, cmdline2.Args...)
c3 := exec.Command(cmdline3.Cmd, cmdline3.Args...)
fmt.Println(c1)
fmt.Println(c2)
fmt.Println(c3)
c2.Stdin, errVelero = c1.StdoutPipe()
if errVelero != nil {
return nil, errVelero
func GetListByCmdPipes(ctx context.Context, cmdlines []*OsCommandLine) ([]string, error) {
var buf bytes.Buffer
var err error
var cmds []*exec.Cmd
for _, cmdline := range cmdlines {
cmd := exec.Command(cmdline.Cmd, cmdline.Args...)
cmds = append(cmds, cmd)
fmt.Println(cmd)
}
c3.Stdin, errAwk = c2.StdoutPipe()
if errAwk != nil {
return nil, errAwk
for i := 0; i < len(cmds); i++ {
if i == len(cmds)-1 {
break
}
cmds[i+1].Stdin, err = cmds[i].StdoutPipe()
if err != nil {
return nil, err
}
}
cmds[len(cmds)-1].Stdout = &buf
for i := len(cmds) - 1; i >= 0; i-- {
_ = cmds[i].Start()
if i == 0 {
_ = cmds[i].Run()
}
}
for i := 1; i < len(cmds); i++ {
_ = cmds[i].Wait()
}
c3.Stdout = &b2
_ = c3.Start()
_ = c2.Start()
_ = c1.Run()
_ = c2.Wait()
_ = c3.Wait()
//fmt.Println(&b2)
scanner := bufio.NewScanner(&b2)
var ret []string
for scanner.Scan() {
fmt.Printf("line: %s\n", scanner.Text())
ret = append(ret, scanner.Text())
}
if err := scanner.Err(); err != nil {
return nil, err
}
return ret, nil
}
func GetListBy5Pipes(ctx context.Context, cmdline1, cmdline2, cmdline3, cmdline4, cmdline5, cmdline6 OsCommandLine) ([]string, error) {
var b5 bytes.Buffer
var errVelero, errAwk error
c1 := exec.CommandContext(ctx, cmdline1.Cmd, cmdline1.Args...)
c2 := exec.Command(cmdline2.Cmd, cmdline2.Args...)
c3 := exec.Command(cmdline3.Cmd, cmdline3.Args...)
c4 := exec.Command(cmdline4.Cmd, cmdline4.Args...)
c5 := exec.Command(cmdline5.Cmd, cmdline5.Args...)
c6 := exec.Command(cmdline6.Cmd, cmdline6.Args...)
fmt.Println(c1)
fmt.Println(c2)
fmt.Println(c3)
fmt.Println(c4)
fmt.Println(c5)
fmt.Println(c6)
c2.Stdin, errVelero = c1.StdoutPipe()
if errVelero != nil {
return nil, errVelero
}
c3.Stdin, errAwk = c2.StdoutPipe()
if errAwk != nil {
return nil, errAwk
}
c4.Stdin, errAwk = c3.StdoutPipe()
if errAwk != nil {
return nil, errAwk
}
c5.Stdin, errAwk = c4.StdoutPipe()
if errAwk != nil {
return nil, errAwk
}
c6.Stdin, errAwk = c5.StdoutPipe()
if errAwk != nil {
return nil, errAwk
}
c6.Stdout = &b5
_ = c6.Start()
_ = c5.Start()
_ = c4.Start()
_ = c3.Start()
_ = c2.Start()
_ = c1.Run()
_ = c2.Wait()
_ = c3.Wait()
_ = c4.Wait()
_ = c5.Wait()
_ = c6.Wait()
//fmt.Println(&b2)
scanner := bufio.NewScanner(&b5)
scanner := bufio.NewScanner(&buf)
var ret []string
for scanner.Scan() {
fmt.Printf("line: %s\n", scanner.Text())

View File

@ -31,7 +31,7 @@ import (
"github.com/vmware-tanzu/velero/pkg/builder"
veleroexec "github.com/vmware-tanzu/velero/pkg/util/exec"
common "github.com/vmware-tanzu/velero/test/e2e/util/common"
"github.com/vmware-tanzu/velero/test/e2e/util/common"
)
// ensureClusterExists returns whether or not a kubernetes cluster exists for tests to be run on.
@ -86,42 +86,52 @@ func GetPvcByPodName(ctx context.Context, namespace, podName string) ([]string,
// Example:
// NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
// kibishii-data-kibishii-deployment-0 Bound pvc-94b9fdf2-c30f-4a7b-87bf-06eadca0d5b6 1Gi RWO kibishii-storage-class 115s
CmdLine1 := &common.OsCommandLine{
cmds := []*common.OsCommandLine{}
cmd := &common.OsCommandLine{
Cmd: "kubectl",
Args: []string{"get", "pvc", "-n", namespace},
}
CmdLine2 := &common.OsCommandLine{
cmds = append(cmds, cmd)
cmd = &common.OsCommandLine{
Cmd: "grep",
Args: []string{podName},
}
CmdLine3 := &common.OsCommandLine{
cmds = append(cmds, cmd)
cmd = &common.OsCommandLine{
Cmd: "awk",
Args: []string{"{print $1}"},
}
cmds = append(cmds, cmd)
return common.GetListBy2Pipes(ctx, *CmdLine1, *CmdLine2, *CmdLine3)
return common.GetListByCmdPipes(ctx, cmds)
}
func GetPvByPvc(ctx context.Context, namespace, pvc string) ([]string, error) {
// Example:
// NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
// pvc-3f784366-58db-40b2-8fec-77307807e74b 1Gi RWO Delete Bound bsl-deletion/kibishii-data-kibishii-deployment-0 kibishii-storage-class 6h41m
CmdLine1 := &common.OsCommandLine{
cmds := []*common.OsCommandLine{}
cmd := &common.OsCommandLine{
Cmd: "kubectl",
Args: []string{"get", "pv"},
}
cmds = append(cmds, cmd)
CmdLine2 := &common.OsCommandLine{
cmd = &common.OsCommandLine{
Cmd: "grep",
Args: []string{namespace + "/" + pvc},
}
cmds = append(cmds, cmd)
CmdLine3 := &common.OsCommandLine{
cmd = &common.OsCommandLine{
Cmd: "awk",
Args: []string{"{print $1}"},
}
cmds = append(cmds, cmd)
return common.GetListBy2Pipes(ctx, *CmdLine1, *CmdLine2, *CmdLine3)
return common.GetListByCmdPipes(ctx, cmds)
}
func CRDShouldExist(ctx context.Context, name string) error {
@ -145,22 +155,26 @@ func CRDCountShouldBe(ctx context.Context, name string, count int) error {
}
func GetCRD(ctx context.Context, name string) ([]string, error) {
CmdLine1 := &common.OsCommandLine{
cmds := []*common.OsCommandLine{}
cmd := &common.OsCommandLine{
Cmd: "kubectl",
Args: []string{"get", "crd"},
}
cmds = append(cmds, cmd)
CmdLine2 := &common.OsCommandLine{
cmd = &common.OsCommandLine{
Cmd: "grep",
Args: []string{name},
}
cmds = append(cmds, cmd)
CmdLine3 := &common.OsCommandLine{
cmd = &common.OsCommandLine{
Cmd: "awk",
Args: []string{"{print $1}"},
}
cmds = append(cmds, cmd)
return common.GetListBy2Pipes(ctx, *CmdLine1, *CmdLine2, *CmdLine3)
return common.GetListByCmdPipes(ctx, cmds)
}
func AddLabelToPv(ctx context.Context, pv, label string) error {
@ -293,3 +307,23 @@ func KubectlGetInfo(cmdName string, arg []string) {
fmt.Println(err)
}
}
func KubectlGetDsJson(veleroNamespace string) (string, error) {
arg := []string{"get", "ds", "-n", veleroNamespace, "-ojson"}
cmd := exec.CommandContext(context.Background(), "kubectl", arg...)
fmt.Printf("Kubectl exec cmd =%v\n", cmd)
stdout, stderr, err := veleroexec.RunCommand(cmd)
fmt.Println(stdout)
if err != nil {
fmt.Println(stderr)
fmt.Println(err)
return "", err
}
return stdout, nil
}
func DeleteVeleroDs(ctx context.Context) error {
args := []string{"delete", "ds", "-n", "velero", "--all", "--force", "--grace-period", "0"}
fmt.Println(args)
return exec.CommandContext(ctx, "kubectl", args...).Run()
}

View File

@ -51,7 +51,7 @@ var DefaultKibishiiData = &KibishiiData{2, 10, 10, 1024, 1024, 0, 2}
var KibishiiPodNameList = []string{"kibishii-deployment-0", "kibishii-deployment-1"}
// RunKibishiiTests runs kibishii tests on the provider.
func RunKibishiiTests(client TestClient, veleroCfg VerleroConfig, backupName, restoreName, backupLocation, kibishiiNamespace string,
func RunKibishiiTests(client TestClient, veleroCfg VeleroConfig, backupName, restoreName, backupLocation, kibishiiNamespace string,
useVolumeSnapshots bool) error {
oneHourTimeout, _ := context.WithTimeout(context.Background(), time.Minute*60)
veleroCLI := VeleroCfg.VeleroCLI

View File

@ -49,7 +49,7 @@ type installOptions struct {
RestoreHelperImage string
}
func VeleroInstall(ctx context.Context, veleroCfg *VerleroConfig, useVolumeSnapshots bool) error {
func VeleroInstall(ctx context.Context, veleroCfg *VeleroConfig, useVolumeSnapshots bool) error {
if veleroCfg.CloudProvider != "kind" {
if veleroCfg.ObjectStoreProvider != "" {
return errors.New("For cloud platforms, object store plugin cannot be overridden") // Can't set an object store provider that is different than your cloud
@ -395,7 +395,7 @@ func waitVeleroReady(ctx context.Context, namespace string, useNodeAgent bool) e
if useNodeAgent {
fmt.Println("Waiting for node-agent daemonset to be ready.")
err := wait.PollImmediate(5*time.Second, 10*time.Minute, func() (bool, error) {
err := wait.PollImmediate(5*time.Second, 1*time.Minute, func() (bool, error) {
stdout, stderr, err := velerexec.RunCommand(exec.CommandContext(ctx, "kubectl", "get", "daemonset/node-agent",
"-o", "json", "-n", namespace))
if err != nil {
@ -411,21 +411,6 @@ func waitVeleroReady(ctx context.Context, namespace string, useNodeAgent bool) e
return false, nil
})
if err != nil {
ns := namespace
fmt.Printf("start to get log for namespace %s ......", ns)
arg0 := []string{"-u"}
KubectlGetInfo("date", arg0)
arg := []string{"get", "all", "-n", ns}
KubectlGetInfo("kubectl", arg)
time.Sleep(5 * time.Second)
arg1 := []string{"get", "pvc", "-n", ns}
KubectlGetInfo("kubectl", arg1)
time.Sleep(5 * time.Second)
arg2 := []string{"get", "pv"}
KubectlGetInfo("kubectl", arg2)
time.Sleep(5 * time.Second)
arg3 := []string{"get", "events", "-o", "custom-columns=FirstSeen:.firstTimestamp,Count:.count,From:.source.component,Type:.type,Reason:.reason,Message:.message", "--all-namespaces"}
KubectlGetInfo("kubectl", arg3)
return errors.Wrap(err, "fail to wait for the node-agent ready")
}
}

View File

@ -96,6 +96,13 @@ var pluginsMatrix = map[string]map[string][]string{
"gcp": {"velero/velero-plugin-for-gcp:v1.5.0"},
"azure-csi": {"velero/velero-plugin-for-microsoft-azure:v1.5.0", "velero/velero-plugin-for-csi:v0.3.0"},
},
"v1.10": {
"aws": {"velero/velero-plugin-for-aws:v1.6.0"},
"azure": {"velero/velero-plugin-for-microsoft-azure:v1.6.0"},
"vsphere": {"velero/velero-plugin-for-aws:v1.6.0", "vsphereveleroplugin/velero-plugin-for-vsphere:v1.4.1"},
"gcp": {"velero/velero-plugin-for-gcp:v1.6.0"},
"azure-csi": {"velero/velero-plugin-for-microsoft-azure:v1.6.0", "velero/velero-plugin-for-csi:v0.4.0"},
},
"main": {
"aws": {"velero/velero-plugin-for-aws:main"},
"azure": {"velero/velero-plugin-for-microsoft-azure:main"},
@ -473,9 +480,6 @@ func RunDebug(ctx context.Context, veleroCLI, veleroNamespace, backup, restore s
if err := VeleroCmdExec(ctx, veleroCLI, args); err != nil {
fmt.Println(errors.Wrapf(err, "failed to run the debug command"))
}
if strings.Contains(restore, "-opt-") || strings.Contains(backup, "-opt-") {
time.Sleep(24 * 60 * time.Minute)
}
}
func VeleroCreateBackupLocation(ctx context.Context,
@ -876,22 +880,27 @@ func GetBackupsFromBsl(ctx context.Context, veleroCLI, bslName string) ([]string
if strings.TrimSpace(bslName) != "" {
args1 = append(args1, "-l", "velero.io/storage-location="+bslName)
}
CmdLine1 := &common.OsCommandLine{
cmds := []*common.OsCommandLine{}
cmd := &common.OsCommandLine{
Cmd: veleroCLI,
Args: args1,
}
cmds = append(cmds, cmd)
CmdLine2 := &common.OsCommandLine{
cmd = &common.OsCommandLine{
Cmd: "awk",
Args: []string{"{print $1}"},
}
cmds = append(cmds, cmd)
CmdLine3 := &common.OsCommandLine{
cmd = &common.OsCommandLine{
Cmd: "tail",
Args: []string{"-n", "+2"},
}
cmds = append(cmds, cmd)
return common.GetListBy2Pipes(ctx, *CmdLine1, *CmdLine2, *CmdLine3)
return common.GetListByCmdPipes(ctx, cmds)
}
func GetScheduledBackupsCreationTime(ctx context.Context, veleroCLI, bslName, scheduleName string) ([]string, error) {
@ -913,22 +922,27 @@ func GetBackupsCreationTime(ctx context.Context, veleroCLI, bslName string) ([]s
if strings.TrimSpace(bslName) != "" {
args1 = append(args1, "-l", "velero.io/storage-location="+bslName)
}
CmdLine1 := &common.OsCommandLine{
cmds := []*common.OsCommandLine{}
cmd := &common.OsCommandLine{
Cmd: veleroCLI,
Args: args1,
}
cmds = append(cmds, cmd)
CmdLine2 := &common.OsCommandLine{
cmd = &common.OsCommandLine{
Cmd: "awk",
Args: []string{"{print " + createdTime + "}"},
}
cmds = append(cmds, cmd)
CmdLine3 := &common.OsCommandLine{
cmd = &common.OsCommandLine{
Cmd: "tail",
Args: []string{"-n", "+2"},
}
cmds = append(cmds, cmd)
return common.GetListBy2Pipes(ctx, *CmdLine1, *CmdLine2, *CmdLine3)
return common.GetListByCmdPipes(ctx, cmds)
}
func GetAllBackups(ctx context.Context, veleroCLI string) ([]string, error) {
@ -992,25 +1006,29 @@ func BackupRepositoriesCountShouldBe(ctx context.Context, veleroNamespace, targe
}
func GetResticRepositories(ctx context.Context, veleroNamespace, targetNamespace string) ([]string, error) {
CmdLine1 := &common.OsCommandLine{
cmds := []*common.OsCommandLine{}
cmd := &common.OsCommandLine{
Cmd: "kubectl",
Args: []string{"get", "-n", veleroNamespace, "BackupRepositories"},
}
cmds = append(cmds, cmd)
CmdLine2 := &common.OsCommandLine{
cmd = &common.OsCommandLine{
Cmd: "grep",
Args: []string{targetNamespace},
}
cmds = append(cmds, cmd)
CmdLine3 := &common.OsCommandLine{
cmd = &common.OsCommandLine{
Cmd: "awk",
Args: []string{"{print $1}"},
}
cmds = append(cmds, cmd)
return common.GetListBy2Pipes(ctx, *CmdLine1, *CmdLine2, *CmdLine3)
return common.GetListByCmdPipes(ctx, cmds)
}
func GetSnapshotCheckPoint(client TestClient, VeleroCfg VerleroConfig, expectCount int, namespaceBackedUp, backupName string, kibishiiPodNameList []string) (SnapshotCheckPoint, error) {
func GetSnapshotCheckPoint(client TestClient, VeleroCfg VeleroConfig, expectCount int, namespaceBackedUp, backupName string, kibishiiPodNameList []string) (SnapshotCheckPoint, error) {
var snapshotCheckPoint SnapshotCheckPoint
snapshotCheckPoint.ExpectCount = expectCount
@ -1092,30 +1110,142 @@ func GetSchedule(ctx context.Context, veleroNamespace, scheduleName string) (str
return stdout, err
}
func VeleroUpgrade(ctx context.Context, veleroCLI, veleroNamespace, toVeleroVersion, uploaderType string) ([]string, error) {
CmdLine1 := &common.OsCommandLine{
Cmd: "kubectl",
Args: []string{"get", "deploy", "-n", veleroNamespace},
func VeleroUpgrade(ctx context.Context, veleroCfg VeleroConfig) error {
crd, err := ApplyCRDs(ctx, veleroCfg.VeleroCLI)
if err != nil {
return errors.Wrap(err, "Fail to Apply CRDs")
}
CmdLine2 := &common.OsCommandLine{
Cmd: "sed",
Args: []string{fmt.Sprintf("s#\"image\"\\: \"velero\\/velero\\:v[0-9]*.[0-9]*.[0-9]*\"#\"image\"\\: \"velero\\/velero\\:%s\"#g", toVeleroVersion)},
fmt.Println(crd)
deploy, err := UpdateVeleroDeployment(ctx, veleroCfg)
if err != nil {
return errors.Wrap(err, "Fail to update Velero deployment")
}
CmdLine3 := &common.OsCommandLine{
Cmd: "sed",
Args: []string{fmt.Sprintf("s#\"--default-volumes-to-restic=true\"#\"--default-volumes-to-fs-backup=true\",\"--uploader-type=%s\"#g", uploaderType)},
fmt.Println(deploy)
if veleroCfg.UseNodeAgent {
dsjson, err := KubectlGetDsJson(veleroCfg.VeleroNamespace)
if err != nil {
return errors.Wrap(err, "Fail to update Velero deployment")
}
err = DeleteVeleroDs(ctx)
if err != nil {
return errors.Wrap(err, "Fail to delete Velero ds")
}
update, err := UpdateNodeAgent(ctx, veleroCfg, dsjson)
fmt.Println(update)
if err != nil {
return errors.Wrap(err, "Fail to update node agent")
}
}
CmdLine4 := &common.OsCommandLine{
Cmd: "sed",
Args: []string{fmt.Sprintf("s#\"image\"\\: \"velero\\/velero\\:v[0-9]*.[0-9]*.[0-9]*\"#\"image\"\\: \"velero\\/velero\\:%s\"#g", toVeleroVersion)},
return waitVeleroReady(ctx, veleroCfg.VeleroNamespace, veleroCfg.UseNodeAgent)
}
func ApplyCRDs(ctx context.Context, veleroCLI string) ([]string, error) {
cmds := []*common.OsCommandLine{}
cmd := &common.OsCommandLine{
Cmd: veleroCLI,
Args: []string{"install", "--crds-only", "--dry-run", "-o", "yaml"},
}
CmdLine5 := &common.OsCommandLine{
Cmd: "sed",
Args: []string{"s#restic-timeout#fs-backup-timeout#g"},
}
CmdLine6 := &common.OsCommandLine{
cmds = append(cmds, cmd)
cmd = &common.OsCommandLine{
Cmd: "kubectl",
Args: []string{"apply", "-f", "-"},
}
return common.GetListBy5Pipes(ctx, *CmdLine1, *CmdLine2, *CmdLine3, *CmdLine4, *CmdLine5, *CmdLine6)
cmds = append(cmds, cmd)
return common.GetListByCmdPipes(ctx, cmds)
}
func UpdateVeleroDeployment(ctx context.Context, veleroCfg VeleroConfig) ([]string, error) {
cmds := []*common.OsCommandLine{}
cmd := &common.OsCommandLine{
Cmd: "kubectl",
Args: []string{"get", "deploy", "-n", veleroCfg.VeleroNamespace, "-ojson"},
}
cmds = append(cmds, cmd)
var args string
if veleroCfg.CloudProvider == "vsphere" {
args = fmt.Sprintf("s#\\\"image\\\"\\: \\\"velero\\/velero\\:v[0-9]*.[0-9]*.[0-9]\\\"#\\\"image\\\"\\: \\\"harbor-repo.vmware.com\\/velero_ci\\/velero\\:%s\\\"#g", veleroCfg.VeleroVersion)
} else {
args = fmt.Sprintf("s#\\\"image\\\"\\: \\\"velero\\/velero\\:v[0-9]*.[0-9]*.[0-9]\\\"#\\\"image\\\"\\: \\\"velero\\/velero\\:%s\\\"#g", veleroCfg.VeleroVersion)
}
cmd = &common.OsCommandLine{
Cmd: "sed",
Args: []string{args},
}
cmds = append(cmds, cmd)
cmd = &common.OsCommandLine{
Cmd: "sed",
Args: []string{fmt.Sprintf("s#\\\"server\\\",#\\\"server\\\",\\\"--uploader-type=%s\\\",#g", veleroCfg.UploaderType)},
}
cmds = append(cmds, cmd)
cmd = &common.OsCommandLine{
Cmd: "sed",
Args: []string{"s#default-volumes-to-restic#default-volumes-to-fs-backup#g"},
}
cmds = append(cmds, cmd)
cmd = &common.OsCommandLine{
Cmd: "sed",
Args: []string{"s#default-restic-prune-frequency#default-repo-maintain-frequency#g"},
}
cmds = append(cmds, cmd)
cmd = &common.OsCommandLine{
Cmd: "sed",
Args: []string{"s#restic-timeout#fs-backup-timeout#g"},
}
cmds = append(cmds, cmd)
cmd = &common.OsCommandLine{
Cmd: "kubectl",
Args: []string{"apply", "-f", "-"},
}
cmds = append(cmds, cmd)
return common.GetListByCmdPipes(ctx, cmds)
}
func UpdateNodeAgent(ctx context.Context, veleroCfg VeleroConfig, dsjson string) ([]string, error) {
cmds := []*common.OsCommandLine{}
cmd := &common.OsCommandLine{
Cmd: "echo",
Args: []string{dsjson},
}
cmds = append(cmds, cmd)
var args string
if veleroCfg.CloudProvider == "vsphere" {
args = fmt.Sprintf("s#\\\"image\\\"\\: \\\"velero\\/velero\\:v[0-9]*.[0-9]*.[0-9]\\\"#\\\"image\\\"\\: \\\"harbor-repo.vmware.com\\/velero_ci\\/velero\\:%s\\\"#g", veleroCfg.VeleroVersion)
} else {
args = fmt.Sprintf("s#\\\"image\\\"\\: \\\"velero\\/velero\\:v[0-9]*.[0-9]*.[0-9]\\\"#\\\"image\\\"\\: \\\"velero\\/velero\\:%s\\\"#g", veleroCfg.VeleroVersion)
}
cmd = &common.OsCommandLine{
Cmd: "sed",
Args: []string{args},
}
cmds = append(cmds, cmd)
cmd = &common.OsCommandLine{
Cmd: "sed",
Args: []string{"s#\\\"name\\\"\\: \\\"restic\\\"#\\\"name\\\"\\: \\\"node-agent\\\"#g"},
}
cmds = append(cmds, cmd)
cmd = &common.OsCommandLine{
Cmd: "sed",
Args: []string{"s#\\\"restic\\\",#\\\"node-agent\\\",#g"},
}
cmds = append(cmds, cmd)
cmd = &common.OsCommandLine{
Cmd: "kubectl",
Args: []string{"create", "-f", "-"},
}
cmds = append(cmds, cmd)
return common.GetListByCmdPipes(ctx, cmds)
}