Skip to content

Commit b3a3ca2

Browse files
authored
Move deprecated e2e to one namespace per spec (#2707)
Signed-off-by: perdasilva <[email protected]>
1 parent f2a3f26 commit b3a3ca2

File tree

1 file changed

+54
-51
lines changed

1 file changed

+54
-51
lines changed

test/e2e/deprecated_e2e_test.go

+54-51
Original file line numberDiff line numberDiff line change
@@ -2,89 +2,92 @@ package e2e
22

33
import (
44
"context"
5+
"fmt"
56
"time"
67

78
"github.com/blang/semver/v4"
89
. "github.com/onsi/ginkgo"
9-
"github.com/onsi/ginkgo/extensions/table"
1010
. "github.com/onsi/gomega"
11+
operatorsv1 "github.com/operator-framework/api/pkg/operators/v1"
1112
operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
13+
"github.com/operator-framework/operator-lifecycle-manager/test/e2e/ctx"
14+
corev1 "k8s.io/api/core/v1"
1215
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1316
"sigs.k8s.io/controller-runtime/pkg/client"
14-
15-
"github.com/operator-framework/operator-lifecycle-manager/test/e2e/ctx"
1617
)
1718

1819
var missingAPI = `{"apiVersion":"verticalpodautoscalers.autoscaling.k8s.io/v1","kind":"VerticalPodAutoscaler","metadata":{"name":"my.thing","namespace":"foo"}}`
1920

2021
var _ = Describe("Not found APIs", func() {
22+
23+
var ns corev1.Namespace
24+
2125
BeforeEach(func() {
22-
csv := newCSV("test-csv", testNamespace, "", semver.Version{}, nil, nil, nil)
26+
namespaceName := genName("deprecated-e2e-")
27+
og := operatorsv1.OperatorGroup{
28+
ObjectMeta: metav1.ObjectMeta{
29+
Name: fmt.Sprintf("%s-operatorgroup", namespaceName),
30+
Namespace: namespaceName,
31+
},
32+
}
33+
ns = SetupGeneratedTestNamespaceWithOperatorGroup(namespaceName, og)
34+
35+
csv := newCSV("test-csv", ns.GetName(), "", semver.Version{}, nil, nil, nil)
2336
Expect(ctx.Ctx().Client().Create(context.TODO(), &csv)).To(Succeed())
2437
})
38+
2539
AfterEach(func() {
26-
TearDown(testNamespace)
40+
TeardownNamespace(ns.GetName())
2741
})
2842

29-
When("objects with APIs that are not on-cluster are created in the installplan", func() {
30-
// each entry is an installplan with a deprecated resource
31-
type payload struct {
32-
name string
33-
IP *operatorsv1alpha1.InstallPlan
34-
errMessage string
35-
}
36-
37-
tableEntries := []table.TableEntry{
38-
table.Entry("contains an entry with a missing API not found on cluster ", payload{
39-
name: "installplan contains a missing API",
40-
IP: &operatorsv1alpha1.InstallPlan{
43+
Context("objects with APIs that are not on-cluster are created in the installplan", func() {
44+
When("installplan contains a missing API", func() {
45+
It("the ip enters a failed state with a helpful error message", func() {
46+
ip := &operatorsv1alpha1.InstallPlan{
4147
ObjectMeta: metav1.ObjectMeta{
42-
Namespace: *namespace, // this is necessary due to ginkgo table semantics, see https://github.com/onsi/ginkgo/issues/378
4348
Name: "test-plan-api",
49+
Namespace: ns.GetName(),
4450
},
4551
Spec: operatorsv1alpha1.InstallPlanSpec{
4652
Approval: operatorsv1alpha1.ApprovalAutomatic,
4753
Approved: true,
4854
ClusterServiceVersionNames: []string{},
4955
},
50-
},
51-
errMessage: "api-server resource not found installing VerticalPodAutoscaler my.thing: GroupVersionKind " +
52-
"verticalpodautoscalers.autoscaling.k8s.io/v1, Kind=VerticalPodAutoscaler not found on the cluster",
53-
}),
54-
}
55-
56-
table.DescribeTable("the ip enters a failed state with a helpful error message", func(tt payload) {
57-
Expect(ctx.Ctx().Client().Create(context.Background(), tt.IP)).To(Succeed())
56+
}
57+
Expect(ctx.Ctx().Client().Create(context.Background(), ip)).To(Succeed())
5858

59-
tt.IP.Status = operatorsv1alpha1.InstallPlanStatus{
60-
Phase: operatorsv1alpha1.InstallPlanPhaseInstalling,
61-
CatalogSources: []string{},
62-
Plan: []*operatorsv1alpha1.Step{
63-
{
64-
Resolving: "test-csv",
65-
Status: operatorsv1alpha1.StepStatusUnknown,
66-
Resource: operatorsv1alpha1.StepResource{
67-
Name: "my.thing",
68-
Group: "verticalpodautoscalers.autoscaling.k8s.io",
69-
Version: "v1",
70-
Kind: "VerticalPodAutoscaler",
71-
Manifest: missingAPI,
59+
ip.Status = operatorsv1alpha1.InstallPlanStatus{
60+
Phase: operatorsv1alpha1.InstallPlanPhaseInstalling,
61+
CatalogSources: []string{},
62+
Plan: []*operatorsv1alpha1.Step{
63+
{
64+
Resolving: "test-csv",
65+
Status: operatorsv1alpha1.StepStatusUnknown,
66+
Resource: operatorsv1alpha1.StepResource{
67+
Name: "my.thing",
68+
Group: "verticalpodautoscalers.autoscaling.k8s.io",
69+
Version: "v1",
70+
Kind: "VerticalPodAutoscaler",
71+
Manifest: missingAPI,
72+
},
7273
},
7374
},
74-
},
75-
}
75+
}
7676

77-
Expect(ctx.Ctx().Client().Status().Update(context.Background(), tt.IP)).To(Succeed(), "failed to update the resource")
77+
Expect(ctx.Ctx().Client().Status().Update(context.Background(), ip)).To(Succeed(), "failed to update the resource")
7878

79-
// The IP sits in the Installing phase with the GVK missing error
80-
Eventually(func() (*operatorsv1alpha1.InstallPlan, error) {
81-
return tt.IP, ctx.Ctx().Client().Get(context.Background(), client.ObjectKeyFromObject(tt.IP), tt.IP)
82-
}).Should(And(HavePhase(operatorsv1alpha1.InstallPlanPhaseInstalling)), HaveMessage(tt.errMessage))
79+
errMessage := "api-server resource not found installing VerticalPodAutoscaler my.thing: GroupVersionKind " +
80+
"verticalpodautoscalers.autoscaling.k8s.io/v1, Kind=VerticalPodAutoscaler not found on the cluster"
81+
// The IP sits in the Installing phase with the GVK missing error
82+
Eventually(func() (*operatorsv1alpha1.InstallPlan, error) {
83+
return ip, ctx.Ctx().Client().Get(context.Background(), client.ObjectKeyFromObject(ip), ip)
84+
}).Should(And(HavePhase(operatorsv1alpha1.InstallPlanPhaseInstalling)), HaveMessage(errMessage))
8385

84-
// Eventually the IP fails with the GVK missing error, after installplan retries, which is by default 1 minute.
85-
Eventually(func() (*operatorsv1alpha1.InstallPlan, error) {
86-
return tt.IP, ctx.Ctx().Client().Get(context.Background(), client.ObjectKeyFromObject(tt.IP), tt.IP)
87-
}, 2*time.Minute).Should(And(HavePhase(operatorsv1alpha1.InstallPlanPhaseFailed)), HaveMessage(tt.errMessage))
88-
}, tableEntries...)
86+
// Eventually the IP fails with the GVK missing error, after installplan retries, which is by default 1 minute.
87+
Eventually(func() (*operatorsv1alpha1.InstallPlan, error) {
88+
return ip, ctx.Ctx().Client().Get(context.Background(), client.ObjectKeyFromObject(ip), ip)
89+
}, 2*time.Minute).Should(And(HavePhase(operatorsv1alpha1.InstallPlanPhaseFailed)), HaveMessage(errMessage))
90+
})
91+
})
8992
})
9093
})

0 commit comments

Comments
 (0)