-
Notifications
You must be signed in to change notification settings - Fork 545
/
e2e_test.go
152 lines (127 loc) · 4.37 KB
/
e2e_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package e2e
import (
"context"
"flag"
"fmt"
"os"
"path"
"strconv"
"testing"
"time"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
operatorsv1 "github.com/operator-framework/api/pkg/operators/v1"
"github.com/operator-framework/operator-lifecycle-manager/test/e2e/ctx"
)
func init() {
log.SetLogger(zap.New())
}
var (
kubeConfigPath = flag.String(
"kubeconfig", "", "path to the kubeconfig file")
namespace = flag.String(
"namespace", "", "namespace where tests will run")
olmNamespace = flag.String(
"olmNamespace", "", "namespace where olm is running")
catalogNamespace = flag.String(
"catalogNamespace", "", "namespace where the global catalog content is stored")
communityOperators = flag.String(
"communityOperators",
"quay.io/operatorhubio/catalog:latest",
"reference to upstream-community-operators image",
)
dummyImage = flag.String(
"dummyImage",
"bitnami/nginx:latest",
"dummy image to treat as an operator in tests",
)
collectArtifactsScriptPath = flag.String(
"gather-artifacts-script-path",
"./collect-ci-artifacts.sh",
"configures the relative/absolute path to the script responsible for collecting CI artifacts",
)
testdataPath = flag.String(
"test-data-dir",
"./testdata",
"configures where to find the testdata directory",
)
kubeconfigRootDir = flag.String(
"kubeconfig-root",
"",
"configures the root directory for kubeconfig files when running tests in parallel. "+
"Each test worker will expect their kubeconfig file to be <kubeconfig-root>/kubeconfig-<test-number>. "+
"Where, <test-number> is the number of the test worker (> 0). "+
"Note that this flag will override the kubeconfig flag.",
)
testdataDir = ""
testNamespace = ""
operatorNamespace = ""
communityOperatorsImage = ""
globalCatalogNamespace = ""
)
func TestEndToEnd(t *testing.T) {
RegisterFailHandler(Fail)
SetDefaultEventuallyTimeout(1 * time.Minute)
SetDefaultEventuallyPollingInterval(1 * time.Second)
SetDefaultConsistentlyDuration(30 * time.Second)
SetDefaultConsistentlyPollingInterval(1 * time.Second)
RunSpecs(t, "End-to-end")
}
var deprovision func() = func() {}
// This function initializes a client which is used to create an operator group for a given namespace
var _ = BeforeSuite(func() {
if kubeconfigRootDir != nil && *kubeconfigRootDir != "" {
os.Setenv("KUBECONFIG", path.Join(*kubeconfigRootDir, "kubeconfig-"+strconv.Itoa(GinkgoParallelProcess())))
} else if kubeConfigPath != nil && *kubeConfigPath != "" {
os.Setenv("KUBECONFIG", *kubeConfigPath)
}
if collectArtifactsScriptPath != nil && *collectArtifactsScriptPath != "" {
os.Setenv("E2E_ARTIFACT_SCRIPT", *collectArtifactsScriptPath)
}
testNamespace = *namespace
operatorNamespace = *olmNamespace
communityOperatorsImage = *communityOperators
globalCatalogNamespace = *catalogNamespace
testdataDir = *testdataPath
deprovision = ctx.MustProvision(ctx.Ctx())
ctx.MustInstall(ctx.Ctx())
var groups operatorsv1.OperatorGroupList
Expect(ctx.Ctx().Client().List(context.Background(), &groups, client.InNamespace(testNamespace))).To(Succeed())
if len(groups.Items) == 0 {
og := operatorsv1.OperatorGroup{
ObjectMeta: metav1.ObjectMeta{
Name: "opgroup",
Namespace: testNamespace,
},
}
Expect(ctx.Ctx().Client().Create(context.TODO(), &og)).To(Succeed())
}
// Tests can assume the group in the test namespace has been reconciled at least once.
Eventually(func() ([]operatorsv1.OperatorGroupStatus, error) {
var groups operatorsv1.OperatorGroupList
if err := ctx.Ctx().Client().List(context.Background(), &groups, client.InNamespace(testNamespace)); err != nil {
return nil, err
}
var statuses []operatorsv1.OperatorGroupStatus
for _, group := range groups.Items {
statuses = append(statuses, group.Status)
}
return statuses, nil
}).Should(And(
HaveLen(1),
ContainElement(Not(BeZero())),
))
_, err := fetchCatalogSourceOnStatus(ctx.Ctx().OperatorClient(), "operatorhubio-catalog", operatorNamespace, catalogSourceRegistryPodSynced())
Expect(err).NotTo(HaveOccurred())
})
var _ = AfterSuite(func() {
if env := os.Getenv("SKIP_CLEANUP"); env != "" {
fmt.Println("Skipping deprovisioning...")
return
}
deprovision()
})