Skip to content

Commit 5c93c20

Browse files
committed
add e2e test
1 parent b4b5071 commit 5c93c20

File tree

4 files changed

+220
-11
lines changed

4 files changed

+220
-11
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: operators.coreos.com/v1
2+
kind: OLMConfig
3+
metadata:
4+
name: cluster
5+
spec:
6+
features:
7+
disableCopiedCSVs: false

pkg/controller/operators/openshift/suite_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
. "github.com/onsi/gomega"
1111
configv1 "github.com/openshift/api/config/v1"
1212
"github.com/operator-framework/api/crds"
13+
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
1314
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1415
"k8s.io/client-go/rest"
1516
ctrl "sigs.k8s.io/controller-runtime"
@@ -54,8 +55,8 @@ var _ = BeforeSuite(func() {
5455
base := filepath.Join("..", "..", "..", "..", "vendor", "github.com", "openshift", "api", "config", "v1")
5556
testEnv = &envtest.Environment{
5657
ErrorIfCRDPathMissing: true,
57-
CRDs: []client.Object{
58-
crds.ClusterServiceVersion(),
58+
CRDs: []apiextensionsv1.CustomResourceDefinition{
59+
*crds.ClusterServiceVersion(),
5960
},
6061
CRDDirectoryPaths: []string{
6162
filepath.Join(base, "0000_00_cluster-version-operator_01_clusteroperator.crd.yaml"),

pkg/controller/operators/suite_test.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,15 @@ var _ = BeforeSuite(func() {
8888
useExisting := false
8989
testEnv = &envtest.Environment{
9090
UseExistingCluster: &useExisting,
91-
CRDs: []client.Object{
92-
crds.CatalogSource(),
93-
crds.ClusterServiceVersion(),
94-
crds.InstallPlan(),
95-
crds.Subscription(),
96-
crds.OperatorGroup(),
97-
crds.Operator(),
98-
crds.OperatorCondition(),
91+
CRDs: []apiextensionsv1.CustomResourceDefinition{
92+
*crds.CatalogSource(),
93+
*crds.ClusterServiceVersion(),
94+
*crds.InstallPlan(),
95+
*crds.Subscription(),
96+
*crds.OperatorGroup(),
97+
*crds.Operator(),
98+
*crds.OperatorCondition(),
99+
*crds.OLMConfig(),
99100
},
100101
}
101102

test/e2e/csv_e2e_test.go

Lines changed: 201 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@ import (
1818
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
1919
"k8s.io/apimachinery/pkg/api/equality"
2020
k8serrors "k8s.io/apimachinery/pkg/api/errors"
21+
"k8s.io/apimachinery/pkg/api/meta"
2122
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23+
"k8s.io/apimachinery/pkg/labels"
2224
k8slabels "k8s.io/apimachinery/pkg/labels"
2325
"k8s.io/apimachinery/pkg/runtime"
26+
"k8s.io/apimachinery/pkg/selection"
27+
apitypes "k8s.io/apimachinery/pkg/types"
2428
"k8s.io/apimachinery/pkg/util/diff"
2529
"k8s.io/apimachinery/pkg/util/intstr"
2630
"k8s.io/apimachinery/pkg/util/wait"
@@ -37,7 +41,7 @@ import (
3741
"github.com/operator-framework/operator-lifecycle-manager/test/e2e/ctx"
3842
)
3943

40-
var _ = Describe("ClusterServiceVersion", func() {
44+
var _ = FDescribe("ClusterServiceVersion", func() {
4145
HavePhase := func(goal operatorsv1alpha1.ClusterServiceVersionPhase) types.GomegaMatcher {
4246
return WithTransform(func(csv *operatorsv1alpha1.ClusterServiceVersion) operatorsv1alpha1.ClusterServiceVersionPhase {
4347
return csv.Status.Phase
@@ -4169,6 +4173,202 @@ var _ = Describe("ClusterServiceVersion", func() {
41694173

41704174
Expect(apiService2.Spec.CABundle).Should(Equal(apiService1.Spec.CABundle))
41714175
})
4176+
4177+
It("Disabling copied csvs", func() {
4178+
ns := &corev1.Namespace{
4179+
ObjectMeta: metav1.ObjectMeta{
4180+
Name: genName("csv-toggle-test-"),
4181+
},
4182+
}
4183+
4184+
// Create a new operator group for the new namespace
4185+
operatorGroup := v1.OperatorGroup{
4186+
ObjectMeta: metav1.ObjectMeta{
4187+
Name: genName("csv-toggle-test-"),
4188+
Namespace: ns.GetName(),
4189+
},
4190+
}
4191+
4192+
csv := v1alpha1.ClusterServiceVersion{
4193+
ObjectMeta: metav1.ObjectMeta{
4194+
Name: genName("csv-toggle-test-"),
4195+
Namespace: ns.GetName(),
4196+
},
4197+
Spec: v1alpha1.ClusterServiceVersionSpec{
4198+
InstallStrategy: newNginxInstallStrategy(genName("csv-toggle-test-"), nil, nil),
4199+
InstallModes: []v1alpha1.InstallMode{
4200+
{
4201+
Type: v1alpha1.InstallModeTypeAllNamespaces,
4202+
Supported: true,
4203+
},
4204+
},
4205+
},
4206+
}
4207+
Context("When an operator is installed in all namespace mode", func() {
4208+
Eventually(func() error {
4209+
if err := ctx.Ctx().Client().Create(context.TODO(), ns); err != nil && !k8serrors.IsAlreadyExists(err) {
4210+
ctx.Ctx().Logf("Unable to create ns: %v", err)
4211+
return err
4212+
}
4213+
4214+
if err := ctx.Ctx().Client().Create(context.TODO(), &operatorGroup); err != nil && !k8serrors.IsAlreadyExists(err) {
4215+
ctx.Ctx().Logf("Unable to create og: %v", err)
4216+
return err
4217+
}
4218+
4219+
if err := ctx.Ctx().Client().Create(context.TODO(), &csv); err != nil && !k8serrors.IsAlreadyExists(err) {
4220+
ctx.Ctx().Logf("Unable to create csv: %v", err)
4221+
return err
4222+
}
4223+
4224+
return nil
4225+
}).Should(Succeed())
4226+
})
4227+
4228+
Context("Copied CSVs should be generated in all other namespaces", func() {
4229+
Eventually(func() error {
4230+
requirement, err := labels.NewRequirement(v1alpha1.CopiedLabelKey, selection.Equals, []string{csv.GetNamespace()})
4231+
if err != nil {
4232+
return err
4233+
}
4234+
4235+
var copiedCSVs v1alpha1.ClusterServiceVersionList
4236+
err = ctx.Ctx().Client().List(context.TODO(), &copiedCSVs, &client.ListOptions{
4237+
LabelSelector: labels.NewSelector().Add(*requirement),
4238+
})
4239+
if err != nil {
4240+
return err
4241+
}
4242+
4243+
var namespaces corev1.NamespaceList
4244+
if err := ctx.Ctx().Client().List(context.TODO(), &namespaces, &client.ListOptions{}); err != nil {
4245+
return err
4246+
}
4247+
4248+
if len(namespaces.Items) != len(copiedCSVs.Items)+1 {
4249+
return fmt.Errorf("CSVs are not copied to every namespace %v vs %v", len(namespaces.Items), (copiedCSVs.Items))
4250+
}
4251+
4252+
return nil
4253+
}).Should(Succeed())
4254+
})
4255+
4256+
When("Copied CSVs should be generated in all other namespaces", func() {
4257+
Eventually(func() error {
4258+
var olmConfig v1.OLMConfig
4259+
if err := ctx.Ctx().Client().Get(context.TODO(), apitypes.NamespacedName{Name: "cluster"}, &olmConfig); err != nil {
4260+
ctx.Ctx().Logf("Error getting olmConfig %v", err)
4261+
return err
4262+
}
4263+
4264+
olmConfig.Spec.Features.DisableCopiedCSVs = true
4265+
4266+
if err := ctx.Ctx().Client().Update(context.TODO(), &olmConfig); err != nil {
4267+
ctx.Ctx().Logf("Error setting olmConfig %v", err)
4268+
return err
4269+
}
4270+
4271+
return nil
4272+
}).Should(Succeed())
4273+
})
4274+
Context("Should delete existing copied csvs", func() {
4275+
Eventually(func() error {
4276+
requirement, err := labels.NewRequirement(v1alpha1.CopiedLabelKey, selection.Equals, []string{csv.GetNamespace()})
4277+
if err != nil {
4278+
return err
4279+
}
4280+
4281+
var copiedCSVs v1alpha1.ClusterServiceVersionList
4282+
err = ctx.Ctx().Client().List(context.TODO(), &copiedCSVs, &client.ListOptions{
4283+
LabelSelector: labels.NewSelector().Add(*requirement),
4284+
})
4285+
if err != nil {
4286+
return err
4287+
}
4288+
4289+
if len(copiedCSVs.Items) != 0 {
4290+
return fmt.Errorf("Number of copied csvs should be 0")
4291+
}
4292+
return nil
4293+
}).Should(Succeed())
4294+
})
4295+
4296+
Context("Should updated the olmConfig status to reflect that the cluster is in the expected state", func() {
4297+
Eventually(func() error {
4298+
var olmConfig v1.OLMConfig
4299+
if err := ctx.Ctx().Client().Get(context.TODO(), apitypes.NamespacedName{Name: "cluster"}, &olmConfig); err != nil {
4300+
return err
4301+
}
4302+
4303+
if !meta.IsStatusConditionPresentAndEqual(olmConfig.Status.Conditions, "ready", metav1.ConditionTrue) {
4304+
return fmt.Errorf("Copied CSVs not ready not ready")
4305+
}
4306+
4307+
return nil
4308+
}).Should(Succeed())
4309+
})
4310+
When("Copied CSVs are toggled back on", func() {
4311+
Eventually(func() error {
4312+
4313+
var olmConfig v1.OLMConfig
4314+
if err := ctx.Ctx().Client().Get(context.TODO(), apitypes.NamespacedName{Name: "cluster"}, &olmConfig); err != nil {
4315+
return err
4316+
}
4317+
4318+
olmConfig.Spec.Features.DisableCopiedCSVs = false
4319+
4320+
if err := ctx.Ctx().Client().Update(context.TODO(), &olmConfig); err != nil {
4321+
return err
4322+
}
4323+
4324+
return nil
4325+
}).Should(Succeed())
4326+
})
4327+
4328+
Context("OLM should recreate existing copied csvs", func() {
4329+
Eventually(func() error {
4330+
// find copied csvs...
4331+
requirement, err := labels.NewRequirement(v1alpha1.CopiedLabelKey, selection.Equals, []string{csv.GetNamespace()})
4332+
if err != nil {
4333+
return err
4334+
}
4335+
4336+
var copiedCSVs v1alpha1.ClusterServiceVersionList
4337+
err = ctx.Ctx().Client().List(context.TODO(), &copiedCSVs, &client.ListOptions{
4338+
LabelSelector: labels.NewSelector().Add(*requirement),
4339+
})
4340+
if err != nil {
4341+
return err
4342+
}
4343+
4344+
var namespaces corev1.NamespaceList
4345+
if err := ctx.Ctx().Client().List(context.TODO(), &namespaces, &client.ListOptions{}); err != nil {
4346+
return err
4347+
}
4348+
4349+
if len(namespaces.Items) != len(copiedCSVs.Items)+1 {
4350+
return fmt.Errorf("CSVs are not copied to every namespace")
4351+
}
4352+
4353+
return nil
4354+
}).Should(Succeed())
4355+
})
4356+
4357+
Context("Should updated the olmConfig status to reflect that the cluster is in the expected state", func() {
4358+
Eventually(func() error {
4359+
var olmConfig v1.OLMConfig
4360+
if err := ctx.Ctx().Client().Get(context.TODO(), apitypes.NamespacedName{Name: "cluster"}, &olmConfig); err != nil {
4361+
return err
4362+
}
4363+
4364+
if !meta.IsStatusConditionPresentAndEqual(olmConfig.Status.Conditions, "ready", metav1.ConditionTrue) {
4365+
return fmt.Errorf("Copied CSVs not ready not ready")
4366+
}
4367+
4368+
return nil
4369+
}).Should(Succeed())
4370+
})
4371+
})
41724372
})
41734373

41744374
var singleInstance = int32(1)

0 commit comments

Comments
 (0)