@@ -45,6 +45,7 @@ import (
45
45
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/bundle"
46
46
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/catalog"
47
47
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry"
48
+ // "github.com/operator-framework/operator-lifecycle-manager/pkg/lib/catalogsource"
48
49
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/kubernetes/pkg/apis/rbac"
49
50
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
50
51
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/ownerutil"
@@ -4031,37 +4032,23 @@ var _ = Describe("Install Plan", func() {
4031
4032
4032
4033
4033
4034
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 () {
4034
4046
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 )
4062
4049
4063
4050
// create a scheme
4064
- scheme : = runtime .NewScheme ()
4051
+ scheme = runtime .NewScheme ()
4065
4052
Expect (apiextensionsv1 .AddToScheme (scheme )).To (Succeed ())
4066
4053
Expect (operatorsv1alpha1 .AddToScheme (scheme )).To (Succeed ())
4067
4054
@@ -4071,37 +4058,43 @@ FDescribe("When an operator is attempted to be installed from a catalog", func (
4071
4058
return k8sjson .NewSerializer (k8sjson .DefaultMetaFactory , scheme , scheme , false ).Encode (& csv , & csvManifest )
4072
4059
}).Should (Succeed ())
4073
4060
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
-
4084
4061
// Create an operatorgroup for the same namespace
4085
- og : = & operatorsv1.OperatorGroup {
4062
+ og = & operatorsv1.OperatorGroup {
4086
4063
ObjectMeta : metav1.ObjectMeta {
4087
4064
Name : "og" ,
4088
- Namespace : ns . GetName () ,
4065
+ Namespace : testNamespace ,
4089
4066
},
4090
4067
Spec : operatorsv1.OperatorGroupSpec {
4091
- TargetNamespaces : []string {ns . GetName () },
4068
+ TargetNamespaces : []string {testNamespace },
4092
4069
},
4093
4070
}
4094
-
4095
4071
// wait for the OG to be applied
4096
4072
Eventually (func () error {
4097
4073
return ctx .Ctx ().Client ().Create (context .Background (), og )
4098
4074
}).Should (Succeed ())
4075
+ })
4099
4076
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 () {
4100
4093
4101
4094
// put the installplan in motion
4102
- plan : = & operatorsv1alpha1.InstallPlan {
4095
+ plan = & operatorsv1alpha1.InstallPlan {
4103
4096
ObjectMeta : metav1.ObjectMeta {
4104
- Namespace : ns . GetName () ,
4097
+ Namespace : testNamespace ,
4105
4098
Name : genName ("ip-" ),
4106
4099
},
4107
4100
Spec : operatorsv1alpha1.InstallPlanSpec {
@@ -4136,31 +4129,66 @@ FDescribe("When an operator is attempted to be installed from a catalog", func (
4136
4129
return ctx .Ctx ().Client ().Status ().Update (context .Background (), plan )
4137
4130
}).Should (Succeed ())
4138
4131
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 ))
4146
4136
})
4137
+ })
4147
4138
4148
4139
// Unhappy Path
4149
4140
When ("The CSV doesn't contain APIVersion" , func () {
4150
-
4151
- // BeforeEach
4152
- BeforeEach (func () {
4153
- })
4154
4141
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 ))
4156
4187
})
4157
4188
})
4158
4189
4159
4190
4160
4191
When ("The CSV doesn't contain Kind" , func () {
4161
- // BeforeEach
4162
- BeforeEach (func () {
4163
- })
4164
4192
It ("fails to install with an error stating CSV missing Kind" , func () {
4165
4193
// TODO Get IPStatus to verify install Is in failed state with expected message
4166
4194
})
0 commit comments