Skip to content

Commit 7f4e497

Browse files
committed
tests in progress - failing unhappy path
refactor refactored refactoring refactoring - for review refactoring - switched namespace
1 parent 5f1b72d commit 7f4e497

File tree

1 file changed

+87
-59
lines changed

1 file changed

+87
-59
lines changed

test/e2e/installplan_e2e_test.go

+87-59
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import (
4545
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/bundle"
4646
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/catalog"
4747
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry"
48+
// "github.com/operator-framework/operator-lifecycle-manager/pkg/lib/catalogsource"
4849
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/kubernetes/pkg/apis/rbac"
4950
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
5051
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/ownerutil"
@@ -4031,37 +4032,23 @@ var _ = Describe("Install Plan", func() {
40314032

40324033

40334034
FDescribe("When an operator is attempted to be installed from a catalog", func () {
4035+
4036+
var (
4037+
csv operatorsv1alpha1.ClusterServiceVersion
4038+
scheme *runtime.Scheme
4039+
csvManifest bytes.Buffer
4040+
og *operatorsv1.OperatorGroup
4041+
plan *operatorsv1alpha1.InstallPlan
4042+
)
4043+
4044+
// BeforeEach
4045+
BeforeEach(func () {
40344046

4035-
// AfterEach - Stolen from the top
4036-
// AfterEach(func() {
4037-
// TearDown(testNamespace)
4038-
// })
4039-
4040-
// Create valid CSVs
4041-
4042-
// Happy Path
4043-
When("The catalog is properly formed", func () {
4044-
4045-
// BeforeEach
4046-
// BeforeEach(func () {
4047-
// // csv := newCSV("test", "default", "", semver.MustParse("0.1.0"), nil, nil, nil)
4048-
// // Expect(ctx.Ctx().Client().Create(context.TODO(), &csv)).To(Succeed())
4049-
// })
4050-
4051-
It("installs the operator as expected", func () {
4052-
// Wait for the inspected install plan to be created
4053-
4054-
// generate client
4055-
c := newKubeClient()
4056-
// crc := newCRClient()
4057-
4058-
4059-
// create a csv
4060-
csv := newCSV("stable", "default", "", semver.MustParse("0.1.0"), nil, nil, nil)
4061-
Expect(ctx.Ctx().Client().Create(context.TODO(), &csv)).To(Succeed())
4047+
// Make CSV
4048+
csv = newCSV("test", testNamespace, "", semver.MustParse("0.1.0"), nil, nil, nil)
40624049

40634050
// create a scheme
4064-
scheme := runtime.NewScheme()
4051+
scheme = runtime.NewScheme()
40654052
Expect(apiextensionsv1.AddToScheme(scheme)).To(Succeed())
40664053
Expect(operatorsv1alpha1.AddToScheme(scheme)).To(Succeed())
40674054

@@ -4071,37 +4058,43 @@ FDescribe("When an operator is attempted to be installed from a catalog", func (
40714058
return k8sjson.NewSerializer(k8sjson.DefaultMetaFactory, scheme, scheme, false).Encode(&csv, &csvManifest)
40724059
}).Should(Succeed())
40734060

4074-
// fmt.Printf("CSV: %v\n", csv)
4075-
// create a namespace for the installPlan
4076-
ns, err := c.KubernetesInterface().CoreV1().Namespaces().Create(context.TODO(), &corev1.Namespace{
4077-
ObjectMeta: metav1.ObjectMeta{
4078-
Name: genName("ns-"),
4079-
},
4080-
}, metav1.CreateOptions{})
4081-
Expect(err).ToNot(HaveOccurred())
4082-
// defer c.KubernetesInterface().CoreV1().Namespaces().Delete(context.TODO(), ns.GetName(), metav1.DeleteOptions{})
4083-
40844061
// Create an operatorgroup for the same namespace
4085-
og := &operatorsv1.OperatorGroup {
4062+
og = &operatorsv1.OperatorGroup {
40864063
ObjectMeta: metav1.ObjectMeta{
40874064
Name: "og",
4088-
Namespace: ns.GetName(),
4065+
Namespace: testNamespace,
40894066
},
40904067
Spec: operatorsv1.OperatorGroupSpec{
4091-
TargetNamespaces: []string{ns.GetName()},
4068+
TargetNamespaces: []string{testNamespace},
40924069
},
40934070
}
4094-
40954071
// wait for the OG to be applied
40964072
Eventually(func() error {
40974073
return ctx.Ctx().Client().Create(context.Background(), og)
40984074
}).Should(Succeed())
4075+
})
40994076

4077+
// AfterEach
4078+
AfterEach(func() {
4079+
// delete the operator group
4080+
Eventually(func() error {
4081+
return ctx.Ctx().Client().Delete(context.Background(), og)
4082+
}, timeout, interval).Should(Succeed())
4083+
4084+
// remaining teardown should be free from TearDown(testNamespace)
4085+
})
4086+
4087+
// Create valid CSVs
4088+
4089+
// Happy Path
4090+
When("The catalog is properly formed", func () {
4091+
4092+
It("installs the operator as expected", func () {
41004093

41014094
// put the installplan in motion
4102-
plan := &operatorsv1alpha1.InstallPlan{
4095+
plan = &operatorsv1alpha1.InstallPlan{
41034096
ObjectMeta: metav1.ObjectMeta{
4104-
Namespace: ns.GetName(),
4097+
Namespace: testNamespace,
41054098
Name: genName("ip-"),
41064099
},
41074100
Spec: operatorsv1alpha1.InstallPlanSpec{
@@ -4136,31 +4129,66 @@ FDescribe("When an operator is attempted to be installed from a catalog", func (
41364129
return ctx.Ctx().Client().Status().Update(context.Background(), plan)
41374130
}).Should(Succeed())
41384131

4139-
//
4140-
key := client.ObjectKeyFromObject(plan)
4141-
fmt.Printf("Key: %v\n", key)
4142-
Eventually(func() (*operatorsv1alpha1.InstallPlan, error) {
4143-
return plan, ctx.Ctx().Client().Get(context.Background(), key, plan)
4144-
}).Should(Succeed())
4145-
})
4132+
key := client.ObjectKeyFromObject(plan)
4133+
Eventually(func() (*operatorsv1alpha1.InstallPlan, error){
4134+
return plan, ctx.Ctx().Client().Get(context.Background(), key, plan)
4135+
}).Should(HavePhase(operatorsv1alpha1.InstallPlanPhaseComplete))
41464136
})
4137+
})
41474138

41484139
// Unhappy Path
41494140
When("The CSV doesn't contain APIVersion", func () {
4150-
4151-
// BeforeEach
4152-
BeforeEach(func () {
4153-
})
41544141
It("fails to install with an error stating CSV missing APIVersion", func () {
4155-
// TODO Get IPStatus to verify install Is in failed state with expected message
4142+
4143+
// modify the CSV to not incude the APIVersion
4144+
csv.APIVersion = ""
4145+
4146+
// put the installplan in motion
4147+
plan = &operatorsv1alpha1.InstallPlan{
4148+
ObjectMeta: metav1.ObjectMeta{
4149+
Namespace: testNamespace,
4150+
Name: genName("ip-"),
4151+
},
4152+
Spec: operatorsv1alpha1.InstallPlanSpec{
4153+
Approval: operatorsv1alpha1.ApprovalAutomatic,
4154+
Approved: true,
4155+
ClusterServiceVersionNames: []string{csv.GetName()},
4156+
},
4157+
}
4158+
4159+
4160+
// wait for the IP to be applied
4161+
Eventually(func() error {
4162+
return ctx.Ctx().Client().Create(context.Background(), plan)
4163+
}).Should(Succeed())
4164+
4165+
plan.Status = operatorsv1alpha1.InstallPlanStatus{
4166+
Phase: operatorsv1alpha1.InstallPlanPhaseInstalling,
4167+
CatalogSources: []string{},
4168+
Plan: []*operatorsv1alpha1.Step{
4169+
{
4170+
Status: operatorsv1alpha1.StepStatusUnknown,
4171+
Resource: operatorsv1alpha1.StepResource{
4172+
Name: csv.GetName(),
4173+
Manifest: csvManifest.String(),
4174+
},
4175+
},
4176+
},
4177+
}
4178+
4179+
Eventually(func() error {
4180+
return ctx.Ctx().Client().Status().Update(context.Background(), plan)
4181+
}).Should(Succeed())
4182+
4183+
key := client.ObjectKeyFromObject(plan)
4184+
Eventually(func() (*operatorsv1alpha1.InstallPlan, error){
4185+
return plan, ctx.Ctx().Client().Get(context.Background(), key, plan)
4186+
}).Should(HavePhase(operatorsv1alpha1.InstallPlanPhaseFailed))
41564187
})
41574188
})
41584189

41594190

41604191
When("The CSV doesn't contain Kind", func () {
4161-
// BeforeEach
4162-
BeforeEach(func () {
4163-
})
41644192
It("fails to install with an error stating CSV missing Kind", func () {
41654193
// TODO Get IPStatus to verify install Is in failed state with expected message
41664194
})

0 commit comments

Comments
 (0)