From 8bf081a29f26061e12a3847f50f59aef1e838e45 Mon Sep 17 00:00:00 2001 From: Tiger Kaovilai Date: Sat, 12 Aug 2023 02:33:19 -0400 Subject: [PATCH] Add ignorable restore error logs and unit test --- tests/e2e/lib/velero_helpers.go | 32 ++++++++---------------- tests/e2e/lib/velero_helpers_test.go | 37 ++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 22 deletions(-) create mode 100644 tests/e2e/lib/velero_helpers_test.go diff --git a/tests/e2e/lib/velero_helpers.go b/tests/e2e/lib/velero_helpers.go index 7062d70c271..1c911a99bb8 100644 --- a/tests/e2e/lib/velero_helpers.go +++ b/tests/e2e/lib/velero_helpers.go @@ -164,6 +164,10 @@ var errorIgnorePatterns = []string{ "blob unknown", "num errors=0", "level=debug", // debug logs may contain the text error about recoverable errors so ignore them + + // Ignore managed fields errors per https://github.com/vmware-tanzu/velero/pull/6110 and avoid e2e failure. + // https://prow.ci.openshift.org/view/gs/origin-ci-test/pr-logs/pull/openshift_oadp-operator/1126/pull-ci-openshift-oadp-operator-master-4.10-operator-e2e-aws/1690109468546699264#1:build-log.txt%3A686 + "level=error msg=\"error patch for managed fields ", } func recoverFromPanicLogs(veleroNamespace string, panicReason interface{}, panicFrom string) string { @@ -178,37 +182,21 @@ func recoverFromPanicLogs(veleroNamespace string, panicReason interface{}, panic func BackupErrorLogs(ocClient client.Client, backup velero.Backup) []string { bl := BackupLogs(ocClient, backup) - errorRegex, err := regexp.Compile("error|Error") - if err != nil { - return []string{"could not compile regex: ", err.Error()} - } - logLines := []string{} - for _, line := range strings.Split(bl, "\n") { - if errorRegex.MatchString(line) { - // ignore some expected errors - ignoreLine := false - for _, ignore := range errorIgnorePatterns { - ignoreLine, _ = regexp.MatchString(ignore, line) - if ignoreLine { - break - } - } - if !ignoreLine { - logLines = append(logLines, line) - } - } - } - return logLines + return errorLogsExcludingIgnored(bl) } func RestoreErrorLogs(ocClient client.Client, restore velero.Restore) []string { rl := RestoreLogs(ocClient, restore) + return errorLogsExcludingIgnored(rl) +} + +func errorLogsExcludingIgnored(logs string) []string { errorRegex, err := regexp.Compile("error|Error") if err != nil { return []string{"could not compile regex: ", err.Error()} } logLines := []string{} - for _, line := range strings.Split(rl, "\n") { + for _, line := range strings.Split(logs, "\n") { if errorRegex.MatchString(line) { // ignore some expected errors ignoreLine := false diff --git a/tests/e2e/lib/velero_helpers_test.go b/tests/e2e/lib/velero_helpers_test.go new file mode 100644 index 00000000000..46590cd415d --- /dev/null +++ b/tests/e2e/lib/velero_helpers_test.go @@ -0,0 +1,37 @@ +package lib + +import ( + "reflect" + "testing" +) + +func Test_errorLogsExcludingIgnored(t *testing.T) { + type args struct { + logs string + } + tests := []struct { + name string + args args + want []string + }{ + { + // sample from https://prow.ci.openshift.org/view/gs/origin-ci-test/pr-logs/pull/openshift_oadp-operator/1126/pull-ci-openshift-oadp-operator-master-4.10-operator-e2e-aws/1690109468546699264#1:build-log.txt%3A686 + name: "error patch for managed fields are ignored", + args: args{ + logs: `time="2023-08-11T22:02:39Z" level=debug msg="status field for endpointslices.discovery.k8s.io: exists: false, should restore: false" logSource="pkg/restore/restore.go:1487" restore=openshift-adp/mysql-twovol-csi-e2e-76673cb9-3892-11ee-b9ab-0a580a83082d +time="2023-08-11T22:02:39Z" level=error msg="error patch for managed fields mysql-persistent/mysql-6ztv6: endpointslices.discovery.k8s.io \"mysql-6ztv6\" not found" logSource="pkg/restore/restore.go:1516" restore=openshift-adp/mysql-twovol-csi-e2e-76673cb9-3892-11ee-b9ab-0a580a83082d +time="2023-08-11T22:02:39Z" level=info msg="Restored 40 items out of an estimated total of 50 (estimate will change throughout the restore)" logSource="pkg/restore/restore.go:669" name=mysql-6ztv6 namespace=mysql-persistent progress= resource=endpointslices.discovery.k8s.io restore=openshift-adp/mysql-twovol-csi-e2e-76673cb9-3892-11ee-b9ab-0a580a83082d +time="2023-08-11T22:02:39Z" level=info msg="restore status includes excludes: " logSource="pkg/restore/restore.go:1189" restore=openshift-adp/mysql-twovol-csi-e2e-76673cb9-3892-11ee-b9ab-0a580a83082d +time="2023-08-11T22:02:39Z" level=debug msg="Skipping action because it does not apply to this resource" logSource="pkg/plugin/framework/action_resolver.go:61" restore=openshift-adp/mysql-twovol-csi-e2e-76673cb9-3892-11ee-b9ab-0a580a83082d`, + }, + want: []string{}, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := errorLogsExcludingIgnored(tt.args.logs); !reflect.DeepEqual(got, tt.want) { + t.Errorf("errorLogsExcludingIgnored() = %v, want %v", got, tt.want) + } + }) + } +}