Skip to content

Commit 58c8485

Browse files
authored
.github,test: Upload container logs during e2e runs as artifacts (#2432)
* test/e2e: Update operators v1 API package import name Update the operatorsv1 API package import from v1 -> operatorsv1. Signed-off-by: timflannagan <[email protected]> * .github,test/e2e: Specify a base testing artifacts directory Update the $JUNIT_DIRECTORY environment varaible that's used throughout the e2e testing suite to the more generalized $ARTIFACTS_DIRECTORY which can be used as the base directory for various testing artifacts. Junit reports are now created implicitly whenever the $ARTIFACTS_DIRECTORY has been specified/non-empty. Signed-off-by: timflannagan <[email protected]> * test/e2e: Collect container logs in the kind provisioner before deprovisioning Update the kind provisioner and collect container logs (and various other testing artifacts) before deprovisioning the kind cluster that tests were running. Signed-off-by: timflannagan <[email protected]>
1 parent adf9a83 commit 58c8485

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

.github/workflows/e2e-tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- uses: actions/setup-go@v2
1515
with:
1616
go-version: '~1.16'
17-
- run: make e2e-local E2E_NODES=2 JUNIT_DIRECTORY=./artifacts/
17+
- run: make e2e-local E2E_NODES=2 ARTIFACTS_DIR=./artifacts/
1818
- name: Archive Test Artifacts # test results, failed or not, are always uploaded.
1919
if: ${{ always() }}
2020
uses: actions/upload-artifact@v2

test/e2e/ctx/provisioner_kind.go

+7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
var (
2424
images = flag.String("kind.images", "", "comma-separated list of image archives to load on cluster nodes, relative to the test binary or test package path")
25+
logDir = "logs"
2526

2627
verbosity int
2728
)
@@ -139,6 +140,12 @@ func Provision(ctx *TestContext) (func(), error) {
139140
var once sync.Once
140141
deprovision := func() {
141142
once.Do(func() {
143+
if artifactsDir := os.Getenv("ARTIFACTS_DIR"); artifactsDir != "" {
144+
ctx.Logf("collecting container logs for the %s cluster", name)
145+
if err := provider.CollectLogs(name, filepath.Join(artifactsDir, logDir)); err != nil {
146+
ctx.Logf("failed to collect logs: %v", err)
147+
}
148+
}
142149
provider.Delete(name, kubeconfigPath)
143150
})
144151
}

test/e2e/e2e_test.go

+10-8
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1717
"sigs.k8s.io/controller-runtime/pkg/client"
1818

19-
v1 "github.com/operator-framework/api/pkg/operators/v1"
19+
operatorsv1 "github.com/operator-framework/api/pkg/operators/v1"
2020
"github.com/operator-framework/operator-lifecycle-manager/test/e2e/ctx"
2121
)
2222

@@ -43,6 +43,7 @@ var (
4343
testNamespace = ""
4444
operatorNamespace = ""
4545
communityOperatorsImage = ""
46+
junitDir = "junit"
4647
)
4748

4849
func TestEndToEnd(t *testing.T) {
@@ -52,8 +53,9 @@ func TestEndToEnd(t *testing.T) {
5253
SetDefaultConsistentlyDuration(30 * time.Second)
5354
SetDefaultConsistentlyPollingInterval(1 * time.Second)
5455

55-
if junitDir := os.Getenv("JUNIT_DIRECTORY"); junitDir != "" {
56-
junitReporter := reporters.NewJUnitReporter(path.Join(junitDir, fmt.Sprintf("junit_e2e_%02d.xml", config.GinkgoConfig.ParallelNode)))
56+
// always configure a junit report when ARTIFACTS_DIR has been set
57+
if artifactsDir := os.Getenv("ARTIFACTS_DIR"); artifactsDir != "" {
58+
junitReporter := reporters.NewJUnitReporter(path.Join(artifactsDir, junitDir, fmt.Sprintf("junit_e2e_%02d.xml", config.GinkgoConfig.ParallelNode)))
5759
RunSpecsWithDefaultAndCustomReporters(t, "End-to-end", []Reporter{junitReporter})
5860
} else {
5961
RunSpecs(t, "End-to-end")
@@ -75,10 +77,10 @@ var _ = BeforeSuite(func() {
7577
deprovision = ctx.MustProvision(ctx.Ctx())
7678
ctx.MustInstall(ctx.Ctx())
7779

78-
var groups v1.OperatorGroupList
80+
var groups operatorsv1.OperatorGroupList
7981
Expect(ctx.Ctx().Client().List(context.Background(), &groups, client.InNamespace(testNamespace))).To(Succeed())
8082
if len(groups.Items) == 0 {
81-
og := v1.OperatorGroup{
83+
og := operatorsv1.OperatorGroup{
8284
ObjectMeta: metav1.ObjectMeta{
8385
Name: "opgroup",
8486
Namespace: testNamespace,
@@ -88,12 +90,12 @@ var _ = BeforeSuite(func() {
8890
}
8991

9092
// Tests can assume the group in the test namespace has been reconciled at least once.
91-
Eventually(func() ([]v1.OperatorGroupStatus, error) {
92-
var groups v1.OperatorGroupList
93+
Eventually(func() ([]operatorsv1.OperatorGroupStatus, error) {
94+
var groups operatorsv1.OperatorGroupList
9395
if err := ctx.Ctx().Client().List(context.Background(), &groups, client.InNamespace(testNamespace)); err != nil {
9496
return nil, err
9597
}
96-
var statuses []v1.OperatorGroupStatus
98+
var statuses []operatorsv1.OperatorGroupStatus
9799
for _, group := range groups.Items {
98100
statuses = append(statuses, group.Status)
99101
}

0 commit comments

Comments
 (0)