-
Notifications
You must be signed in to change notification settings - Fork 552
/
Copy pathdynamic_resource_e2e_test.go
151 lines (123 loc) · 5.2 KB
/
dynamic_resource_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
package e2e
import (
"context"
"strings"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/dynamic"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/operator-framework/api/pkg/operators/v1alpha1"
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned"
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry"
"github.com/operator-framework/operator-lifecycle-manager/test/e2e/ctx"
)
// This test was disabled because both of its tests are currently being skipped
// We need to understand why and whether this test is even needed:
// https://github.com/operator-framework/operator-lifecycle-manager/issues/3402
var _ = XDescribe("Subscriptions create required objects from Catalogs", Label("DynamicResource"), func() {
var (
crc versioned.Interface
generatedNamespace corev1.Namespace
dynamicClient dynamic.Interface
deleteOpts *metav1.DeleteOptions
)
BeforeEach(func() {
crc = ctx.Ctx().OperatorClient()
dynamicClient = ctx.Ctx().DynamicClient()
deleteOpts = &metav1.DeleteOptions{}
generatedNamespace = SetupGeneratedTestNamespace(genName("dynamic-resource-e2e-"))
})
AfterEach(func() {
TearDown(generatedNamespace.GetName())
})
Context("Given a Namespace", func() {
When("a CatalogSource is created with a bundle that contains prometheus objects", func() {
Context("creating a subscription using the CatalogSource", func() {
var (
catsrc *v1alpha1.CatalogSource
subName string
cleanupSub cleanupFunc
)
BeforeEach(func() {
By("Create CatalogSource")
catsrc = &v1alpha1.CatalogSource{
ObjectMeta: metav1.ObjectMeta{
Name: genName("dynamic-catalog-"),
Namespace: generatedNamespace.GetName(),
},
Spec: v1alpha1.CatalogSourceSpec{
Image: "quay.io/olmtest/catsrc_dynamic_resources:e2e-test",
SourceType: v1alpha1.SourceTypeGrpc,
GrpcPodConfig: &v1alpha1.GrpcPodConfig{
SecurityContextConfig: v1alpha1.Restricted,
},
},
}
catsrc, err := crc.OperatorsV1alpha1().CatalogSources(catsrc.GetNamespace()).Create(context.TODO(), catsrc, metav1.CreateOptions{})
Expect(err).NotTo(HaveOccurred())
By("Wait for the CatalogSource to be ready")
_, err = fetchCatalogSourceOnStatus(crc, catsrc.GetName(), catsrc.GetNamespace(), catalogSourceRegistryPodSynced())
Expect(err).NotTo(HaveOccurred())
By("Generate a Subscription")
subName = genName("dynamic-resources")
cleanupSub = createSubscriptionForCatalog(crc, catsrc.GetNamespace(), subName, catsrc.GetName(), "etcd", "singlenamespace-alpha", "", v1alpha1.ApprovalAutomatic)
})
AfterEach(func() {
By("clean up subscription")
if cleanupSub != nil {
cleanupSub()
}
By("Delete CatalogSource")
if catsrc != nil {
err := crc.OperatorsV1alpha1().CatalogSources(catsrc.GetNamespace()).Delete(context.TODO(), catsrc.GetName(), *deleteOpts)
Expect(err).NotTo(HaveOccurred())
}
})
It("should install the operator successfully", func() {
Skip("this test disabled pending fix of the v1 CRD feature")
_, err := fetchSubscription(crc, catsrc.GetNamespace(), subName, subscriptionHasInstallPlanChecker())
Expect(err).NotTo(HaveOccurred())
})
It("should have created the expected prometheus objects", func() {
Skip("this test disabled pending fix of the v1 CRD feature")
sub, err := fetchSubscription(crc, catsrc.GetNamespace(), subName, subscriptionHasInstallPlanChecker())
Expect(err).NotTo(HaveOccurred())
ipName := sub.Status.InstallPlanRef.Name
ip, err := waitForInstallPlan(crc, ipName, sub.GetNamespace(), buildInstallPlanPhaseCheckFunc(v1alpha1.InstallPlanPhaseFailed, v1alpha1.InstallPlanPhaseComplete))
Expect(err).NotTo(HaveOccurred())
By("Ensure the InstallPlan contains the steps resolved from the bundle image")
expectedSteps := map[registry.ResourceKey]struct{}{
{Name: "my-prometheusrule", Kind: "PrometheusRule"}: {},
{Name: "my-servicemonitor", Kind: "ServiceMonitor"}: {},
}
By("Verify Resource steps match expected steps")
for _, step := range ip.Status.Plan {
key := registry.ResourceKey{
Name: step.Resource.Name,
Kind: step.Resource.Kind,
}
for expected := range expectedSteps {
if strings.HasPrefix(key.Name, expected.Name) && key.Kind == expected.Kind {
delete(expectedSteps, expected)
}
}
}
Expect(len(expectedSteps)).To(BeZero(), "Resource steps do not match expected: %#v", expectedSteps)
By("Confirm that the expected types exist")
gvr := schema.GroupVersionResource{
Group: "monitoring.coreos.com",
Version: "v1",
Resource: "prometheusrules",
}
err = waitForGVR(dynamicClient, gvr, "my-prometheusrule", generatedNamespace.GetName())
Expect(err).NotTo(HaveOccurred())
gvr.Resource = "servicemonitors"
err = waitForGVR(dynamicClient, gvr, "my-servicemonitor", generatedNamespace.GetName())
Expect(err).NotTo(HaveOccurred())
})
})
})
})
})